You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
2.5 KiB

  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. /** @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. #ifdef LOG4CPLUS_HAVE_RVALUE_REFS
  54. inline
  55. std::string
  56. tostring (std::string && str)
  57. {
  58. return std::move (str);
  59. }
  60. #endif
  61. inline
  62. std::wstring
  63. towstring (wchar_t const * str)
  64. {
  65. return std::wstring (str);
  66. }
  67. inline
  68. std::wstring
  69. towstring (std::wstring const & str)
  70. {
  71. return str;
  72. }
  73. inline
  74. std::wstring const &
  75. towstring (std::wstring & str)
  76. {
  77. return str;
  78. }
  79. #ifdef LOG4CPLUS_HAVE_RVALUE_REFS
  80. inline
  81. std::wstring
  82. towstring (std::wstring && str)
  83. {
  84. return std::move (str);
  85. }
  86. #endif
  87. LOG4CPLUS_EXPORT std::string tostring(const std::wstring&);
  88. LOG4CPLUS_EXPORT std::string tostring(wchar_t const *);
  89. LOG4CPLUS_EXPORT std::wstring towstring(const std::string&);
  90. LOG4CPLUS_EXPORT std::wstring towstring(char const *);
  91. } // namespace helpers
  92. #ifdef UNICODE
  93. #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
  94. #define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
  95. #define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING)
  96. #else // UNICODE
  97. #define LOG4CPLUS_C_STR_TO_TSTRING(STRING) std::string(STRING)
  98. #define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING
  99. #define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING
  100. #endif // UNICODE
  101. } // namespace log4cplus
  102. #endif // LOG4CPLUS_TSTRING_HEADER_