log4cplus  2.0.0
tstring.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    tstring.h
00004 // Created: 4/2003
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 2003-2015 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 inline
00067 std::string
00068 tostring (std::string && str)
00069 {
00070     return std::move (str);
00071 }
00072 
00073 
00074 inline
00075 std::wstring
00076 towstring (wchar_t const * str)
00077 {
00078     return std::wstring (str);
00079 }
00080 
00081 inline
00082 std::wstring
00083 towstring (std::wstring const & str)
00084 {
00085     return str;
00086 }
00087 
00088 inline
00089 std::wstring const &
00090 towstring (std::wstring & str)
00091 {
00092     return str;
00093 }
00094 
00095 inline
00096 std::wstring
00097 towstring (std::wstring && str)
00098 {
00099     return std::move (str);
00100 }
00101 
00102 
00103 LOG4CPLUS_EXPORT std::string tostring(const std::wstring&);
00104 LOG4CPLUS_EXPORT std::string tostring(wchar_t const *);
00105 
00106 LOG4CPLUS_EXPORT std::wstring towstring(const std::string&);
00107 LOG4CPLUS_EXPORT std::wstring towstring(char const *);
00108 
00109 } // namespace helpers
00110 
00111 #ifdef UNICODE
00112 
00113 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
00114 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
00115 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING)
00116 
00117 #else // UNICODE
00118 
00119 #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) (std::string(STRING))
00120 #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING
00121 #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING
00122 
00123 #endif // UNICODE
00124 
00125 } // namespace log4cplus
00126 
00127 
00128 #endif // LOG4CPLUS_TSTRING_HEADER_