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 <string>
10 #include <vector>
11 #include <list>
12 #include <set>
13 #include <map>
14 
15 // ============================================================================
16 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/HistoDef.h"
18 #include "GaudiKernel/Map.h"
19 // ============================================================================
20 #define PARSERS_DECL_FOR_SINGLE(Type)\
21  GAUDI_API StatusCode parse(Type& result, const std::string& input);
22 
23 #define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)\
24  GAUDI_API StatusCode parse(std::pair<FirstType, SecondType >& result,\
25  const std::string& input);
26 
27 #define PARSERS_DECL_FOR_LIST(InnerType)\
28  GAUDI_API StatusCode parse(std::vector<InnerType>& result,\
29  const std::string& input);
30 // ============================================================================
62 // ============================================================================
63 namespace Gaudi
64 {
65  // ==========================================================================
66  class Histo1DDef ;
67  // ==========================================================================
68  namespace Parsers
69  {
70  // ========================================================================
82  // ========================================================================
96  PARSERS_DECL_FOR_SINGLE(unsigned char)
98  PARSERS_DECL_FOR_SINGLE(signed char)
99  // ========================================================================
115  PARSERS_DECL_FOR_SINGLE(unsigned short)
117  PARSERS_DECL_FOR_SINGLE(unsigned int)
121  PARSERS_DECL_FOR_SINGLE(unsigned long)
123  PARSERS_DECL_FOR_SINGLE(long long)
125  PARSERS_DECL_FOR_SINGLE(unsigned long long)
126  // ========================================================================
142  PARSERS_DECL_FOR_SINGLE(long double)
143  // ========================================================================
156  // ========================================================================
157 
160  PARSERS_DECL_FOR_LIST(unsigned char)
161  PARSERS_DECL_FOR_LIST(signed char)
162 
164  PARSERS_DECL_FOR_LIST(short)
165  PARSERS_DECL_FOR_LIST(unsigned short)
166  PARSERS_DECL_FOR_LIST(unsigned int)
168  PARSERS_DECL_FOR_LIST(unsigned long)
169  PARSERS_DECL_FOR_LIST(long long)
170  PARSERS_DECL_FOR_LIST(unsigned long long)
171 
172  PARSERS_DECL_FOR_LIST(double)
173  PARSERS_DECL_FOR_LIST(float)
174  PARSERS_DECL_FOR_LIST(long double)
175 
177  // ========================================================================
178  // Advanced parses
179  // ========================================================================
192  PARSERS_DECL_FOR_PAIR(double,double)
193  // ========================================================================
206  PARSERS_DECL_FOR_PAIR(int, int)
207  // ========================================================================
223  const std::string& input ) ;
224  // ========================================================================
239  ( std::vector< std::pair<int,int> >& result ,
240  const std::string& input ) ;
241  // ========================================================================
242  // vector< vector< TYPE > >
243  // ========================================================================
258  const std::string& input ) ;
259  // ========================================================================
273  ( std::vector< std::vector<double> >& result ,
274  const std::string& input ) ;
275  // ========================================================================
276  // map< TYPE, TYPE >
277  // ========================================================================
291  ( std::map< int , int >& result ,
292  const std::string& input ) ;
293  // ========================================================================
308  ( std::map< int , double >& result ,
309  const std::string& input ) ;
310  // ========================================================================
325  const std::string& input ) ;
326  // ========================================================================
342  const std::string& input ) ;
343  // ========================================================================
359  const std::string& input ) ;
360  // ========================================================================
378  const std::string& input ) ;
379  // ========================================================================
396  ( std::map< std::string , std::vector< int > >& result ,
397  const std::string& input ) ;
398  // ========================================================================
416  const std::string& input ) ;
417  // ========================================================================
426  ( std::map<int, std::string>& result ,
427  const std::string& input ) ;
428  // ========================================================================
438  const std::string& input ) ;
439  // ========================================================================
446  const std::string& input ) ;
447  // ========================================================================
452  template <typename K, typename V, typename M>
455  const std::string& input ) {
456  return parse((M&)result, input);
457  }
458  // ========================================================================
486  ( std::string& name ,
487  std::string& value ,
488  const std::string& input ) ;
489  // ========================================================================
499  ( Gaudi::Histo1DDef& histo ,
500  const std::string& input ) ;
501  // ========================================================================
512  const std::string& input ) ;
513  // ========================================================================
527  const std::string& input ) ;
528  // ========================================================================
536  template <class T, unsigned int N>
537  StatusCode parse ( T(&result)[N] , const std::string& input )
538  {
539  typedef std::vector<T> _Vct ;
540  // create the temporary vector
541  _Vct tmp ;
542  StatusCode sc = parse ( tmp , input ) ;
543  if ( sc.isFailure() ) { return sc ; } // RETURN
544  if ( N != tmp.size() ) { return StatusCode::FAILURE ; } // RETURN
545  //
546  std::copy ( tmp.begin() , tmp.end() , result ) ;
547  //
548  return StatusCode::SUCCESS ; // RETURN
549  }
550  // ========================================================================
558  template <unsigned int N>
559  StatusCode parse ( char(&result)[N] , const std::string& input )
560  {
561  // clear the string
562  std::fill_n ( result , N , ' ' ) ;
563  // create the temporary string
564  std::string tmp ;
565  StatusCode sc = parse ( tmp , input ) ;
566  if ( sc.isFailure() ) { return sc ; } // RETURN
567  if ( N == tmp.size() )
568  { std::copy ( tmp.begin() , tmp.end() , result ) ; }
569  else if ( N + 2 == tmp.size() &&
570  ( '\'' == tmp[0] || '\"' == tmp[0] ) &&
571  ( tmp[0] == tmp[tmp.size()-1] ))
572  { std::copy ( tmp.begin() + 1 , tmp.end() -1 , result ) ; }
573  else { return StatusCode::FAILURE ; }
574  //
575  return StatusCode::SUCCESS ; // RETURN
576  }
577  // ========================================================================
578  } // end of namespace Gaudi::Parsers
579  // ==========================================================================
580 } // end of namespace Gaudi
581 // ============================================================================
582 // The END
583 // ============================================================================
584 #endif //GAUDIPROPERTYPARSERS_PARSERS_H
585 // ============================================================================
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_LIST(InnerType)
Definition: Parsers.h:27
#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:84
STL class.
int N
Definition: IOTest.py:90
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:30
T size(T...args)
STL class.
T begin(T...args)
T fill_n(T...args)
#define GAUDI_API
Definition: Kernel.h:107
Helper functions to set/get the application return code.
Definition: __init__.py:1
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: Parsers.h:23