Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

ParseMaps.cpp

Go to the documentation of this file.
00001 // $Id: ParseMaps.cpp,v 1.6 2008/10/28 14:02:18 marcocle Exp $
00002 // ============================================================================
00003 // Include files
00004 // ============================================================================
00005 // Local
00006 // ============================================================================
00007 #ifdef WIN32
00008 // Disable warning
00009 //   C4146: unary minus operator applied to unsigned type, result still unsigned
00010 // Coming from the parsers of unsigned integers.
00011 #pragma warning(disable:4146)
00012 #endif
00013 #include "GaudiKernel/Parsers.icpp"
00014 // ============================================================================
00031 // ============================================================================
00032 namespace Gaudi
00033 {
00034   namespace Parsers
00035   {
00036     // ========================================================================
00037     // map< TYPE, TYPE >
00038     // ========================================================================
00039     StatusCode parse
00040     ( map< int , int >& result ,
00041       const string&     input  )
00042     {
00043       MapGrammar< IntGrammar<int> , IntGrammar<int> > g;
00044       return parse
00045         ( createIterator(input)  ,
00046           IteratorT()            ,
00047           g[var(result)=arg1],
00048           SkipperGrammar()).full;
00049     }
00050     // ========================================================================
00051     StatusCode parse
00052     ( map< int , double >& result ,
00053       const string&        input  )
00054     {
00055       MapGrammar< IntGrammar<int> , RealGrammar<double> > g;
00056       return parse
00057         ( createIterator(input),
00058           IteratorT(),
00059           g[var(result)=arg1],
00060           SkipperGrammar()).full;
00061     }
00062     // ========================================================================
00063     StatusCode parse
00064     ( map<string,double>&  result ,
00065       const string&        input  )
00066     {
00067       MapGrammar<StringGrammar,RealGrammar<double> > g;
00068       return parse
00069         ( createIterator(input),
00070           IteratorT(),
00071           g[var(result)=arg1],
00072           SkipperGrammar()).full;
00073     }
00074     // ========================================================================
00075     StatusCode parse
00076     ( map< string , string >& result ,
00077       const string&           input  )
00078     {
00079       MapGrammar<StringGrammar,StringGrammar> g;
00080       return parse
00081         ( createIterator(input),
00082           IteratorT(),
00083           g[var(result)=arg1],
00084           SkipperGrammar()).full;
00085     }
00086     // ========================================================================
00087     StatusCode parse
00088     ( map< string , int >& result ,
00089       const string&        input  )
00090     {
00091       MapGrammar<StringGrammar,IntGrammar<int> > g;
00092       return parse
00093         ( createIterator(input),
00094           IteratorT(),
00095           g[var(result)=arg1],
00096           SkipperGrammar()).full;
00097     }
00098     // ========================================================================
00099     StatusCode parse
00100     ( map< std::string , std::vector< std::string > >& result ,
00101       const string&                                    input  )
00102     {
00103       MapGrammar<StringGrammar,VectorGrammar<StringGrammar> > g;
00104       return parse
00105         ( createIterator(input),
00106           IteratorT(),
00107           g[var(result)=arg1],
00108           SkipperGrammar()).full;
00109     }
00110     // ========================================================================
00111     StatusCode parse
00112     ( map< std::string , std::vector< int > >& result ,
00113       const string&                            input  )
00114     {
00115       MapGrammar<StringGrammar,VectorGrammar<IntGrammar<int> > > g;
00116       return parse
00117         ( createIterator(input),
00118           IteratorT(),
00119           g[var(result)=arg1],
00120           SkipperGrammar()).full;
00121     }
00122     // ========================================================================
00123     StatusCode parse
00124     ( map< std::string , std::vector< double > >& result ,
00125       const string&                               input  )
00126     {
00127       MapGrammar<StringGrammar,VectorGrammar<RealGrammar<double> > > g;
00128       return parse
00129         ( createIterator(input),
00130           IteratorT(),
00131           g[var(result)=arg1],
00132           SkipperGrammar()).full;
00133     }
00134     // ========================================================================
00135     /*  parse the pair expression (map-component)  " 'name' :value"
00136      *
00137      *  @code
00138      *
00139      *  const std::string input = "'PackageName':GaudiKernel" ;
00140      *  std::string name  ;
00141      *  std::string value ;
00142      *  StatusCode sc = Gaudi::Parsers::parse ( name , value , input ) ;
00143      *  if ( sc.isFailure() ) { ... }
00144      *  std::cout <<  "\tParsed name  is " << name
00145      *            <<  "\tParsed value is " << value << std::endl
00146      *  @endcode
00147      *
00148      *  @param  name  (output) the parsed name of the component, defined
00149      *                as 'name' or "name" before the column symbol ":",
00150      *                the leading and trailing blans are omitted
00151      *  @param  value (output) the parsed value of the component,
00152      *                defined as everything after the column symbol ":"
00153      *                till the end of the string
00154      *  @param  input (input) string to be parsed
00155      *  @return status code
00156      *
00157      *  @author Alexander MAZUROV Alexander.Mazurov@gmail.com
00158      *  @author Vanya BELYAEV  ibelyaev@physics.syr.edu
00159      *  @date 2006-05-12
00160      */
00161     // ========================================================================
00162     StatusCode parse ( string& name , string&  value , const string& input )
00163     {
00164       return parse
00165         ( input.c_str(),
00166           (
00167            ch_p('"' ) >> (+(anychar_p-ch_p('"' )))[assign_a(name)] >> ch_p('"' )
00168            |
00169            ch_p('\'') >> (+(anychar_p-ch_p('\'')))[assign_a(name)] >> ch_p('\'')
00170            )
00171           >> ":"
00172           >> (+anychar_p)[assign_a(value)], space_p).full;
00173     }
00174     // ========================================================================
00175     StatusCode parse
00176     ( map<int,std::string>& result ,
00177       const string&         input  )
00178     {
00179       MapGrammar<IntGrammar<int>,StringGrammar> g;
00180       return parse
00181         ( createIterator(input),
00182           IteratorT(),
00183           g[var(result)=arg1],
00184           SkipperGrammar()).full;
00185     }
00186     // ========================================================================
00187     StatusCode parse
00188     ( map<unsigned int,std::string>& result ,
00189       const string&         input  )
00190     {
00191       MapGrammar<IntGrammar<unsigned int>,StringGrammar> g;
00192       return parse
00193         ( createIterator(input),
00194           IteratorT(),
00195           g[var(result)=arg1],
00196           SkipperGrammar()).full;
00197     }
00198     // ========================================================================
00199     StatusCode parse
00200     ( map<std::string,unsigned int>& result ,
00201       const string&         input  )
00202     {
00203       MapGrammar<StringGrammar,IntGrammar<unsigned int> > g;
00204       return parse
00205         ( createIterator(input),
00206           IteratorT(),
00207           g[var(result)=arg1],
00208           SkipperGrammar()).full;
00209     }
00210     // ========================================================================
00211     /*  helper function, needed for implementation of map of pairs
00212      *  It is very useful construction for monitoring to
00213      *  represent the value and error or the allowed range for
00214      *  some parameter
00215      *  @param the map of pair
00216      *  @param input the string to be parsed
00217      *  @return status code
00218      *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00219      *  @author Alexander MAZUROV Alexander.Mazurov@gmail.com
00220      *  @date 2009-05-19
00221      */
00222     StatusCode parse
00223     ( std::map<std::string,std::pair<double,double> >& params ,
00224       const std::string&                               input  )
00225     {
00226       typedef PairGrammar< RealGrammar<double> , RealGrammar <double> > PG ;
00227       MapGrammar < StringGrammar , PG > g ;
00228       return parse
00229         ( createIterator(input),
00230           IteratorT(),
00231           g[var(params)=arg1],
00232           SkipperGrammar()).full;
00233     }
00234     // ========================================================================
00235   } // end of namespace Parsers
00236   // ==========================================================================
00237 } // end of namespace Gaudi
00238 // ============================================================================
00239 // The END
00240 // ============================================================================
00241 
00242 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:53:44 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004