Conversion to unicode, everything except StreamerConfiguration

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
monroegm-disable-blank-issue-2
Esteban Papp 4 years ago
parent 99bf5e54c4
commit 015424eb35

@ -38,7 +38,6 @@ namespace AZ
void DebugBreak();
#endif
void Terminate(int exitCode);
void OutputToDebugger(const char* window, const char* message);
}
}

@ -15,6 +15,11 @@ namespace AZ
{
namespace Debug
{
namespace Platform
{
void OutputToDebugger(const char* window, const char* message);
}
/// Global instance to the tracer.
extern class Trace g_tracer;

@ -49,6 +49,25 @@ namespace AZStd
}
}
template<size_t MaxElementCount>
static inline void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& dest, const wchar_t* first, const wchar_t* last)
{
if constexpr (Size == 2)
{
Utf8::Unchecked::utf16to8(first, last, AZStd::back_inserter(dest));
}
else if constexpr (Size == 4)
{
Utf8::Unchecked::utf32to8(first, last, AZStd::back_inserter(dest));
}
else
{
// Workaround to defer static_assert evaluation until this function is invoked by using the template parameter
using StringType = AZStd::basic_string<string::value_type, string::traits_type, Allocator1>;
static_assert(!AZStd::is_same_v<StringType, StringType>, "only wchar_t types of size 2 or 4 can be converted to utf8");
}
}
template<class Allocator1>
static inline void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator1>& dest, const char* first, const char* last)
{
@ -67,6 +86,25 @@ namespace AZStd
static_assert(!AZStd::is_same_v<StringType, StringType>, "Cannot convert a utf8 string to a wchar_t that isn't size 2 or 4");
}
}
template<size_t MaxElementCount>
static inline void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount, wstring::traits_type>& dest, const char* first, const char* last)
{
if constexpr (Size == 2)
{
Utf8::Unchecked::utf8to16(first, last, AZStd::back_inserter(dest));
}
else if constexpr (Size == 4)
{
Utf8::Unchecked::utf8to32(first, last, AZStd::back_inserter(dest));
}
else
{
// Workaround to defer static_assert evaluation until this function is invoked by using the template parameter
using StringType = AZStd::basic_string<string::value_type, string::traits_type, Allocator1>;
static_assert(!AZStd::is_same_v<StringType, StringType>, "Cannot convert a utf8 string to a wchar_t that isn't size 2 or 4");
}
}
};
}
// 21.5: numeric conversions
@ -266,6 +304,28 @@ namespace AZStd
return to_string(dest, src.c_str(), src.length());
}
template<size_t MaxElementCount>
void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& dest, const wchar_t* str, size_t srcLen = 0)
{
dest.clear();
if (srcLen == 0)
{
srcLen = wcslen(str);
}
if (srcLen > 0)
{
Internal::WCharTPlatformConverter<>::to_string(dest, str, str + srcLen);
}
}
template<size_t MaxElementCount1, size_t MaxElementCount2>
void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount1, string::traits_type>& dest, const AZStd::basic_fixed_string<wstring::value_type, MaxElementCount2, wstring::traits_type>& src)
{
return to_string(dest, src.c_str(), src.length());
}
template<class Allocator>
int stoi(const AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator>& str, AZStd::size_t* idx = 0, int base = 10)
{
@ -384,6 +444,28 @@ namespace AZStd
return to_wstring(dest, src.c_str(), src.length());
}
template<size_t MaxElementCount1>
void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount1, wstring::traits_type>& dest, const char* str, size_t strLen = 0)
{
dest.clear();
if (strLen == 0)
{
strLen = strlen(str);
}
if (strLen > 0)
{
Internal::WCharTPlatformConverter<>::to_wstring(dest, str, str + strLen);
}
}
template<size_t MaxElementCount1, size_t MaxElementCount2>
void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount1, wstring::traits_type>& dest, const AZStd::basic_fixed_string<string::value_type, MaxElementCount2, string::traits_type>& src)
{
return to_wstring(dest, src.c_str(), src.length());
}
// Convert a range of chars to lower case
#if defined(AZSTD_USE_OLD_RW_STL)
template<class Iterator>

@ -72,6 +72,7 @@ namespace AZ
void OutputToDebugger(const char*, const char*)
{
// std::cout << title << ": " << message;
}
}
}

@ -12,6 +12,8 @@
#include <AzCore/PlatformIncl.h>
#include <AzCore/Debug/TraceMessageBus.h>
#include <AzCore/Debug/TraceMessagesDrillerBus.h>
#include <AzCore/std/string/conversions.h>
#include <AzCore/std/string/fixed_string.h>
#include <stdio.h>
@ -22,7 +24,7 @@ namespace AZ
LPTOP_LEVEL_EXCEPTION_FILTER g_previousExceptionHandler = nullptr;
#endif
const int g_maxMessageLength = 4096;
constexpr int g_maxMessageLength = 4096;
namespace Debug
{
@ -58,15 +60,18 @@ namespace AZ
TerminateProcess(GetCurrentProcess(), exitCode);
}
void OutputToDebugger(const char* window, const char* message)
void OutputToDebugger([[maybe_unused]] const char* window, const char* message)
{
AZ_UNUSED(window);
wchar_t messageW[g_maxMessageLength];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, messageW, message, g_maxMessageLength - 1) == 0)
AZStd::fixed_wstring<g_maxMessageLength> tmpW;
if(window)
{
OutputDebugStringW(messageW);
AZStd::to_wstring(tmpW, window);
tmpW += L": ";
OutputDebugStringW(tmpW.c_str());
tmpW.clear();
}
AZStd::to_wstring(tmpW, message);
OutputDebugStringW(tmpW.c_str());
}
}
}

@ -7,6 +7,7 @@
*/
#include <AzCore/Debug/Trace.h>
#include <iostream>
namespace AZ
{
@ -14,8 +15,9 @@ namespace AZ
{
namespace Platform
{
void OutputToDebugger(const char*, const char*)
void OutputToDebugger(const char* title, const char* message)
{
// std::cout << title << ": " << message;
}
}
}

@ -29,7 +29,7 @@ namespace AZ
return errno;
}
void SharedMemory_Mac::ComposeMutexName(char* dest, size_t length, const char* name)
void ComposeMutexName(char* dest, size_t length, const char* name)
{
azstrncpy(m_name, AZ_ARRAY_SIZE(m_name), name, strlen(name));

@ -29,7 +29,6 @@ namespace AZ
static int GetLastError();
void ComposeMutexName(char* dest, size_t length, const char* name);
CreateResult Create(const char* name, unsigned int size, bool openIfCreated);
bool Open(const char* name);
void Close();

@ -290,7 +290,7 @@ namespace AZ::IO
static bool CollectHardwareInfo(HardwareInformation& hardwareInfo, bool addAllDrives, bool reportHardware)
{
char drives[512];
if (::GetLogicalDriveStrings(sizeof(drives) - 1, drives))
if (::GetLogicalDriveStringsA(sizeof(drives) - 1, drives))
{
AZStd::unordered_map<DWORD, DriveInformation> driveMappings;
char* driveIt = drives;
@ -318,7 +318,7 @@ namespace AZ::IO
deviceName += driveIt;
deviceName.erase(deviceName.length() - 1); // Erase the slash.
HANDLE deviceHandle = ::CreateFile(
HANDLE deviceHandle = ::CreateFileA(
deviceName.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
if (deviceHandle != INVALID_HANDLE_VALUE)
{

@ -11,6 +11,7 @@
#include <AzCore/IPC/SharedMemory.h>
#include <AzCore/std/parallel/spin_mutex.h>
#include <AzCore/std/string/conversions.h>
#include <AzCore/std/string/fixed_string.h>
namespace AZ
{
@ -21,16 +22,17 @@ namespace AZ
{
}
void SharedMemory_Windows::ComposeMutexName(char* dest, size_t length, const char* name)
void ComposeName(AZStd::fixed_wstring<256>& dest, const char* name, const wchar_t* suffix)
{
azstrncpy(m_name, AZ_ARRAY_SIZE(m_name), name, strlen(name));
azsnprintf(dest, length, "%s_Mutex", name);
AZStd::to_wstring(dest, name);
dest += L"_";
dest += suffix;
}
SharedMemory_Common::CreateResult SharedMemory_Windows::Create(const char* name, unsigned int size, bool openIfCreated)
{
char fullName[256];
ComposeMutexName(fullName, AZ_ARRAY_SIZE(fullName), name);
AZStd::fixed_wstring<256> fullName;
ComposeName(fullName, name, L"Mutex");
// Security attributes
SECURITY_ATTRIBUTES secAttr;
@ -42,9 +44,7 @@ namespace AZ
SetSecurityDescriptorDacl(secAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
// Obtain global mutex
AZStd::wstring fullNameW;
AZStd::to_wstring(fullNameW, fullName);
m_globalMutex = CreateMutexW(&secAttr, FALSE, fullNameW.c_str());
m_globalMutex = CreateMutexW(&secAttr, FALSE, fullName.c_str());
DWORD error = GetLastError();
if (m_globalMutex == NULL || (error == ERROR_ALREADY_EXISTS && openIfCreated == false))
{
@ -53,8 +53,8 @@ namespace AZ
}
// Create the file mapping.
azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name);
m_mapHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, &secAttr, PAGE_READWRITE, 0, size, fullNameW.c_str());
ComposeName(fullName, name, L"Data");
m_mapHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, &secAttr, PAGE_READWRITE, 0, size, fullName.c_str());
error = GetLastError();
if (m_mapHandle == NULL || (error == ERROR_ALREADY_EXISTS && openIfCreated == false))
{
@ -67,12 +67,10 @@ namespace AZ
bool SharedMemory_Windows::Open(const char* name)
{
char fullName[256];
ComposeMutexName(fullName, AZ_ARRAY_SIZE(fullName), name);
AZStd::wstring fullNameW;
AZStd::to_wstring(fullNameW, fullName);
AZStd::fixed_wstring<256> fullName;
ComposeName(fullName, name, L"Mutex");
m_globalMutex = OpenMutex(SYNCHRONIZE, TRUE, fullNameW.c_str());
m_globalMutex = OpenMutex(SYNCHRONIZE, TRUE, fullName.c_str());
AZ_Warning("AZSystem", m_globalMutex != NULL, "Failed to open OS mutex [%s]\n", m_name);
if (m_globalMutex == NULL)
{
@ -80,8 +78,8 @@ namespace AZ
return false;
}
azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name);
m_mapHandle = OpenFileMapping(FILE_MAP_WRITE, false, fullNameW.c_str());
ComposeName(fullName, name, L"Data");
m_mapHandle = OpenFileMapping(FILE_MAP_WRITE, false, fullName.c_str());
if (m_mapHandle == NULL)
{
AZ_TracePrintf("AZSystem", "OpenFileMapping %s failed with error %d\n", m_name, GetLastError());

@ -41,9 +41,6 @@ namespace AZ
HANDLE m_mapHandle;
HANDLE m_globalMutex;
int m_lastLockResult;
private:
void ComposeMutexName(char* dest, size_t length, const char* name);
};
using SharedMemory_Platform = SharedMemory_Windows;

Loading…
Cancel
Save