1 // -*- C++ -*- 2 // Module: Log4CPLUS 3 // File: tstring.h 4 // Created: 4/2003 5 // Author: Tad E. Smith 6 // 7 // 8 // Copyright 2003-2013 Tad E. Smith 9 // 10 // Licensed under the Apache License, Version 2.0 (the "License"); 11 // you may not use this file except in compliance with the License. 12 // You may obtain a copy of the License at 13 // 14 // http://www.apache.org/licenses/LICENSE-2.0 15 // 16 // Unless required by applicable law or agreed to in writing, software 17 // distributed under the License is distributed on an "AS IS" BASIS, 18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 // See the License for the specific language governing permissions and 20 // limitations under the License. 21 22 /** @file */ 23 24 #ifndef LOG4CPLUS_TSTRING_HEADER_ 25 #define LOG4CPLUS_TSTRING_HEADER_ 26 27 #include <log4cplus/config.hxx> 28 29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 30 #pragma once 31 #endif 32 33 #include <string> 34 #include <log4cplus/tchar.h> 35 36 namespace log4cplus 37 { 38 39 typedef std::basic_string<tchar> tstring; 40 41 42 namespace helpers 43 { 44 45 inline 46 std::string tostring(char const * str)47tostring (char const * str) 48 { 49 return std::string (str); 50 } 51 52 inline 53 std::string tostring(std::string const & str)54tostring (std::string const & str) 55 { 56 return str; 57 } 58 59 inline 60 std::string const & tostring(std::string & str)61tostring (std::string & str) 62 { 63 return str; 64 } 65 66 #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 67 inline 68 std::string tostring(std::string && str)69tostring (std::string && str) 70 { 71 return std::move (str); 72 } 73 74 #endif 75 76 77 78 inline 79 std::wstring towstring(wchar_t const * str)80towstring (wchar_t const * str) 81 { 82 return std::wstring (str); 83 } 84 85 inline 86 std::wstring towstring(std::wstring const & str)87towstring (std::wstring const & str) 88 { 89 return str; 90 } 91 92 inline 93 std::wstring const & towstring(std::wstring & str)94towstring (std::wstring & str) 95 { 96 return str; 97 } 98 99 #ifdef LOG4CPLUS_HAVE_RVALUE_REFS 100 inline 101 std::wstring towstring(std::wstring && str)102towstring (std::wstring && str) 103 { 104 return std::move (str); 105 } 106 107 #endif 108 109 LOG4CPLUS_EXPORT std::string tostring(const std::wstring&); 110 LOG4CPLUS_EXPORT std::string tostring(wchar_t const *); 111 112 LOG4CPLUS_EXPORT std::wstring towstring(const std::string&); 113 LOG4CPLUS_EXPORT std::wstring towstring(char const *); 114 115 } // namespace helpers 116 117 #ifdef UNICODE 118 119 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 120 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING) 121 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING) 122 123 #else // UNICODE 124 125 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) std::string(STRING) 126 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING 127 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING 128 129 #endif // UNICODE 130 131 } // namespace log4cplus 132 133 134 #endif // LOG4CPLUS_TSTRING_HEADER_ 135