Shadowrun: Awakened 29 September 2011 - Build 871
Utils.h
Go to the documentation of this file.
00001 /*
00002 * Utils - Some helper & utility stuff.
00003 *
00004 * @Author Michael <Tharbas> Matzen
00005 *
00006 * This program is free software; you can redistribute it and/or modify it
00007 * under the terms of the GNU General Public License as published by the Free
00008 * Software Foundation; either version 2 of the License, or (at your option)
00009 * any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful, but WITHOUT
00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00014 * more details.
00015 *
00016 * You should have received a copy of the GNU General Public License along with
00017 * this program; if not, write to the Free Software Foundation, Inc., 51
00018 * Franklin St, Fifth Floor, Boston, MA 02110, USA
00019 * 
00020 */
00021 #pragma once
00022 
00023 #include "WindowsIncludes.h"
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <iostream>
00027 #include <map>
00028 #include <memory>
00029 
00030 
00034 __inline std::string convertString(const wchar_t* string)
00035 {
00036     size_t size = wcslen(string);
00037     size_t outCharCount;
00038     char *buf = new char[sizeof(wchar_t)*size];
00039     wcstombs_s(&outCharCount, buf, size, string, size);
00040     std::string ret(buf);
00041     delete[] buf;
00042     return ret;
00043 }
00044 
00048 __inline wchar_t* convertString(const std::string& string)
00049 {
00050     //the memory allocated here should theoretically be managed by the DLLBind mechanism, so there is no corresponding delete
00051     //If at a later time, we find a memory leak in the applicable, this could be it.
00052     wchar_t *ret = new wchar_t[string.size()];
00053 
00054     size_t size = (size_t)string.size();
00055     size_t outCharCount;
00056     mbstowcs_s(&outCharCount, ret, size, string.c_str(),size);
00057     return ret;
00058 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net