00001
00002 #ifndef GAUDIPROPERTYPARSERS_PARSERS_H
00003 #define GAUDIPROPERTYPARSERS_PARSERS_H 1
00004
00005
00006
00007
00008
00009 #include <string>
00010 #include <vector>
00011 #include <list>
00012 #include <set>
00013 #include <map>
00014
00015
00016 #include "GaudiKernel/StatusCode.h"
00017 #include "GaudiKernel/HistoDef.h"
00018
00019 #define PARSERS_DECL_FOR_SINGLE(Type)\
00020 GAUDI_API StatusCode parse(Type& result, const std::string& input);
00021
00022 #define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)\
00023 GAUDI_API StatusCode parse(std::pair<FirstType, SecondType >& result,\
00024 const std::string& input);
00025
00026 #define PARSERS_DECL_FOR_LIST(InnerType)\
00027 GAUDI_API StatusCode parse(std::vector<InnerType>& result,\
00028 const std::string& input);
00029
00061
00062 namespace Gaudi
00063 {
00064
00065 class Histo1DDef ;
00066
00067 namespace Parsers
00068 {
00069
00080 PARSERS_DECL_FOR_SINGLE(bool)
00081
00093 PARSERS_DECL_FOR_SINGLE(char)
00095 PARSERS_DECL_FOR_SINGLE(unsigned char)
00097 PARSERS_DECL_FOR_SINGLE(signed char)
00098
00110 PARSERS_DECL_FOR_SINGLE(int)
00112 PARSERS_DECL_FOR_SINGLE(short)
00114 PARSERS_DECL_FOR_SINGLE(unsigned short)
00116 PARSERS_DECL_FOR_SINGLE(unsigned int)
00118 PARSERS_DECL_FOR_SINGLE(long)
00120 PARSERS_DECL_FOR_SINGLE(unsigned long)
00122 PARSERS_DECL_FOR_SINGLE(long long)
00124 PARSERS_DECL_FOR_SINGLE(unsigned long long)
00125
00137 PARSERS_DECL_FOR_SINGLE(double)
00139 PARSERS_DECL_FOR_SINGLE(float)
00141 PARSERS_DECL_FOR_SINGLE(long double)
00142
00154 PARSERS_DECL_FOR_SINGLE(std::string)
00155
00156
00157 PARSERS_DECL_FOR_LIST(bool)
00158 PARSERS_DECL_FOR_LIST(char)
00159 PARSERS_DECL_FOR_LIST(unsigned char)
00160 PARSERS_DECL_FOR_LIST(signed char)
00161
00162 PARSERS_DECL_FOR_LIST(int)
00163 PARSERS_DECL_FOR_LIST(short)
00164 PARSERS_DECL_FOR_LIST(unsigned short)
00165 PARSERS_DECL_FOR_LIST(unsigned int)
00166 PARSERS_DECL_FOR_LIST(long)
00167 PARSERS_DECL_FOR_LIST(unsigned long)
00168 PARSERS_DECL_FOR_LIST(long long)
00169 PARSERS_DECL_FOR_LIST(unsigned long long)
00170
00171 PARSERS_DECL_FOR_LIST(double)
00172 PARSERS_DECL_FOR_LIST(float)
00173 PARSERS_DECL_FOR_LIST(long double)
00174
00175 PARSERS_DECL_FOR_LIST(std::string)
00176
00177
00178
00191 PARSERS_DECL_FOR_PAIR(double,double)
00192
00205 PARSERS_DECL_FOR_PAIR(int, int)
00206
00220 GAUDI_API StatusCode parse
00221 ( std::vector< std::pair<double,double> >& result ,
00222 const std::string& input ) ;
00223
00237 GAUDI_API StatusCode parse
00238 ( std::vector< std::pair<int,int> >& result ,
00239 const std::string& input ) ;
00240
00241
00242
00255 GAUDI_API StatusCode parse
00256 ( std::vector< std::vector<std::string> >& result ,
00257 const std::string& input ) ;
00258
00271 GAUDI_API StatusCode parse
00272 ( std::vector< std::vector<double> >& result ,
00273 const std::string& input ) ;
00274
00275
00276
00289 GAUDI_API StatusCode parse
00290 ( std::map< int , int >& result ,
00291 const std::string& input ) ;
00292
00306 GAUDI_API StatusCode parse
00307 ( std::map< int , double >& result ,
00308 const std::string& input ) ;
00309
00322 GAUDI_API StatusCode parse
00323 ( std::map< std::string , std::string >& result ,
00324 const std::string& input ) ;
00325
00339 GAUDI_API StatusCode parse
00340 ( std::map< std::string , int >& result ,
00341 const std::string& input ) ;
00342
00356 GAUDI_API StatusCode parse
00357 ( std::map< std::string , double >& result ,
00358 const std::string& input ) ;
00359
00375 GAUDI_API StatusCode parse
00376 ( std::map< std::string , std::vector< std::string> >& result ,
00377 const std::string& input ) ;
00378
00394 GAUDI_API StatusCode parse
00395 ( std::map< std::string , std::vector< int > >& result ,
00396 const std::string& input ) ;
00397
00413 GAUDI_API StatusCode parse
00414 ( std::map< std::string , std::vector< double > >& result ,
00415 const std::string& input ) ;
00416
00424 GAUDI_API StatusCode parse
00425 ( std::map<int, std::string>& result ,
00426 const std::string& input ) ;
00427
00435 GAUDI_API StatusCode parse
00436 ( std::map<unsigned int, std::string>& result ,
00437 const std::string& input ) ;
00438
00443 GAUDI_API StatusCode parse
00444 ( std::map<std::string, unsigned int>& result ,
00445 const std::string& input ) ;
00446
00473 GAUDI_API StatusCode parse
00474 ( std::string& name ,
00475 std::string& value ,
00476 const std::string& input ) ;
00477
00486 GAUDI_API StatusCode parse
00487 ( Gaudi::Histo1DDef& histo ,
00488 const std::string& input ) ;
00489
00498 GAUDI_API StatusCode parse
00499 ( std::map<std::string,Gaudi::Histo1DDef>& histos ,
00500 const std::string& input ) ;
00501
00513 GAUDI_API StatusCode parse
00514 ( std::map<std::string,std::pair<double,double> >& params ,
00515 const std::string& input ) ;
00516
00524 template <class T, unsigned int N>
00525 StatusCode parse ( T(&result)[N] , const std::string& input )
00526 {
00527 typedef std::vector<T> _Vct ;
00528
00529 _Vct tmp ;
00530 StatusCode sc = parse ( tmp , input ) ;
00531 if ( sc.isFailure() ) { return sc ; }
00532 if ( N != tmp.size() ) { return StatusCode::FAILURE ; }
00533
00534 std::copy ( tmp.begin() , tmp.end() , result ) ;
00535
00536 return StatusCode::SUCCESS ;
00537 }
00538
00546 template <unsigned int N>
00547 StatusCode parse ( char(&result)[N] , const std::string& input )
00548 {
00549
00550 std::fill_n ( result , N , ' ' ) ;
00551
00552 std::string tmp ;
00553 StatusCode sc = parse ( tmp , input ) ;
00554 if ( sc.isFailure() ) { return sc ; }
00555 if ( N == tmp.size() )
00556 { std::copy ( tmp.begin() , tmp.end() , result ) ; }
00557 else if ( N + 2 == tmp.size() &&
00558 ( '\'' == tmp[0] || '\"' == tmp[0] ) &&
00559 ( tmp[0] == tmp[tmp.size()-1] ))
00560 { std::copy ( tmp.begin() + 1 , tmp.end() -1 , result ) ; }
00561 else { return StatusCode::FAILURE ; }
00562
00563 return StatusCode::SUCCESS ;
00564 }
00565
00566 }
00567
00568 }
00569
00570
00571
00572 #endif //GAUDIPROPERTYPARSERS_PARSERS_H
00573