Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

278 lines
8.1KB

  1. // TR2 <bool_set> support files -*- C++ -*-
  2. // Copyright (C) 2009-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file tr2/bool_set.tcc
  21. * This is a TR2 C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_TR2_BOOL_SET_TCC
  24. #define _GLIBCXX_TR2_BOOL_SET_TCC 1
  25. #pragma GCC system_header
  26. namespace std _GLIBCXX_VISIBILITY(default)
  27. {
  28. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  29. namespace tr2
  30. {
  31. bool_set::_Bool_set_val
  32. bool_set::_S_not[4] =
  33. { _S_true_, _S_false, _S_indet, _S_empty };
  34. bool_set::_Bool_set_val
  35. bool_set::_S_xor[4][4] =
  36. { { _S_false, _S_true_, _S_indet, _S_empty },
  37. { _S_true_, _S_false, _S_indet, _S_empty },
  38. { _S_indet, _S_indet, _S_indet, _S_empty },
  39. { _S_empty, _S_empty, _S_empty, _S_empty } };
  40. bool_set::_Bool_set_val
  41. bool_set::_S_or[4][4] =
  42. { { _S_false, _S_true_, _S_indet, _S_empty },
  43. { _S_true_, _S_true_, _S_true_, _S_empty },
  44. { _S_indet, _S_true_, _S_indet, _S_empty },
  45. { _S_empty, _S_empty, _S_empty, _S_empty } };
  46. bool_set::_Bool_set_val
  47. bool_set::_S_and[4][4] =
  48. { { _S_false, _S_false, _S_false, _S_empty },
  49. { _S_false, _S_true_, _S_indet, _S_empty },
  50. { _S_false, _S_indet, _S_indet, _S_empty },
  51. { _S_empty, _S_empty, _S_empty, _S_empty } };
  52. bool_set::_Bool_set_val
  53. bool_set::_S_eq[4][4] =
  54. { { _S_true_, _S_false, _S_indet, _S_empty },
  55. { _S_false, _S_true_, _S_indet, _S_empty },
  56. { _S_indet, _S_indet, _S_indet, _S_empty },
  57. { _S_empty, _S_empty, _S_empty, _S_empty } };
  58. }
  59. _GLIBCXX_END_NAMESPACE_VERSION
  60. }
  61. // I object to these things.
  62. // The stuff in locale facets are for basic types.
  63. // I think we could hack operator<< and operator>>.
  64. /**
  65. * @brief Numeric parsing.
  66. *
  67. * Parses the input stream into the bool @a v. It does so by calling
  68. * num_get::do_get().
  69. *
  70. * If ios_base::boolalpha is set, attempts to read
  71. * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
  72. * @a v to true or false if successful. Sets err to
  73. * ios_base::failbit if reading the string fails. Sets err to
  74. * ios_base::eofbit if the stream is emptied.
  75. *
  76. * If ios_base::boolalpha is not set, proceeds as with reading a long,
  77. * except if the value is 1, sets @a v to true, if the value is 0, sets
  78. * @a v to false, and otherwise set err to ios_base::failbit.
  79. *
  80. * @param in Start of input stream.
  81. * @param end End of input stream.
  82. * @param io Source of locale and flags.
  83. * @param err Error flags to set.
  84. * @param v Value to format and insert.
  85. * @return Iterator after reading.
  86. iter_type
  87. get(iter_type __in, iter_type __end, ios_base& __io,
  88. ios_base::iostate& __err, bool& __v) const
  89. { return this->do_get(__in, __end, __io, __err, __v); }
  90. */
  91. /*
  92. template<typename _CharT, typename _InIter>
  93. _InIter
  94. num_get<_CharT, _InIter>::
  95. do_get(iter_type __beg, iter_type __end, ios_base& __io,
  96. ios_base::iostate& __err, bool_set& __v) const
  97. {
  98. if (!(__io.flags() & ios_base::boolalpha))
  99. {
  100. // Parse bool values as long.
  101. // NB: We can't just call do_get(long) here, as it might
  102. // refer to a derived class.
  103. long __l = -1;
  104. __beg = _M_extract_int(__beg, __end, __io, __err, __l);
  105. if (__c >= _S_false && __c < _S_empty)
  106. __b._M_b = static_cast<_Bool_set_val>(__c);
  107. else
  108. {
  109. // What should we do here?
  110. __v = true;
  111. __err = ios_base::failbit;
  112. if (__beg == __end)
  113. __err |= ios_base::eofbit;
  114. }
  115. }
  116. else
  117. {
  118. // Parse bool values as alphanumeric.
  119. typedef __numpunct_cache<_CharT> __cache_type;
  120. __use_cache<__cache_type> __uc;
  121. const locale& __loc = __io._M_getloc();
  122. const __cache_type* __lc = __uc(__loc);
  123. bool __testf = true;
  124. bool __testt = true;
  125. bool __donef = __lc->_M_falsename_size == 0;
  126. bool __donet = __lc->_M_truename_size == 0;
  127. bool __testeof = false;
  128. size_t __n = 0;
  129. while (!__donef || !__donet)
  130. {
  131. if (__beg == __end)
  132. {
  133. __testeof = true;
  134. break;
  135. }
  136. const char_type __c = *__beg;
  137. if (!__donef)
  138. __testf = __c == __lc->_M_falsename[__n];
  139. if (!__testf && __donet)
  140. break;
  141. if (!__donet)
  142. __testt = __c == __lc->_M_truename[__n];
  143. if (!__testt && __donef)
  144. break;
  145. if (!__testt && !__testf)
  146. break;
  147. ++__n;
  148. ++__beg;
  149. __donef = !__testf || __n >= __lc->_M_falsename_size;
  150. __donet = !__testt || __n >= __lc->_M_truename_size;
  151. }
  152. if (__testf && __n == __lc->_M_falsename_size && __n)
  153. {
  154. __v = false;
  155. if (__testt && __n == __lc->_M_truename_size)
  156. __err = ios_base::failbit;
  157. else
  158. __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
  159. }
  160. else if (__testt && __n == __lc->_M_truename_size && __n)
  161. {
  162. __v = true;
  163. __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
  164. }
  165. else
  166. {
  167. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  168. // 23. Num_get overflow result.
  169. __v = false;
  170. __err = ios_base::failbit;
  171. if (__testeof)
  172. __err |= ios_base::eofbit;
  173. }
  174. }
  175. return __beg;
  176. }
  177. */
  178. /**
  179. * @brief Numeric formatting.
  180. *
  181. * Formats the boolean @a v and inserts it into a stream. It does so
  182. * by calling num_put::do_put().
  183. *
  184. * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
  185. * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
  186. *
  187. * @param s Stream to write to.
  188. * @param io Source of locale and flags.
  189. * @param fill Char_type to use for filling.
  190. * @param v Value to format and insert.
  191. * @return Iterator after writing.
  192. iter_type
  193. put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
  194. { return this->do_put(__s, __f, __fill, __v); }
  195. */
  196. /*
  197. template<typename _CharT, typename _OutIter>
  198. _OutIter
  199. num_put<_CharT, _OutIter>::
  200. do_put(iter_type __s, ios_base& __io, char_type __fill, bool_set __v) const
  201. {
  202. const ios_base::fmtflags __flags = __io.flags();
  203. if ((__flags & ios_base::boolalpha) == 0)
  204. {
  205. const long __l = __v;
  206. __s = _M_insert_int(__s, __io, __fill, __l);
  207. }
  208. else
  209. {
  210. typedef __numpunct_cache<_CharT> __cache_type;
  211. __use_cache<__cache_type> __uc;
  212. const locale& __loc = __io._M_getloc();
  213. const __cache_type* __lc = __uc(__loc);
  214. const _CharT* __name = __v ? __lc->_M_truename
  215. : __lc->_M_falsename;
  216. int __len = __v ? __lc->_M_truename_size
  217. : __lc->_M_falsename_size;
  218. const streamsize __w = __io.width();
  219. if (__w > static_cast<streamsize>(__len))
  220. {
  221. const streamsize __plen = __w - __len;
  222. _CharT* __ps
  223. = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
  224. * __plen));
  225. char_traits<_CharT>::assign(__ps, __plen, __fill);
  226. __io.width(0);
  227. if ((__flags & ios_base::adjustfield) == ios_base::left)
  228. {
  229. __s = std::__write(__s, __name, __len);
  230. __s = std::__write(__s, __ps, __plen);
  231. }
  232. else
  233. {
  234. __s = std::__write(__s, __ps, __plen);
  235. __s = std::__write(__s, __name, __len);
  236. }
  237. return __s;
  238. }
  239. __io.width(0);
  240. __s = std::__write(__s, __name, __len);
  241. }
  242. return __s;
  243. }
  244. */
  245. #endif // _GLIBCXX_TR2_BOOL_SET_TCC