Logo ROOT   6.07/09
Reference Guide
GenVectorIO.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT MathLib Team (FNAL component) *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Support templates (class and function) for stream i/o of vectors
12 // This is a utuility to allow for control, via manipulators, of the
13 // form of
14 //
15 // Created by: W. E. Brown and M. Fischler at Tue Jun 21 2005
16 //
17 // Last update: Tue Jun 21 2005
18 //
19 #ifndef ROOT_Math_GenVector_GenVectorIO
20 #define ROOT_Math_GenVector_GenVectorIO 1
21 
22 #include <cctype>
23 #include <iostream>
24 
25 
26 namespace ROOT {
27 namespace Math {
28 
29 namespace detail {
30 
31 
32 // -------- Manipulator support ----------
33 
34 
36 
37 
38 inline int
39  ios_data( int k )
40 {
41  static int const ios_data[4] = { std::ios::xalloc() // open
42  , std::ios::xalloc() // sep
43  , std::ios::xalloc() // close
44  , std::ios::xalloc() // bitforbit
45  };
46 
47  return ios_data[k];
48 
49 } // ios_data()
50 
51 
52 template< class char_t, class traits_t >
53  inline char_t
54  get_manip( std::basic_ios<char_t,traits_t> & ios
55  , manip_t m
56  )
57 {
58  char_t ch = static_cast<char_t>( ios.iword( ios_data(m) ) );
59  if( ch ) return ch;
60 
61  switch( m )
62  { default : return ios.widen( '?' );
63  case open : return ios.widen( '(' );
64  case close : return ios.widen( ')' );
65  case sep : return ios.widen( ',' );
66  case bitforbit : return ch;
67  }
68 
69 } // get_manip<>()
70 
71 
72 template< class char_t, class traits_t >
73  inline void
74  set_manip( std::basic_ios<char_t,traits_t> & ios
75  , manip_t m
76  , char_t ch
77  )
78 {
79  ios.iword( ios_data(m) ) = static_cast<long>(ch);
80 
81 } // set_manip<>()
82 
83 
84 template< class char_t >
86 {
87 public:
88  explicit
90  , char_t ch = 0
91  )
92  : fMan(m)
93  , fChar(ch)
94  { }
95 
96  template< class traits_t >
97  void
98  set( std::basic_ios<char_t,traits_t> & ios ) const
99  {
100  set_manip<char_t>( ios, fMan, fChar );
101  }
102 
103 private:
105  char_t fChar;
106 
107 }; // manipulator<>
108 
109 
110 template< class char_t, class traits_t >
111  inline
112  std::basic_istream<char_t,traits_t> &
113  require_delim( std::basic_istream<char_t,traits_t> & is
114  , manip_t m
115  )
116 {
117  char_t delim = get_manip( is, m );
118  if( std::isspace(delim) ) return is;
119 
120  char_t ch;
121  is >> ch;
122  if( ch != delim )
123  is.setstate( std::ios::failbit );
124 
125  return is;
126 
127 } // require_delim<>()
128 
129 
130 template< class char_t, class traits_t >
131  inline
132  std::basic_ostream<char_t,traits_t> &
133  operator << ( std::basic_ostream<char_t,traits_t> & os
134  , detail::manipulator<char_t> const & manip
135  )
136 
137 {
138  manip.set(os);
139  return os;
140 
141 } // op<< <>()
142 
143 
144 template< class char_t, class traits_t >
145  inline
146  std::basic_istream<char_t,traits_t> &
147  operator >> ( std::basic_istream<char_t,traits_t> & is
148  , detail::manipulator<char_t> const & manip
149  )
150 
151 {
152  manip.set(is);
153  return is;
154 
155 } // op>> <>()
156 
157 } // namespace detail
158 
159 
160 // --------- Functions that allow a user to control vector I/O ----------
161 
162 
163 
164 template< class char_t >
165  inline
167  set_open( char_t ch )
168 {
170 
171 } // set_open<>()
172 
173 
174 template< class char_t >
175  inline
177  set_separator( char_t ch )
178 {
180 
181 } // set_separator<>()
182 
183 
184 template< class char_t >
185  inline
187  set_close( char_t ch )
188 {
190 
191 } // set_close<>()
192 
193 
194 template< class char_t, class traits_t >
195  inline
196  std::basic_ios<char_t,traits_t> &
197  human_readable( std::basic_ios<char_t,traits_t> & ios )
198 {
199  ios.iword( ios_data(detail::bitforbit) ) = 0L;
200  return ios;
201 
202 } // human_readable<>()
203 
204 
205 template< class char_t, class traits_t >
206  inline
207  std::basic_ios<char_t,traits_t> &
208  machine_readable( std::basic_ios<char_t,traits_t> & ios )
209 {
210  ios.iword( ios_data(detail::bitforbit) ) = 1L;
211  return ios;
212 
213 } // machine_readable<>()
214 
215 
216 
217 } // namespace ROOT
218 } // namespace Math
219 
220 
221 #endif // ROOT_Math_GenVector_GenVectorIO
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
detail::manipulator< char_t > set_open(char_t ch)
Definition: GenVectorIO.h:167
RooArgList L(const RooAbsArg &v1)
manipulator(manip_t m, char_t ch=0)
Definition: GenVectorIO.h:89
int ios_data(int k)
Definition: GenVectorIO.h:39
detail::manipulator< char_t > set_separator(char_t ch)
Definition: GenVectorIO.h:177
std::basic_istream< char_t, traits_t > & operator>>(std::basic_istream< char_t, traits_t > &is, detail::manipulator< char_t > const &manip)
Definition: GenVectorIO.h:147
char_t get_manip(std::basic_ios< char_t, traits_t > &ios, manip_t m)
Definition: GenVectorIO.h:54
std::basic_ios< char_t, traits_t > & human_readable(std::basic_ios< char_t, traits_t > &ios)
Definition: GenVectorIO.h:197
TMarker * m
Definition: textangle.C:8
void set(std::basic_ios< char_t, traits_t > &ios) const
Definition: GenVectorIO.h:98
std::basic_ios< char_t, traits_t > & machine_readable(std::basic_ios< char_t, traits_t > &ios)
Definition: GenVectorIO.h:208
void set_manip(std::basic_ios< char_t, traits_t > &ios, manip_t m, char_t ch)
Definition: GenVectorIO.h:74
Namespace for new Math classes and functions.
std::basic_istream< char_t, traits_t > & require_delim(std::basic_istream< char_t, traits_t > &is, manip_t m)
Definition: GenVectorIO.h:113
detail::manipulator< char_t > set_close(char_t ch)
Definition: GenVectorIO.h:187