The Gaudi Framework  v30r4 (9b837755)
CommonParsers.h
Go to the documentation of this file.
1 #pragma once
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // STD & STL
6 // ============================================================================
7 #include <list>
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 // ============================================================================
14 #include "GaudiKernel/HistoDef.h"
15 #include "GaudiKernel/Map.h"
16 #include "GaudiKernel/StatusCode.h"
17 // ============================================================================
18 #define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, const std::string& input );
19 
20 #define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \
21  GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, const std::string& input );
22 
23 #define PARSERS_DECL_FOR_LIST( InnerType ) \
24  GAUDI_API StatusCode parse( std::vector<InnerType>& result, const std::string& input );
25 // ============================================================================
57 // ============================================================================
58 namespace Gaudi
59 {
60  // ==========================================================================
61  class Histo1DDef;
62  // ==========================================================================
63  namespace Parsers
64  {
65  // ========================================================================
77  // ========================================================================
91  PARSERS_DECL_FOR_SINGLE( unsigned char )
93  PARSERS_DECL_FOR_SINGLE( signed char )
94  // ========================================================================
108  PARSERS_DECL_FOR_SINGLE( short )
110  PARSERS_DECL_FOR_SINGLE( unsigned short )
112  PARSERS_DECL_FOR_SINGLE( unsigned int )
116  PARSERS_DECL_FOR_SINGLE( unsigned long )
118  PARSERS_DECL_FOR_SINGLE( long long )
120  PARSERS_DECL_FOR_SINGLE( unsigned long long )
121  // ========================================================================
133  PARSERS_DECL_FOR_SINGLE( double )
135  PARSERS_DECL_FOR_SINGLE( float )
137  PARSERS_DECL_FOR_SINGLE( long double )
138  // ========================================================================
151  // ========================================================================
152 
153  PARSERS_DECL_FOR_LIST( bool )
154  PARSERS_DECL_FOR_LIST( char )
155  PARSERS_DECL_FOR_LIST( unsigned char )
156  PARSERS_DECL_FOR_LIST( signed char )
157 
158  PARSERS_DECL_FOR_LIST( int )
159  PARSERS_DECL_FOR_LIST( short )
160  PARSERS_DECL_FOR_LIST( unsigned short )
161  PARSERS_DECL_FOR_LIST( unsigned int )
162  PARSERS_DECL_FOR_LIST( long )
163  PARSERS_DECL_FOR_LIST( unsigned long )
164  PARSERS_DECL_FOR_LIST( long long )
165  PARSERS_DECL_FOR_LIST( unsigned long long )
166 
167  PARSERS_DECL_FOR_LIST( double )
168  PARSERS_DECL_FOR_LIST( float )
169  PARSERS_DECL_FOR_LIST( long double )
170 
172  // ========================================================================
173  // Advanced parses
174  // ========================================================================
187  PARSERS_DECL_FOR_PAIR( double, double )
188  // ========================================================================
201  PARSERS_DECL_FOR_PAIR( int, int )
202  // ========================================================================
217  // ========================================================================
232  // ========================================================================
233  // vector< vector< TYPE > >
234  // ========================================================================
248  // ========================================================================
262  // ========================================================================
263  // map< TYPE, TYPE >
264  // ========================================================================
277  GAUDI_API StatusCode parse( std::map<int, int>& result, const std::string& input );
278  // ========================================================================
293  // ========================================================================
307  // ========================================================================
322  // ========================================================================
337  // ========================================================================
354  // ========================================================================
371  // ========================================================================
388  // ========================================================================
397  // ========================================================================
406  // ========================================================================
412  // ========================================================================
417  template <typename K, typename V, typename M>
419  {
420  return parse( (M&)result, input );
421  }
422  // ========================================================================
450  // ========================================================================
459  GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, const std::string& input );
460  // ========================================================================
470  // ========================================================================
483  // ========================================================================
491  template <class T, unsigned int N>
492  StatusCode parse( T ( &result )[N], const std::string& input )
493  {
494  typedef std::vector<T> _Vct;
495  // create the temporary vector
496  _Vct tmp;
497  StatusCode sc = parse( tmp, input );
498  if ( sc.isFailure() ) {
499  return sc;
500  } // RETURN
501  if ( N != tmp.size() ) {
502  return StatusCode::FAILURE;
503  } // RETURN
504  //
505  std::copy( tmp.begin(), tmp.end(), result );
506  //
507  return StatusCode::SUCCESS; // RETURN
508  }
509  // ========================================================================
517  template <unsigned int N>
518  StatusCode parse( char ( &result )[N], const std::string& input )
519  {
520  // clear the string
521  std::fill_n( result, N, ' ' );
522  // create the temporary string
523  std::string tmp;
524  StatusCode sc = parse( tmp, input );
525  if ( sc.isFailure() ) {
526  return sc;
527  } // RETURN
528  if ( N == tmp.size() ) {
529  std::copy( tmp.begin(), tmp.end(), result );
530  } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
531  std::copy( tmp.begin() + 1, tmp.end() - 1, result );
532  } else {
533  return StatusCode::FAILURE;
534  }
535  //
536  return StatusCode::SUCCESS; // RETURN
537  }
538  // ========================================================================
539  } // end of namespace Gaudi::Parsers
540  // ==========================================================================
541 } // end of namespace Gaudi
constexpr static const auto FAILURE
Definition: StatusCode.h:88
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)
STL class.
bool isFailure() const
Definition: StatusCode.h:139
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: CommonParsers.h:20
STL class.
int N
Definition: IOTest.py:101
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:33
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: CommonParsers.h:18
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T size(T...args)
STL class.
T begin(T...args)
T fill_n(T...args)
#define GAUDI_API
Definition: Kernel.h:71
Helper functions to set/get the application return code.
Definition: __init__.py:1
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: CommonParsers.h:23