libstdc++
bool_set.tcc
Go to the documentation of this file.
00001 // TR2 <bool_set> support files -*- C++ -*-
00002 
00003 // Copyright (C) 2009, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file tr2/bool_set.tcc
00026  *  This is a TR2 C++ Library header.
00027  */
00028 
00029 #ifndef _GLIBCXX_TR2_BOOL_SET_TCC
00030 #define _GLIBCXX_TR2_BOOL_SET_TCC 1
00031 
00032 #pragma GCC system_header
00033 
00034 namespace std _GLIBCXX_VISIBILITY(default)
00035 {
00036 namespace tr2
00037 {
00038 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00039 
00040   bool_set::_Bool_set_val
00041   bool_set::_S_not[4] =
00042   { _S_true_, _S_false, _S_indet, _S_empty };
00043 
00044   bool_set::_Bool_set_val
00045   bool_set::_S_xor[4][4] =
00046   { { _S_false, _S_true_, _S_indet, _S_empty },
00047     { _S_true_, _S_false, _S_indet, _S_empty },
00048     { _S_indet, _S_indet, _S_indet, _S_empty },
00049     { _S_empty, _S_empty, _S_empty, _S_empty } };
00050 
00051   bool_set::_Bool_set_val
00052   bool_set::_S_or[4][4] =
00053   { { _S_false, _S_true_, _S_indet, _S_empty },
00054     { _S_true_, _S_true_, _S_true_, _S_empty },
00055     { _S_indet, _S_true_, _S_indet, _S_empty },
00056     { _S_empty, _S_empty, _S_empty, _S_empty } };
00057 
00058   bool_set::_Bool_set_val
00059   bool_set::_S_and[4][4] =
00060   { { _S_false, _S_false, _S_false, _S_empty },
00061     { _S_false, _S_true_, _S_indet, _S_empty },
00062     { _S_false, _S_indet, _S_indet, _S_empty },
00063     { _S_empty, _S_empty, _S_empty, _S_empty } };
00064 
00065   bool_set::_Bool_set_val
00066   bool_set::_S_eq[4][4] =
00067   { { _S_true_, _S_false, _S_indet, _S_empty },
00068     { _S_false, _S_true_, _S_indet, _S_empty },
00069     { _S_indet, _S_indet, _S_indet, _S_empty },
00070     { _S_empty, _S_empty, _S_empty, _S_empty } };
00071 
00072 _GLIBCXX_END_NAMESPACE_VERSION
00073 }
00074 }
00075 
00076 //  I object to these things.
00077 //  The stuff in locale facets are for basic types.
00078 //  I think we could hack operator<< and operator>>.
00079 
00080       /**
00081        *  @brief  Numeric parsing.
00082        *
00083        *  Parses the input stream into the bool @a v.  It does so by calling
00084        *  num_get::do_get().
00085        *
00086        *  If ios_base::boolalpha is set, attempts to read
00087        *  ctype<CharT>::truename() or ctype<CharT>::falsename().  Sets
00088        *  @a v to true or false if successful.  Sets err to
00089        *  ios_base::failbit if reading the string fails.  Sets err to
00090        *  ios_base::eofbit if the stream is emptied.
00091        *
00092        *  If ios_base::boolalpha is not set, proceeds as with reading a long,
00093        *  except if the value is 1, sets @a v to true, if the value is 0, sets
00094        *  @a v to false, and otherwise set err to ios_base::failbit.
00095        *
00096        *  @param  in  Start of input stream.
00097        *  @param  end  End of input stream.
00098        *  @param  io  Source of locale and flags.
00099        *  @param  err  Error flags to set.
00100        *  @param  v  Value to format and insert.
00101        *  @return  Iterator after reading.
00102       iter_type
00103       get(iter_type __in, iter_type __end, ios_base& __io,
00104       ios_base::iostate& __err, bool& __v) const
00105       { return this->do_get(__in, __end, __io, __err, __v); }
00106        */
00107 /*
00108   template<typename _CharT, typename _InIter>
00109     _InIter
00110     num_get<_CharT, _InIter>::
00111     do_get(iter_type __beg, iter_type __end, ios_base& __io,
00112        ios_base::iostate& __err, bool_set& __v) const
00113     {
00114       if (!(__io.flags() & ios_base::boolalpha))
00115     {
00116       // Parse bool values as long.
00117       // NB: We can't just call do_get(long) here, as it might
00118       // refer to a derived class.
00119       long __l = -1;
00120       __beg = _M_extract_int(__beg, __end, __io, __err, __l);
00121       if (__c >= _S_false && __c < _S_empty)
00122         __b._M_b = static_cast<_Bool_set_val>(__c);
00123       else
00124         {
00125           // What should we do here?
00126           __v = true;
00127           __err = ios_base::failbit;
00128           if (__beg == __end)
00129         __err |= ios_base::eofbit;
00130         }
00131     }
00132       else
00133     {
00134       // Parse bool values as alphanumeric.
00135       typedef __numpunct_cache<_CharT>  __cache_type;
00136       __use_cache<__cache_type> __uc;
00137       const locale& __loc = __io._M_getloc();
00138       const __cache_type* __lc = __uc(__loc);
00139 
00140       bool __testf = true;
00141       bool __testt = true;
00142       bool __donef = __lc->_M_falsename_size == 0;
00143       bool __donet = __lc->_M_truename_size == 0;
00144       bool __testeof = false;
00145       size_t __n = 0;
00146       while (!__donef || !__donet)
00147         {
00148           if (__beg == __end)
00149         {
00150           __testeof = true;
00151           break;
00152         }
00153 
00154           const char_type __c = *__beg;
00155 
00156           if (!__donef)
00157         __testf = __c == __lc->_M_falsename[__n];
00158 
00159           if (!__testf && __donet)
00160         break;
00161 
00162           if (!__donet)
00163         __testt = __c == __lc->_M_truename[__n];
00164 
00165           if (!__testt && __donef)
00166         break;
00167 
00168           if (!__testt && !__testf)
00169         break;
00170 
00171           ++__n;
00172           ++__beg;
00173 
00174           __donef = !__testf || __n >= __lc->_M_falsename_size;
00175           __donet = !__testt || __n >= __lc->_M_truename_size;
00176         }
00177       if (__testf && __n == __lc->_M_falsename_size && __n)
00178         {
00179           __v = false;
00180           if (__testt && __n == __lc->_M_truename_size)
00181         __err = ios_base::failbit;
00182           else
00183         __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
00184         }
00185       else if (__testt && __n == __lc->_M_truename_size && __n)
00186         {
00187           __v = true;
00188           __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
00189         }
00190       else
00191         {
00192           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00193           // 23. Num_get overflow result.
00194           __v = false;
00195           __err = ios_base::failbit;
00196           if (__testeof)
00197         __err |= ios_base::eofbit;
00198         }
00199     }
00200       return __beg;
00201     }
00202 */
00203 
00204       /**
00205        *  @brief  Numeric formatting.
00206        *
00207        *  Formats the boolean @a v and inserts it into a stream.  It does so
00208        *  by calling num_put::do_put().
00209        *
00210        *  If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
00211        *  ctype<CharT>::falsename().  Otherwise formats @a v as an int.
00212        *
00213        *  @param  s  Stream to write to.
00214        *  @param  io  Source of locale and flags.
00215        *  @param  fill  Char_type to use for filling.
00216        *  @param  v  Value to format and insert.
00217        *  @return  Iterator after writing.
00218       iter_type
00219       put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
00220       { return this->do_put(__s, __f, __fill, __v); }
00221        */
00222 
00223 /*
00224   template<typename _CharT, typename _OutIter>
00225     _OutIter
00226     num_put<_CharT, _OutIter>::
00227     do_put(iter_type __s, ios_base& __io, char_type __fill, bool_set __v) const
00228     {
00229       const ios_base::fmtflags __flags = __io.flags();
00230       if ((__flags & ios_base::boolalpha) == 0)
00231     {
00232       const long __l = __v;
00233       __s = _M_insert_int(__s, __io, __fill, __l);
00234     }
00235       else
00236     {
00237       typedef __numpunct_cache<_CharT> __cache_type;
00238       __use_cache<__cache_type> __uc;
00239       const locale& __loc = __io._M_getloc();
00240       const __cache_type* __lc = __uc(__loc);
00241 
00242       const _CharT* __name = __v ? __lc->_M_truename
00243                      : __lc->_M_falsename;
00244       int __len = __v ? __lc->_M_truename_size
00245               : __lc->_M_falsename_size;
00246 
00247       const streamsize __w = __io.width();
00248       if (__w > static_cast<streamsize>(__len))
00249         {
00250           const streamsize __plen = __w - __len;
00251           _CharT* __ps
00252         = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00253                             * __plen));
00254 
00255           char_traits<_CharT>::assign(__ps, __plen, __fill);
00256           __io.width(0);
00257 
00258           if ((__flags & ios_base::adjustfield) == ios_base::left)
00259         {
00260           __s = std::__write(__s, __name, __len);
00261           __s = std::__write(__s, __ps, __plen);
00262         }
00263           else
00264         {
00265           __s = std::__write(__s, __ps, __plen);
00266           __s = std::__write(__s, __name, __len);
00267         }
00268           return __s;
00269         }
00270       __io.width(0);
00271       __s = std::__write(__s, __name, __len);
00272     }
00273       return __s;
00274     }
00275 */
00276 
00277 #endif // _GLIBCXX_TR2_BOOL_SET_TCC