From fdd06e8c2ebeb308b46b968935a6cd83a37333ac Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 23 May 2016 03:34:35 +0300 Subject: [PATCH] Minor aditions to the system path library. Fixed small const correctness in remaining typename functions. Added a flag to block certain format warnings on x64 builds. --- cbp/Squirrel.cbp | 1 + modules/xml/Common.cpp | 2 +- source/Library/Chrono/Date.cpp | 2 +- source/Library/Chrono/Time.cpp | 2 +- source/Library/Crypt/AES.cpp | 2 +- source/Library/System/Path.cpp | 39 ++++++++++++++++++++++++++++++++-- source/Library/System/Path.hpp | 26 ++++++++++++++++++++++- source/Routine.cpp | 2 +- 8 files changed, 68 insertions(+), 8 deletions(-) diff --git a/cbp/Squirrel.cbp b/cbp/Squirrel.cbp index 143e947b..b42b5d34 100644 --- a/cbp/Squirrel.cbp +++ b/cbp/Squirrel.cbp @@ -164,6 +164,7 @@ + diff --git a/modules/xml/Common.cpp b/modules/xml/Common.cpp index 32744726..cfbac701 100644 --- a/modules/xml/Common.cpp +++ b/modules/xml/Common.cpp @@ -92,7 +92,7 @@ void DocumentRef::Validate() const // ------------------------------------------------------------------------------------------------ SQInteger ParseResult::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqXmlParseResult"); + static const SQChar name[] = _SC("SqXmlParseResult"); sq_pushstring(vm, name, sizeof(name)); return 1; } diff --git a/source/Library/Chrono/Date.cpp b/source/Library/Chrono/Date.cpp index 703ab07c..4453811d 100644 --- a/source/Library/Chrono/Date.cpp +++ b/source/Library/Chrono/Date.cpp @@ -16,7 +16,7 @@ const Uint8 Date::MonthLengths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 3 // ------------------------------------------------------------------------------------------------ SQInteger Date::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqChronoDate"); + static const SQChar name[] = _SC("SqChronoDate"); sq_pushstring(vm, name, sizeof(name)); return 1; } diff --git a/source/Library/Chrono/Time.cpp b/source/Library/Chrono/Time.cpp index 1ccab47e..b7f01262 100644 --- a/source/Library/Chrono/Time.cpp +++ b/source/Library/Chrono/Time.cpp @@ -13,7 +13,7 @@ SQChar Time::Delimiter = ':'; // ------------------------------------------------------------------------------------------------ SQInteger Time::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqChronoTime"); + static const SQChar name[] = _SC("SqChronoTime"); sq_pushstring(vm, name, sizeof(name)); return 1; } diff --git a/source/Library/Crypt/AES.cpp b/source/Library/Crypt/AES.cpp index 21b600ef..8df5af78 100644 --- a/source/Library/Crypt/AES.cpp +++ b/source/Library/Crypt/AES.cpp @@ -13,7 +13,7 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ SQInteger AES256::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqAES256"); + static const SQChar name[] = _SC("SqAES256"); sq_pushstring(vm, name, sizeof(name)); return 1; } diff --git a/source/Library/System/Path.cpp b/source/Library/System/Path.cpp index dac3d260..354af8d7 100644 --- a/source/Library/System/Path.cpp +++ b/source/Library/System/Path.cpp @@ -36,7 +36,7 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ SQInteger SysPath::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqSysPath"); + static const SQChar name[] = _SC("SqSysPath"); sq_pushstring(vm, name, sizeof(name)); return 1; } @@ -1632,11 +1632,41 @@ SysPath SysPath::Null() } // ------------------------------------------------------------------------------------------------ -SysPath SysPath::With(const SysPath & parent, CSStr name) +SysPath SysPath::With(const SysPath & parent, CSStr name) { return SysPath(parent, name); } +// ------------------------------------------------------------------------------------------------ +SysPath SysPath::MakeUnix(CSStr path) +{ + return SysPath(path, Style::Unix); +} + +// ------------------------------------------------------------------------------------------------ +SysPath SysPath::MakeWindows(CSStr path) +{ + return SysPath(path, Style::Windows); +} + +// ------------------------------------------------------------------------------------------------ +SysPath SysPath::MakeNative(CSStr path) +{ + return SysPath(path, Style::Native); +} + +// ------------------------------------------------------------------------------------------------ +SysPath SysPath::MakeGuess(CSStr path) +{ + return SysPath(path, Style::Guess); +} + +// ------------------------------------------------------------------------------------------------ +SysPath SysPath::MakeDynamic(CSStr path) +{ + return SysPath(path, Style::Dynamic); +} + // ================================================================================================ void Register_SysPath(HSQUIRRELVM vm) { @@ -1710,6 +1740,11 @@ void Register_SysPath(HSQUIRRELVM vm) .StaticFunc(_SC("System"), &SysPath::System) .StaticFunc(_SC("Null"), &SysPath::Null) .StaticFunc(_SC("With"), &SysPath::With) + .StaticFunc(_SC("Unix"), &SysPath::MakeUnix) + .StaticFunc(_SC("Windows"), &SysPath::MakeWindows) + .StaticFunc(_SC("Native"), &SysPath::MakeNative) + .StaticFunc(_SC("Guess"), &SysPath::MakeGuess) + .StaticFunc(_SC("Dynamic"), &SysPath::MakeDynamic) // Static Overloads .StaticOverload< SysPath (*)(CSStr) >(_SC("ForDir"), &SysPath::ForDirectory) .StaticOverload< SysPath (*)(CSStr, Int32) >(_SC("ForDir"), &SysPath::ForDirectory) diff --git a/source/Library/System/Path.hpp b/source/Library/System/Path.hpp index 303baa3b..0a165383 100644 --- a/source/Library/System/Path.hpp +++ b/source/Library/System/Path.hpp @@ -720,8 +720,32 @@ public: * Creates a path from a parent path and a file name. The parent path is expected to reference * a directory. */ - static SysPath With(const SysPath & parent, CSStr name); + static SysPath With(const SysPath & parent, CSStr name); + /* -------------------------------------------------------------------------------------------- + * Creates a path in unix format from a string. + */ + static SysPath MakeUnix(CSStr path); + + /* -------------------------------------------------------------------------------------------- + * Creates a path in windows format from a string. + */ + static SysPath MakeWindows(CSStr path); + + /* -------------------------------------------------------------------------------------------- + * Creates a path in native format from a string. + */ + static SysPath MakeNative(CSStr path); + + /* -------------------------------------------------------------------------------------------- + * Creates a path in and guess the format from a string. + */ + static SysPath MakeGuess(CSStr path); + + /* -------------------------------------------------------------------------------------------- + * Creates a path in dynamic format from a string. + */ + static SysPath MakeDynamic(CSStr path); }; } // Namespace:: SqMod diff --git a/source/Routine.cpp b/source/Routine.cpp index 757c69d9..1921442f 100644 --- a/source/Routine.cpp +++ b/source/Routine.cpp @@ -18,7 +18,7 @@ Routine::Objects Routine::s_Objects; // ------------------------------------------------------------------------------------------------ SQInteger Routine::Typename(HSQUIRRELVM vm) { - static SQChar name[] = _SC("SqRoutine"); + static const SQChar name[] = _SC("SqRoutine"); sq_pushstring(vm, name, sizeof(name)); return 1; }