The Gaudi Framework  v29r0 (ff2e7097)
Parsers.h
Go to the documentation of this file.
1 // ============================================================================
2 #ifndef GAUDIPROPERTYPARSERS_PARSERS_H
3 #define GAUDIPROPERTYPARSERS_PARSERS_H 1
4 // ============================================================================
5 // Include files
6 // ============================================================================
7 // STD & STL
8 // ============================================================================
9 #include <list>
10 #include <map>
11 #include <set>
12 #include <string>
13 #include <vector>
14 
15 // ============================================================================
16 #include "GaudiKernel/HistoDef.h"
17 #include "GaudiKernel/Map.h"
18 #include "GaudiKernel/StatusCode.h"
19 // ============================================================================
20 #define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, const std::string& input );
21 
22 #define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \
23  GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, const std::string& input );
24 
25 #define PARSERS_DECL_FOR_LIST( InnerType ) \
26  GAUDI_API StatusCode parse( std::vector<InnerType>& result, const std::string& input );
27 // ============================================================================
59 // ============================================================================
60 namespace Gaudi
61 {
62  // ==========================================================================
63  class Histo1DDef;
64  // ==========================================================================
65  namespace Parsers
66  {
67  // ========================================================================
79  // ========================================================================
93  PARSERS_DECL_FOR_SINGLE( unsigned char )
95  PARSERS_DECL_FOR_SINGLE( signed char )
96  // ========================================================================
110  PARSERS_DECL_FOR_SINGLE( short )
112  PARSERS_DECL_FOR_SINGLE( unsigned short )
114  PARSERS_DECL_FOR_SINGLE( unsigned int )
118  PARSERS_DECL_FOR_SINGLE( unsigned long )
120  PARSERS_DECL_FOR_SINGLE( long long )
122  PARSERS_DECL_FOR_SINGLE( unsigned long long )
123  // ========================================================================
135  PARSERS_DECL_FOR_SINGLE( double )
137  PARSERS_DECL_FOR_SINGLE( float )
139  PARSERS_DECL_FOR_SINGLE( long double )
140  // ========================================================================
153  // ========================================================================
154 
155  PARSERS_DECL_FOR_LIST( bool )
156  PARSERS_DECL_FOR_LIST( char )
157  PARSERS_DECL_FOR_LIST( unsigned char )
158  PARSERS_DECL_FOR_LIST( signed char )
159 
160  PARSERS_DECL_FOR_LIST( int )
161  PARSERS_DECL_FOR_LIST( short )
162  PARSERS_DECL_FOR_LIST( unsigned short )
163  PARSERS_DECL_FOR_LIST( unsigned int )
164  PARSERS_DECL_FOR_LIST( long )
165  PARSERS_DECL_FOR_LIST( unsigned long )
166  PARSERS_DECL_FOR_LIST( long long )
167  PARSERS_DECL_FOR_LIST( unsigned long long )
168 
169  PARSERS_DECL_FOR_LIST( double )
170  PARSERS_DECL_FOR_LIST( float )
171  PARSERS_DECL_FOR_LIST( long double )
172 
174  // ========================================================================
175  // Advanced parses
176  // ========================================================================
189  PARSERS_DECL_FOR_PAIR( double, double )
190  // ========================================================================
203  PARSERS_DECL_FOR_PAIR( int, int )
204  // ========================================================================
219  // ========================================================================
234  // ========================================================================
235  // vector< vector< TYPE > >
236  // ========================================================================
250  // ========================================================================
264  // ========================================================================
265  // map< TYPE, TYPE >
266  // ========================================================================
279  GAUDI_API StatusCode parse( std::map<int, int>& result, const std::string& input );
280  // ========================================================================
295  // ========================================================================
309  // ========================================================================
324  // ========================================================================
339  // ========================================================================
356  // ========================================================================
373  // ========================================================================
390  // ========================================================================
399  // ========================================================================
408  // ========================================================================
414  // ========================================================================
419  template <typename K, typename V, typename M>
421  {
422  return parse( (M&)result, input );
423  }
424  // ========================================================================
452  // ========================================================================
461  GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, const std::string& input );
462  // ========================================================================
472  // ========================================================================
485  // ========================================================================
493  template <class T, unsigned int N>
494  StatusCode parse( T ( &result )[N], const std::string& input )
495  {
496  typedef std::vector<T> _Vct;
497  // create the temporary vector
498  _Vct tmp;
499  StatusCode sc = parse( tmp, input );
500  if ( sc.isFailure() ) {
501  return sc;
502  } // RETURN
503  if ( N != tmp.size() ) {
504  return StatusCode::FAILURE;
505  } // RETURN
506  //
507  std::copy( tmp.begin(), tmp.end(), result );
508  //
509  return StatusCode::SUCCESS; // RETURN
510  }
511  // ========================================================================
519  template <unsigned int N>
520  StatusCode parse( char ( &result )[N], const std::string& input )
521  {
522  // clear the string
523  std::fill_n( result, N, ' ' );
524  // create the temporary string
525  std::string tmp;
526  StatusCode sc = parse( tmp, input );
527  if ( sc.isFailure() ) {
528  return sc;
529  } // RETURN
530  if ( N == tmp.size() ) {
531  std::copy( tmp.begin(), tmp.end(), result );
532  } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
533  std::copy( tmp.begin() + 1, tmp.end() - 1, result );
534  } else {
535  return StatusCode::FAILURE;
536  }
537  //
538  return StatusCode::SUCCESS; // RETURN
539  }
540  // ========================================================================
541  } // end of namespace Gaudi::Parsers
542  // ==========================================================================
543 } // end of namespace Gaudi
544 // ============================================================================
545 // The END
546 // ============================================================================
547 #endif // GAUDIPROPERTYPARSERS_PARSERS_H
548 // ============================================================================
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: Parsers.h:22
Extension of the STL map.
Definition: Map.h:82
T copy(T...args)
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
T end(T...args)
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: Parsers.h:20
STL class.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
STL class.
int N
Definition: IOTest.py:101
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: Parsers.h:25
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:33
T size(T...args)
STL class.
T begin(T...args)
T fill_n(T...args)
#define GAUDI_API
Definition: Kernel.h:110
Helper functions to set/get the application return code.
Definition: __init__.py:1