All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
19 #define PARSERS_DECL_FOR_SINGLE(Type)\
20  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,\
24  const std::string& input);
25 
26 #define PARSERS_DECL_FOR_LIST(InnerType)\
27  GAUDI_API StatusCode parse(std::vector<InnerType>& result,\
28  const std::string& input);
29 // ============================================================================
61 // ============================================================================
62 namespace Gaudi
63 {
64  // ==========================================================================
65  class Histo1DDef ;
66  // ==========================================================================
67  namespace Parsers
68  {
69  // ========================================================================
81  // ========================================================================
95  PARSERS_DECL_FOR_SINGLE(unsigned char)
97  PARSERS_DECL_FOR_SINGLE(signed char)
98  // ========================================================================
114  PARSERS_DECL_FOR_SINGLE(unsigned short)
116  PARSERS_DECL_FOR_SINGLE(unsigned int)
120  PARSERS_DECL_FOR_SINGLE(unsigned long)
122  PARSERS_DECL_FOR_SINGLE(long long)
124  PARSERS_DECL_FOR_SINGLE(unsigned long long)
125  // ========================================================================
141  PARSERS_DECL_FOR_SINGLE(long double)
142  // ========================================================================
154  PARSERS_DECL_FOR_SINGLE(std::string)
155  // ========================================================================
156 
159  PARSERS_DECL_FOR_LIST(unsigned char)
160  PARSERS_DECL_FOR_LIST(signed char)
161 
163  PARSERS_DECL_FOR_LIST(short)
164  PARSERS_DECL_FOR_LIST(unsigned short)
165  PARSERS_DECL_FOR_LIST(unsigned int)
167  PARSERS_DECL_FOR_LIST(unsigned long)
168  PARSERS_DECL_FOR_LIST(long long)
169  PARSERS_DECL_FOR_LIST(unsigned long long)
170 
171  PARSERS_DECL_FOR_LIST(double)
172  PARSERS_DECL_FOR_LIST(float)
173  PARSERS_DECL_FOR_LIST(long double)
174 
175  PARSERS_DECL_FOR_LIST(std::string)
176  // ========================================================================
177  // Advanced parses
178  // ========================================================================
191  PARSERS_DECL_FOR_PAIR(double,double)
192  // ========================================================================
205  PARSERS_DECL_FOR_PAIR(int, int)
206  // ========================================================================
221  ( std::vector< std::pair<double,double> >& result ,
222  const std::string& input ) ;
223  // ========================================================================
238  ( std::vector< std::pair<int,int> >& result ,
239  const std::string& input ) ;
240  // ========================================================================
241  // vector< vector< TYPE > >
242  // ========================================================================
256  ( std::vector< std::vector<std::string> >& result ,
257  const std::string& input ) ;
258  // ========================================================================
272  ( std::vector< std::vector<double> >& result ,
273  const std::string& input ) ;
274  // ========================================================================
275  // map< TYPE, TYPE >
276  // ========================================================================
290  ( std::map< int , int >& result ,
291  const std::string& input ) ;
292  // ========================================================================
307  ( std::map< int , double >& result ,
308  const std::string& input ) ;
309  // ========================================================================
323  ( std::map< std::string , std::string >& result ,
324  const std::string& input ) ;
325  // ========================================================================
340  ( std::map< std::string , int >& result ,
341  const std::string& input ) ;
342  // ========================================================================
357  ( std::map< std::string , double >& result ,
358  const std::string& input ) ;
359  // ========================================================================
376  ( std::map< std::string , std::vector< std::string> >& result ,
377  const std::string& input ) ;
378  // ========================================================================
395  ( std::map< std::string , std::vector< int > >& result ,
396  const std::string& input ) ;
397  // ========================================================================
414  ( std::map< std::string , std::vector< double > >& result ,
415  const std::string& input ) ;
416  // ========================================================================
425  ( std::map<int, std::string>& result ,
426  const std::string& input ) ;
427  // ========================================================================
436  ( std::map<unsigned int, std::string>& result ,
437  const std::string& input ) ;
438  // ========================================================================
444  ( std::map<std::string, unsigned int>& result ,
445  const std::string& input ) ;
446  // ========================================================================
474  ( std::string& name ,
475  std::string& value ,
476  const std::string& input ) ;
477  // ========================================================================
487  ( Gaudi::Histo1DDef& histo ,
488  const std::string& input ) ;
489  // ========================================================================
499  ( std::map<std::string,Gaudi::Histo1DDef>& histos ,
500  const std::string& input ) ;
501  // ========================================================================
514  ( std::map<std::string,std::pair<double,double> >& params ,
515  const std::string& input ) ;
516  // ========================================================================
524  template <class T, unsigned int N>
525  StatusCode parse ( T(&result)[N] , const std::string& input )
526  {
527  typedef std::vector<T> _Vct ;
528  // create the temporary vector
529  _Vct tmp ;
530  StatusCode sc = parse ( tmp , input ) ;
531  if ( sc.isFailure() ) { return sc ; } // RETURN
532  if ( N != tmp.size() ) { return StatusCode::FAILURE ; } // RETURN
533  //
534  std::copy ( tmp.begin() , tmp.end() , result ) ;
535  //
536  return StatusCode::SUCCESS ; // RETURN
537  }
538  // ========================================================================
546  template <unsigned int N>
547  StatusCode parse ( char(&result)[N] , const std::string& input )
548  {
549  // clear the string
550  std::fill_n ( result , N , ' ' ) ;
551  // create the temporary string
552  std::string tmp ;
553  StatusCode sc = parse ( tmp , input ) ;
554  if ( sc.isFailure() ) { return sc ; } // RETURN
555  if ( N == tmp.size() )
556  { std::copy ( tmp.begin() , tmp.end() , result ) ; }
557  else if ( N + 2 == tmp.size() &&
558  ( '\'' == tmp[0] || '\"' == tmp[0] ) &&
559  ( tmp[0] == tmp[tmp.size()-1] ))
560  { std::copy ( tmp.begin() + 1 , tmp.end() -1 , result ) ; }
561  else { return StatusCode::FAILURE ; }
562  //
563  return StatusCode::SUCCESS ; // RETURN
564  }
565  // ========================================================================
566  } // end of namespace Gaudi::Parsers
567  // ==========================================================================
568 } // end of namespace Gaudi
569 // ============================================================================
570 // The END
571 // ============================================================================
572 #endif //GAUDIPROPERTYPARSERS_PARSERS_H
573 // ============================================================================
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: Parsers.h:26
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: Parsers.h:19
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
int N
Definition: IOTest.py:90
struct GAUDI_API map
Parametrisation class for map-like implementation.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:32
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
#define GAUDI_API
Definition: Kernel.h:108
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: Parsers.h:22