log4cplus 2.0.8
tstring.h
Go to the documentation of this file.
1// -*- C++ -*-
2// Module: Log4CPLUS
3// File: tstring.h
4// Created: 4/2003
5// Author: Tad E. Smith
6//
7//
8// Copyright 2003-2017 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
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
36namespace log4cplus
37{
38
39typedef std::basic_string<tchar> tstring;
40
41
42namespace helpers
43{
44
45inline
46std::string
47tostring (char const * str)
48{
49 return std::string (str);
50}
51
52inline
53std::string
54tostring (std::string const & str)
55{
56 return str;
57}
58
59inline
60std::string const &
61tostring (std::string & str)
62{
63 return str;
64}
65
66inline
67std::string
68tostring (std::string && str)
69{
70 return std::move (str);
71}
72
73
74inline
75std::wstring
76towstring (wchar_t const * str)
77{
78 return std::wstring (str);
79}
80
81inline
82std::wstring
83towstring (std::wstring const & str)
84{
85 return str;
86}
87
88inline
89std::wstring const &
90towstring (std::wstring & str)
91{
92 return str;
93}
94
95inline
96std::wstring
97towstring (std::wstring && str)
98{
99 return std::move (str);
100}
101
102
103LOG4CPLUS_EXPORT std::string tostring(const std::wstring&);
104LOG4CPLUS_EXPORT std::string tostring(wchar_t const *);
105
106LOG4CPLUS_EXPORT std::wstring towstring(const std::string&);
107LOG4CPLUS_EXPORT std::wstring towstring(char const *);
108
109} // namespace helpers
110
111#ifdef UNICODE
112
113#define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
114#define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
115#define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING)
116
117#else // UNICODE
118
119#define LOG4CPLUS_C_STR_TO_TSTRING(STRING) (std::string(STRING))
120#define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING
121#define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING
122
123#endif // UNICODE
124
125} // namespace log4cplus
126
127
128#endif // LOG4CPLUS_TSTRING_HEADER_
std::wstring towstring(wchar_t const *str)
Definition tstring.h:76
std::string tostring(char const *str)
Definition tstring.h:47
std::basic_string< tchar > tstring
Definition tstring.h:39
#define LOG4CPLUS_EXPORT
Definition win32.h:141