From 9a2a524f1e311853d08050be2dcdddc09ac7759a Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:01:29 +0200 Subject: 3.0 --- shared/zstring.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'shared/zstring.h') diff --git a/shared/zstring.h b/shared/zstring.h index 018ca42e..9c7c2245 100644 --- a/shared/zstring.h +++ b/shared/zstring.h @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef __WXDEBUG__ #include @@ -22,8 +23,10 @@ #ifdef ZSTRING_CHAR typedef char DefaultChar; //use char strings +#define DefaultStr(x) x // #elif defined ZSTRING_WIDE_CHAR typedef wchar_t DefaultChar; //use wide character strings +#define DefaultStr(x) L ## x // #endif @@ -123,6 +126,10 @@ private: }; +template +Zstring numberToZstring(const T& number); //convert number to Zstring + + //####################################################################################### //begin of implementation @@ -146,13 +153,13 @@ int defaultCompare(const char* str1, const char* str2, const size_t count) } inline -char* defaultStrFind(const char* str1, const char* str2) +const char* defaultStrFind(const char* str1, const char* str2) { return strstr(str1, str2); } inline -char* defaultStrFind(const char* str1, int ch) +const char* defaultStrFind(const char* str1, int ch) { return strchr(str1, ch); } @@ -236,6 +243,7 @@ public: private: AllocationCount() {} + AllocationCount(const AllocationCount&); ~AllocationCount(); wxCriticalSection lockActStrings; @@ -253,11 +261,12 @@ size_t getCapacityToAllocate(const size_t length) inline Zstring::StringDescriptor* Zstring::allocate(const size_t newLength) -{ //allocate and set data for new string +{ + //allocate and set data for new string const size_t newCapacity = getCapacityToAllocate(newLength); assert(newCapacity); - StringDescriptor* newDescr = static_cast(::malloc(sizeof(StringDescriptor) + (newCapacity + 1) * sizeof(DefaultChar))); //use C-memory functions because of realloc() + StringDescriptor* const newDescr = static_cast(::malloc(sizeof(StringDescriptor) + (newCapacity + 1) * sizeof(DefaultChar))); //use C-memory functions because of realloc() if (newDescr == NULL) throw std::bad_alloc(); @@ -288,6 +297,7 @@ Zstring::Zstring() inline + Zstring::Zstring(const DefaultChar* source) { initAndCopy(source, defaultLength(source)); @@ -671,4 +681,17 @@ const Zstring Zstring::operator+(const DefaultChar ch) const } +template +inline +Zstring numberToZstring(const T& number) //convert number to string the C++ way +{ +#ifdef ZSTRING_CHAR + std::stringstream ss; +#elif defined ZSTRING_WIDE_CHAR + std::wstringstream ss; +#endif + ss << number; + return Zstring(ss.str().c_str(), ss.str().length()); +} + #endif // ZSTRING_H_INCLUDED -- cgit