plugins/consoles/rcons/server/win32/Misc.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // Misc.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 #include "Misc.h"
       
    13 
       
    14 void* operator new(size_t n, TThrow)
       
    15 	{
       
    16 	void* cell = ::operator new(n);
       
    17 	if (!cell)
       
    18 		{
       
    19 		throw KExceptionNoMemory;
       
    20 		}
       
    21 	return cell;
       
    22 	}
       
    23 
       
    24 void operator delete(void* const p, TThrow)
       
    25 	{
       
    26 	::operator delete(p);
       
    27 	}
       
    28 
       
    29 void* operator new[](size_t n, TThrow)
       
    30 	{
       
    31 	void* cell = ::operator new[](n);
       
    32 	if (!cell)
       
    33 		{
       
    34 		throw KExceptionNoMemory;
       
    35 		}
       
    36 	return cell;
       
    37 	}
       
    38 
       
    39 void operator delete[](void* const p, TThrow)
       
    40 	{
       
    41 	::operator delete[](p);
       
    42 	}
       
    43 
       
    44 void Panic()
       
    45 	{
       
    46 	_asm int 3;
       
    47 	}
       
    48 
       
    49 void DebugLog(LPCTSTR aFormat, ...)
       
    50 	{
       
    51 	const int KMaxFormatBuf = 256;
       
    52 	va_list args;
       
    53 	va_start(args, aFormat);
       
    54 	TCHAR buf[KMaxFormatBuf];
       
    55 	int length = _vsnwprintf(buf, KMaxFormatBuf, aFormat, args);
       
    56 	OutputDebugString(buf);
       
    57 	OutputDebugString(TEXT("\r\n"));
       
    58 	}
       
    59 
       
    60 bool FileExists(LPCTSTR aFileName)
       
    61 	{
       
    62 	int att = GetFileAttributes(aFileName);
       
    63 	return (att > 0);
       
    64 	}
       
    65 
       
    66 void ConvertNarrowToWide(const char* aNarrow, int aLength, WCHAR* aWide)
       
    67 	{
       
    68 	for (int i = 0; i < aLength; ++i)
       
    69 		{
       
    70 		aWide[i] = (unsigned short)aNarrow[i];
       
    71 		}
       
    72 	aWide[aLength] = TCHAR('\0');
       
    73 	}
       
    74 
       
    75 void ConvertNarrowToWideAlloc(const char* aNarrow, int aLength, WCHAR*& aWide)
       
    76 	{
       
    77 	aWide = new WCHAR[aLength + 1];
       
    78 	if (aWide)
       
    79 		{
       
    80 		ConvertNarrowToWide(aNarrow, aLength, aWide);
       
    81 		}
       
    82 	}
       
    83 
       
    84 void ConvertWideToNarrow(const WCHAR* aWide, int aLength, char* aNarrow)
       
    85 	{
       
    86 	for (int i = 0; i < aLength; ++i)
       
    87 		{
       
    88 		aNarrow[i] = (char)aWide[i];
       
    89 		}
       
    90 	aNarrow[aLength] = '\0';
       
    91 	}
       
    92 
       
    93 void ConvertWideToNarrowAlloc(const WCHAR* aWide, int aLength, char*& aNarrow)
       
    94 	{
       
    95 	aNarrow = new char[aLength + 1];
       
    96 	if (aNarrow)
       
    97 		{
       
    98 		ConvertWideToNarrow(aWide, aLength, aNarrow);
       
    99 		}
       
   100 	}