File indexing completed on 2025-01-18 10:10:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef ROOT_Math_GenVector_GenVectorIO
0020 #define ROOT_Math_GenVector_GenVectorIO 1
0021
0022 #include <cctype>
0023 #include <iostream>
0024
0025
0026 namespace ROOT {
0027 namespace Math {
0028
0029 namespace detail {
0030
0031
0032
0033
0034
0035 enum manip_t { open, sep, close, bitforbit };
0036
0037
0038 inline int
0039 ios_data( int k )
0040 {
0041 static int const ios_data[4] = { std::ios::xalloc()
0042 , std::ios::xalloc()
0043 , std::ios::xalloc()
0044 , std::ios::xalloc()
0045 };
0046
0047 return ios_data[k];
0048
0049 }
0050
0051
0052 template< class char_t, class traits_t >
0053 inline char_t
0054 get_manip( std::basic_ios<char_t,traits_t> & ios
0055 , manip_t m
0056 )
0057 {
0058 char_t ch = static_cast<char_t>( ios.iword( ios_data(m) ) );
0059 if( ch ) return ch;
0060
0061 switch( m )
0062 { default : return ios.widen( '?' );
0063 case open : return ios.widen( '(' );
0064 case close : return ios.widen( ')' );
0065 case sep : return ios.widen( ',' );
0066 case bitforbit : return ch;
0067 }
0068
0069 }
0070
0071
0072 template< class char_t, class traits_t >
0073 inline void
0074 set_manip( std::basic_ios<char_t,traits_t> & ios
0075 , manip_t m
0076 , char_t ch
0077 )
0078 {
0079 ios.iword( ios_data(m) ) = static_cast<long>(ch);
0080
0081 }
0082
0083
0084 template< class char_t >
0085 class manipulator
0086 {
0087 public:
0088 explicit
0089 manipulator( manip_t m
0090 , char_t ch = 0
0091 )
0092 : fMan(m)
0093 , fChar(ch)
0094 { }
0095
0096 template< class traits_t >
0097 void
0098 set( std::basic_ios<char_t,traits_t> & ios ) const
0099 {
0100 set_manip<char_t>( ios, fMan, fChar );
0101 }
0102
0103 private:
0104 manip_t fMan;
0105 char_t fChar;
0106
0107 };
0108
0109
0110 template< class char_t, class traits_t >
0111 inline
0112 std::basic_istream<char_t,traits_t> &
0113 require_delim( std::basic_istream<char_t,traits_t> & is
0114 , manip_t m
0115 )
0116 {
0117 char_t delim = get_manip( is, m );
0118 if( std::isspace(delim) ) return is;
0119
0120 char_t ch;
0121 is >> ch;
0122 if( ch != delim )
0123 is.setstate( std::ios::failbit );
0124
0125 return is;
0126
0127 }
0128
0129
0130 template< class char_t, class traits_t >
0131 inline
0132 std::basic_ostream<char_t,traits_t> &
0133 operator << ( std::basic_ostream<char_t,traits_t> & os
0134 , detail::manipulator<char_t> const & manip
0135 )
0136
0137 {
0138 manip.set(os);
0139 return os;
0140
0141 }
0142
0143
0144 template< class char_t, class traits_t >
0145 inline
0146 std::basic_istream<char_t,traits_t> &
0147 operator >> ( std::basic_istream<char_t,traits_t> & is
0148 , detail::manipulator<char_t> const & manip
0149 )
0150
0151 {
0152 manip.set(is);
0153 return is;
0154
0155 }
0156
0157 }
0158
0159
0160
0161
0162
0163
0164 template< class char_t >
0165 inline
0166 detail::manipulator<char_t>
0167 set_open( char_t ch )
0168 {
0169 return detail::manipulator<char_t>( detail::open, ch );
0170
0171 }
0172
0173
0174 template< class char_t >
0175 inline
0176 detail::manipulator<char_t>
0177 set_separator( char_t ch )
0178 {
0179 return detail::manipulator<char_t>( detail::sep, ch );
0180
0181 }
0182
0183
0184 template< class char_t >
0185 inline
0186 detail::manipulator<char_t>
0187 set_close( char_t ch )
0188 {
0189 return detail::manipulator<char_t>( detail::close, ch );
0190
0191 }
0192
0193
0194 template< class char_t, class traits_t >
0195 inline
0196 std::basic_ios<char_t,traits_t> &
0197 human_readable( std::basic_ios<char_t,traits_t> & ios )
0198 {
0199 ios.iword( ios_data(detail::bitforbit) ) = 0L;
0200 return ios;
0201
0202 }
0203
0204
0205 template< class char_t, class traits_t >
0206 inline
0207 std::basic_ios<char_t,traits_t> &
0208 machine_readable( std::basic_ios<char_t,traits_t> & ios )
0209 {
0210 ios.iword( ios_data(detail::bitforbit) ) = 1L;
0211 return ios;
0212
0213 }
0214
0215
0216
0217 }
0218 }
0219
0220
0221 #endif