diff --git a/code/nel/include/nel/misc/string_common.h b/code/nel/include/nel/misc/string_common.h index 4a455247d..2d2a7e676 100644 --- a/code/nel/include/nel/misc/string_common.h +++ b/code/nel/include/nel/misc/string_common.h @@ -264,6 +264,40 @@ inline bool fromString(const std::string &str, bool &val) return true; } +inline bool fromString(const char *str, uint32 &val) { if (strstr(str, "-") != NULL) { val = 0; return false; } char *end; unsigned long v; errno = 0; v = strtoul(str, &end, 10); if (errno || v > UINT_MAX || end == str) { val = 0; return false; } else { val = (uint32)v; return true; } } +inline bool fromString(const char *str, sint32 &val) { char *end; long v; errno = 0; v = strtol(str, &end, 10); if (errno || v > INT_MAX || v < INT_MIN || end == str) { val = 0; return false; } else { val = (sint32)v; return true; } } +inline bool fromString(const char *str, uint8 &val) { char *end; long v; errno = 0; v = strtol(str, &end, 10); if (errno || v > UCHAR_MAX || v < 0 || end == str) { val = 0; return false; } else { val = (uint8)v; return true; } } +inline bool fromString(const char *str, sint8 &val) { char *end; long v; errno = 0; v = strtol(str, &end, 10); if (errno || v > SCHAR_MAX || v < SCHAR_MIN || end == str) { val = 0; return false; } else { val = (sint8)v; return true; } } +inline bool fromString(const char *str, uint16 &val) { char *end; long v; errno = 0; v = strtol(str, &end, 10); if (errno || v > USHRT_MAX || v < 0 || end == str) { val = 0; return false; } else { val = (uint16)v; return true; } } +inline bool fromString(const char *str, sint16 &val) { char *end; long v; errno = 0; v = strtol(str, &end, 10); if (errno || v > SHRT_MAX || v < SHRT_MIN || end == str) { val = 0; return false; } else { val = (sint16)v; return true; } } +inline bool fromString(const char *str, uint64 &val) { bool ret = sscanf(str, "%"NL_I64"u", &val) == 1; if (!ret) val = 0; return ret; } +inline bool fromString(const char *str, sint64 &val) { bool ret = sscanf(str, "%"NL_I64"d", &val) == 1; if (!ret) val = 0; return ret; } +inline bool fromString(const char *str, float &val) { bool ret = sscanf(str, "%f", &val) == 1; if (!ret) val = 0.0f; return ret; } +inline bool fromString(const char *str, double &val) { bool ret = sscanf(str, "%lf", &val) == 1; if (!ret) val = 0.0; return ret; } + +inline bool fromString(const char *str, bool &val) +{ + switch (str[0]) + { + case '1': + case 't': + case 'y': + case 'T': + case 'Y': + val = true; + return true; + case '0': + case 'f': + case 'n': + case 'F': + case 'N': + val = false; + return true; + } + + return false; +} + inline bool fromString(const std::string &str, std::string &val) { val = str; return true; } // stl vectors of bool use bit reference and not real bools, so define the operator for bit reference diff --git a/code/nel/include/nel/misc/xml_auto_ptr.h b/code/nel/include/nel/misc/xml_auto_ptr.h index eacde74da..8e0c3adb7 100644 --- a/code/nel/include/nel/misc/xml_auto_ptr.h +++ b/code/nel/include/nel/misc/xml_auto_ptr.h @@ -31,7 +31,7 @@ public: ~CXMLAutoPtr() { destroy(); } operator const char *() const { return _Value; } operator bool() const { return _Value != NULL; } - operator std::string() const { return std::string(_Value); } + inline std::string str() const { return _Value; } bool operator ! () const { return _Value == NULL; } operator const unsigned char *() const { return (const unsigned char *) _Value; } char operator * () const { nlassert(_Value); return *_Value; } diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index a4037607f..2a9c5282a 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -19,12 +19,6 @@ #include "nel/misc/types_nl.h" #ifdef NL_OS_WINDOWS -# define _WIN32_WINDOWS 0x0410 -# ifndef NL_COMP_MINGW -# define WINVER 0x0400 -# define NOMINMAX -# endif -# include # include # include # include diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index 8b6b7a577..4b9231663 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -18,16 +18,7 @@ #include "nel/misc/types_nl.h" -#ifdef NL_OS_WINDOWS -// these defines is for IsDebuggerPresent(). it'll not compile on windows 95 -// just comment this and the IsDebuggerPresent to compile on windows 95 -# define _WIN32_WINDOWS 0x0410 -# ifndef NL_COMP_MINGW -# define WINVER 0x0400 -# define NOMINMAX -# endif -# include -#else +#ifndef NL_OS_WINDOWS # define IsDebuggerPresent() false #endif diff --git a/code/nel/src/misc/mem_displayer.cpp b/code/nel/src/misc/mem_displayer.cpp index 49431097d..fc5681657 100644 --- a/code/nel/src/misc/mem_displayer.cpp +++ b/code/nel/src/misc/mem_displayer.cpp @@ -103,7 +103,7 @@ static string getFuncInfo (DWORD_TYPE funcAddr, DWORD_TYPE stackAddr) if (stop==0 && (parse[i] == ',' || parse[i] == ')')) { char tmp[32]; - sprintf (tmp, "=0x%p", *((ULONG*)(stackAddr) + 2 + pos++)); + sprintf(tmp, "=0x%p", *((DWORD_TYPE*)(stackAddr) + 2 + pos++)); str += tmp; } str += parse[i]; diff --git a/code/nel/src/misc/mutex.cpp b/code/nel/src/misc/mutex.cpp index 28f6bae37..8135d954f 100644 --- a/code/nel/src/misc/mutex.cpp +++ b/code/nel/src/misc/mutex.cpp @@ -41,15 +41,6 @@ using namespace std; #ifdef NL_OS_WINDOWS -// these defines are for IsDebuggerPresent(). It'll not compile on windows 95 -// just comment this and the IsDebuggerPresent to compile on windows 95 -#define _WIN32_WINDOWS 0x0410 -#ifndef NL_COMP_MINGW -# define WINVER 0x0400 -# define NOMINMAX -#endif -#include - #ifdef DEBUG_NEW #define new DEBUG_NEW #endif diff --git a/code/nel/src/misc/stdmisc.h b/code/nel/src/misc/stdmisc.h index b98d92d2a..37284511c 100644 --- a/code/nel/src/misc/stdmisc.h +++ b/code/nel/src/misc/stdmisc.h @@ -43,8 +43,10 @@ #include #ifdef _WIN32 -# ifndef __MINGW32__ - #define NOMINMAX +# define _WIN32_WINDOWS 0x0410 +# ifndef NL_COMP_MINGW +# define WINVER 0x0400 +# define NOMINMAX # endif # include # include