Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  class Histo1DDef;
61  // ==========================================================================
62  namespace Parsers {
63  // ========================================================================
75  // ========================================================================
89  PARSERS_DECL_FOR_SINGLE( unsigned char )
91  PARSERS_DECL_FOR_SINGLE( signed char )
92  // ========================================================================
106  PARSERS_DECL_FOR_SINGLE( short )
108  PARSERS_DECL_FOR_SINGLE( unsigned short )
110  PARSERS_DECL_FOR_SINGLE( unsigned int )
114  PARSERS_DECL_FOR_SINGLE( unsigned long )
116  PARSERS_DECL_FOR_SINGLE( long long )
118  PARSERS_DECL_FOR_SINGLE( unsigned long long )
119  // ========================================================================
131  PARSERS_DECL_FOR_SINGLE( double )
133  PARSERS_DECL_FOR_SINGLE( float )
135  PARSERS_DECL_FOR_SINGLE( long double )
136  // ========================================================================
149  // ========================================================================
150 
151  PARSERS_DECL_FOR_LIST( bool )
152  PARSERS_DECL_FOR_LIST( char )
153  PARSERS_DECL_FOR_LIST( unsigned char )
154  PARSERS_DECL_FOR_LIST( signed char )
155 
156  PARSERS_DECL_FOR_LIST( int )
157  PARSERS_DECL_FOR_LIST( short )
158  PARSERS_DECL_FOR_LIST( unsigned short )
159  PARSERS_DECL_FOR_LIST( unsigned int )
160  PARSERS_DECL_FOR_LIST( long )
161  PARSERS_DECL_FOR_LIST( unsigned long )
162  PARSERS_DECL_FOR_LIST( long long )
163  PARSERS_DECL_FOR_LIST( unsigned long long )
164 
165  PARSERS_DECL_FOR_LIST( double )
166  PARSERS_DECL_FOR_LIST( float )
167  PARSERS_DECL_FOR_LIST( long double )
168 
170  // ========================================================================
171  // Advanced parses
172  // ========================================================================
185  PARSERS_DECL_FOR_PAIR( double, double )
186  // ========================================================================
199  PARSERS_DECL_FOR_PAIR( int, int )
200  // ========================================================================
215  // ========================================================================
230  // ========================================================================
231  // vector< vector< TYPE > >
232  // ========================================================================
246  // ========================================================================
260  // ========================================================================
261  // map< TYPE, TYPE >
262  // ========================================================================
275  GAUDI_API StatusCode parse( std::map<int, int>& result, const std::string& input );
276  // ========================================================================
291  // ========================================================================
305  // ========================================================================
320  // ========================================================================
335  // ========================================================================
352  // ========================================================================
369  // ========================================================================
386  // ========================================================================
395  // ========================================================================
404  // ========================================================================
410  // ========================================================================
415  template <typename K, typename V, typename M>
417  return parse( (M&)result, input );
418  }
419  // ========================================================================
447  // ========================================================================
456  GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, const std::string& input );
457  // ========================================================================
467  // ========================================================================
480  // ========================================================================
488  template <class T, unsigned int N>
489  StatusCode parse( T ( &result )[N], const std::string& input ) {
490  typedef std::vector<T> _Vct;
491  // create the temporary vector
492  _Vct tmp;
493  StatusCode sc = parse( tmp, input );
494  if ( sc.isFailure() ) { return sc; } // RETURN
495  if ( N != tmp.size() ) { return StatusCode::FAILURE; } // RETURN
496  //
497  std::copy( tmp.begin(), tmp.end(), result );
498  //
499  return StatusCode::SUCCESS; // RETURN
500  }
501  // ========================================================================
509  template <unsigned int N>
510  StatusCode parse( char ( &result )[N], const std::string& input ) {
511  // clear the string
512  std::fill_n( result, N, ' ' );
513  // create the temporary string
514  std::string tmp;
515  StatusCode sc = parse( tmp, input );
516  if ( sc.isFailure() ) { return sc; } // RETURN
517  if ( N == tmp.size() ) {
518  std::copy( tmp.begin(), tmp.end(), result );
519  } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
520  std::copy( tmp.begin() + 1, tmp.end() - 1, result );
521  } else {
522  return StatusCode::FAILURE;
523  }
524  //
525  return StatusCode::SUCCESS; // RETURN
526  }
527  // ========================================================================
528  } // namespace Parsers
529  // ==========================================================================
530 } // end of namespace Gaudi
Extension of the STL map.
Definition: Map.h:81
T copy(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
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:130
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: CommonParsers.h:20
STL class.
int N
Definition: IOTest.py:99
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:31
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: CommonParsers.h:18
T size(T...args)
STL class.
T begin(T...args)
T fill_n(T...args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
#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