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.
 
 
 

209 line
4.4 KiB

  1. // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
  2. /******************************************************************************
  3. *
  4. * file: StandardTraits.h
  5. *
  6. * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot .
  7. * All rights reverved.
  8. *
  9. * See the file COPYING in the top directory of this distribution for
  10. * more information.
  11. *
  12. * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. * DEALINGS IN THE SOFTWARE.
  19. *
  20. *****************************************************************************/
  21. // This is an internal tclap file, you should probably not have to
  22. // include this directly
  23. #ifndef TCLAP_STANDARD_TRAITS_H
  24. #define TCLAP_STANDARD_TRAITS_H
  25. #ifdef HAVE_CONFIG_H
  26. #include <config.h> // To check for long long
  27. #endif
  28. // If Microsoft has already typedef'd wchar_t as an unsigned
  29. // short, then compiles will break because it's as if we're
  30. // creating ArgTraits twice for unsigned short. Thus...
  31. #ifdef _MSC_VER
  32. #ifndef _NATIVE_WCHAR_T_DEFINED
  33. #define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
  34. #endif
  35. #endif
  36. namespace TCLAP {
  37. // ======================================================================
  38. // Integer types
  39. // ======================================================================
  40. /**
  41. * longs have value-like semantics.
  42. */
  43. template<>
  44. struct ArgTraits<long> {
  45. typedef ValueLike ValueCategory;
  46. };
  47. /**
  48. * ints have value-like semantics.
  49. */
  50. template<>
  51. struct ArgTraits<int> {
  52. typedef ValueLike ValueCategory;
  53. };
  54. /**
  55. * shorts have value-like semantics.
  56. */
  57. template<>
  58. struct ArgTraits<short> {
  59. typedef ValueLike ValueCategory;
  60. };
  61. /**
  62. * chars have value-like semantics.
  63. */
  64. template<>
  65. struct ArgTraits<char> {
  66. typedef ValueLike ValueCategory;
  67. };
  68. #ifdef HAVE_LONG_LONG
  69. /**
  70. * long longs have value-like semantics.
  71. */
  72. template<>
  73. struct ArgTraits<long long> {
  74. typedef ValueLike ValueCategory;
  75. };
  76. #endif
  77. // ======================================================================
  78. // Unsigned integer types
  79. // ======================================================================
  80. /**
  81. * unsigned longs have value-like semantics.
  82. */
  83. template<>
  84. struct ArgTraits<unsigned long> {
  85. typedef ValueLike ValueCategory;
  86. };
  87. /**
  88. * unsigned ints have value-like semantics.
  89. */
  90. template<>
  91. struct ArgTraits<unsigned int> {
  92. typedef ValueLike ValueCategory;
  93. };
  94. /**
  95. * unsigned shorts have value-like semantics.
  96. */
  97. template<>
  98. struct ArgTraits<unsigned short> {
  99. typedef ValueLike ValueCategory;
  100. };
  101. /**
  102. * unsigned chars have value-like semantics.
  103. */
  104. template<>
  105. struct ArgTraits<unsigned char> {
  106. typedef ValueLike ValueCategory;
  107. };
  108. // Microsoft implements size_t awkwardly.
  109. #if defined(_MSC_VER) && defined(_M_X64)
  110. /**
  111. * size_ts have value-like semantics.
  112. */
  113. template<>
  114. struct ArgTraits<size_t> {
  115. typedef ValueLike ValueCategory;
  116. };
  117. #endif
  118. #ifdef HAVE_LONG_LONG
  119. /**
  120. * unsigned long longs have value-like semantics.
  121. */
  122. template<>
  123. struct ArgTraits<unsigned long long> {
  124. typedef ValueLike ValueCategory;
  125. };
  126. #endif
  127. // ======================================================================
  128. // Float types
  129. // ======================================================================
  130. /**
  131. * floats have value-like semantics.
  132. */
  133. template<>
  134. struct ArgTraits<float> {
  135. typedef ValueLike ValueCategory;
  136. };
  137. /**
  138. * doubles have value-like semantics.
  139. */
  140. template<>
  141. struct ArgTraits<double> {
  142. typedef ValueLike ValueCategory;
  143. };
  144. // ======================================================================
  145. // Other types
  146. // ======================================================================
  147. /**
  148. * bools have value-like semantics.
  149. */
  150. template<>
  151. struct ArgTraits<bool> {
  152. typedef ValueLike ValueCategory;
  153. };
  154. /**
  155. * wchar_ts have value-like semantics.
  156. */
  157. #ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
  158. template<>
  159. struct ArgTraits<wchar_t> {
  160. typedef ValueLike ValueCategory;
  161. };
  162. #endif
  163. /**
  164. * Strings have string like argument traits.
  165. */
  166. template<>
  167. struct ArgTraits<std::string> {
  168. typedef StringLike ValueCategory;
  169. };
  170. template<typename T>
  171. void SetString(T &dst, const std::string &src)
  172. {
  173. dst = src;
  174. }
  175. } // namespace
  176. #endif