log4cplus
1.1.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: tstring.h 00004 // Created: 4/2003 00005 // Author: Tad E. Smith 00006 // 00007 // 00008 // Copyright 2003-2010 Tad E. Smith 00009 // 00010 // Licensed under the Apache License, Version 2.0 (the "License"); 00011 // you may not use this file except in compliance with the License. 00012 // You may obtain a copy of the License at 00013 // 00014 // http://www.apache.org/licenses/LICENSE-2.0 00015 // 00016 // Unless required by applicable law or agreed to in writing, software 00017 // distributed under the License is distributed on an "AS IS" BASIS, 00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 // See the License for the specific language governing permissions and 00020 // limitations under the License. 00021 00024 #ifndef LOG4CPLUS_TSTRING_HEADER_ 00025 #define LOG4CPLUS_TSTRING_HEADER_ 00026 00027 #include <log4cplus/config.hxx> 00028 00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00030 #pragma once 00031 #endif 00032 00033 #include <string> 00034 #include <log4cplus/tchar.h> 00035 00036 namespace log4cplus 00037 { 00038 00039 typedef std::basic_string<tchar> tstring; 00040 00041 00042 namespace helpers 00043 { 00044 00045 inline 00046 std::string 00047 tostring (char const * str) 00048 { 00049 return std::string (str); 00050 } 00051 00052 inline 00053 std::string 00054 tostring (std::string const & str) 00055 { 00056 return str; 00057 } 00058 00059 inline 00060 std::string const & 00061 tostring (std::string & str) 00062 { 00063 return str; 00064 } 00065 00066 #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 00067 inline 00068 std::string 00069 tostring (std::string && str) 00070 { 00071 return std::move (str); 00072 } 00073 00074 #endif 00075 00076 00077 00078 inline 00079 std::wstring 00080 towstring (wchar_t const * str) 00081 { 00082 return std::wstring (str); 00083 } 00084 00085 inline 00086 std::wstring 00087 towstring (std::wstring const & str) 00088 { 00089 return str; 00090 } 00091 00092 inline 00093 std::wstring const & 00094 towstring (std::wstring & str) 00095 { 00096 return str; 00097 } 00098 00099 #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 00100 inline 00101 std::wstring 00102 towstring (std::wstring && str) 00103 { 00104 return std::move (str); 00105 } 00106 00107 #endif 00108 00109 LOG4CPLUS_EXPORT std::string tostring(const std::wstring&); 00110 LOG4CPLUS_EXPORT std::string tostring(wchar_t const *); 00111 00112 LOG4CPLUS_EXPORT std::wstring towstring(const std::string&); 00113 LOG4CPLUS_EXPORT std::wstring towstring(char const *); 00114 00115 } // namespace helpers 00116 00117 #ifdef UNICODE 00118 00119 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 00120 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 00121 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING) 00122 00123 #else // UNICODE 00124 00125 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) std::string(STRING) 00126 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING 00127 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING 00128 00129 #endif // UNICODE 00130 00131 } // namespace log4cplus 00132 00133 00134 #endif // LOG4CPLUS_TSTRING_HEADER_