tstring.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /** @file */
  22. #ifndef LOG4CPLUS_TSTRING_HEADER_
  23. #define LOG4CPLUS_TSTRING_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <string>
  29. #include <log4cplus/tchar.h>
  30. namespace log4cplus
  31. {
  32. typedef std::basic_string<tchar> tstring;
  33. namespace helpers
  34. {
  35. inline
  36. std::string
  37. tostring (char const * str)
  38. {
  39. return std::string (str);
  40. }
  41. inline
  42. std::string
  43. tostring (std::string const & str)
  44. {
  45. return str;
  46. }
  47. inline
  48. std::string const &
  49. tostring (std::string & str)
  50. {
  51. return str;
  52. }
  53. inline
  54. std::string
  55. tostring (std::string && str)
  56. {
  57. return std::move (str);
  58. }
  59. inline
  60. std::wstring
  61. towstring (wchar_t const * str)
  62. {
  63. return std::wstring (str);
  64. }
  65. inline
  66. std::wstring
  67. towstring (std::wstring const & str)
  68. {
  69. return str;
  70. }
  71. inline
  72. std::wstring const &
  73. towstring (std::wstring & str)
  74. {
  75. return str;
  76. }
  77. inline
  78. std::wstring
  79. towstring (std::wstring && str)
  80. {
  81. return std::move (str);
  82. }
  83. LOG4CPLUS_EXPORT std::string tostring(const std::wstring&);
  84. LOG4CPLUS_EXPORT std::string tostring(wchar_t const *);
  85. LOG4CPLUS_EXPORT std::wstring towstring(const std::string&);
  86. LOG4CPLUS_EXPORT std::wstring towstring(char const *);
  87. } // namespace helpers
  88. #ifdef UNICODE
  89. #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
  90. #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
  91. #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING)
  92. #else // UNICODE
  93. #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) (std::string(STRING))
  94. #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING
  95. #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING
  96. #endif // UNICODE
  97. } // namespace log4cplus
  98. #endif // LOG4CPLUS_TSTRING_HEADER_