|
|
|||
File indexing completed on 2025-12-15 10:14:13
0001 /***********************************************************************************\ 0002 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations * 0003 * * 0004 * This software is distributed under the terms of the Apache version 2 licence, * 0005 * copied verbatim in the file "LICENSE". * 0006 * * 0007 * In applying this licence, CERN does not waive the privileges and immunities * 0008 * granted to it by virtue of its status as an Intergovernmental Organization * 0009 * or submit itself to any jurisdiction. * 0010 \***********************************************************************************/ 0011 #pragma once 0012 // ============================================================================ 0013 // Include files 0014 // ============================================================================ 0015 // STD & STL 0016 // ============================================================================ 0017 #include <list> 0018 #include <map> 0019 #include <set> 0020 #include <string> 0021 #include <unordered_set> 0022 #include <vector> 0023 0024 // ============================================================================ 0025 #include <GaudiKernel/HistoDef.h> 0026 #include <GaudiKernel/Map.h> 0027 #include <GaudiKernel/StatusCode.h> 0028 // ============================================================================ 0029 #define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, std::string_view input ); 0030 0031 #define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \ 0032 GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, std::string_view input ); 0033 0034 #define PARSERS_DECL_FOR_LIST( InnerType ) \ 0035 GAUDI_API StatusCode parse( std::vector<InnerType>& result, std::string_view input ); 0036 0037 #define PARSERS_DECL_FOR_SET( InnerType ) \ 0038 GAUDI_API StatusCode parse( std::set<InnerType>& result, std::string_view input ); \ 0039 GAUDI_API StatusCode parse( std::unordered_set<InnerType>& result, std::string_view input ); 0040 0041 // ============================================================================ 0042 /** @file 0043 * The declaration of major parsing functions used e.g 0044 * for (re)implementation of new extended properties see class Property 0045 * These function also could be used in a different, much wider contex. 0046 * all of them have the semantic: 0047 * <c>StatusCode parse ( TYPE& result , std::string_view input )</c> 0048 * where <c>input</c> is the input string to be parsed, 0049 * and <c>result</c> is the the result of parsing 0050 * 0051 * @code 0052 * 0053 * const std::string input = ... ; 0054 * std::vector<std::string> result ; 0055 * 0056 * // parse the input 0057 * StatusCode sc = parse ( result , input ) ; 0058 * if ( sc.isFailure() ) 0059 * { 0060 * // error here ... 0061 * } 0062 * std::cout << "vector size " << result.size() << std::endl ; 0063 * 0064 * @endcode 0065 * 0066 * @see Gaudi::Parsers::parse 0067 * @see Property 0068 * 0069 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0070 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0071 * @date 2006-05-12 0072 */ 0073 // ============================================================================ 0074 namespace Gaudi { 0075 // ========================================================================== 0076 class Histo1DDef; 0077 // ========================================================================== 0078 namespace Parsers { 0079 // ======================================================================== 0080 /** parse the <c>bool</c> value 0081 * @see Gaudi::Parsers::BoolGrammar 0082 * @param result (output) boolean result 0083 * @param input (input) the string to be parsed 0084 * @return status code 0085 * 0086 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0087 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0088 * @date 2006-05-12 0089 */ 0090 PARSERS_DECL_FOR_SINGLE( bool ) 0091 // ======================================================================== 0092 /** parse the <c>char</c> value 0093 * 0094 * @see Gaudi::Parsers::CharGrammar 0095 * @param result (output) boolean result 0096 * @param input (input) the string to be parsed 0097 * @return status code 0098 * 0099 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0100 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0101 * @date 2006-05-12 0102 */ 0103 PARSERS_DECL_FOR_SINGLE( char ) 0104 /// @see Gaudi::Parsers::parser( char&, const std::string& ) 0105 PARSERS_DECL_FOR_SINGLE( unsigned char ) 0106 /// @see Gaudi::Parsers::parser( char&, const std::string& ) 0107 PARSERS_DECL_FOR_SINGLE( signed char ) 0108 // ======================================================================== 0109 /** parse the <c>int</c> value 0110 * 0111 * @see Gaudi::Parsers::IntGrammar 0112 * @param result (output) integer result 0113 * @param input (input) the string to be parsed 0114 * @return status code 0115 * 0116 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0117 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0118 * @date 2006-05-14 0119 */ 0120 PARSERS_DECL_FOR_SINGLE( int ) 0121 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0122 PARSERS_DECL_FOR_SINGLE( short ) 0123 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0124 PARSERS_DECL_FOR_SINGLE( unsigned short ) 0125 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0126 PARSERS_DECL_FOR_SINGLE( unsigned int ) 0127 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0128 PARSERS_DECL_FOR_SINGLE( long ) 0129 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0130 PARSERS_DECL_FOR_SINGLE( unsigned long ) 0131 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0132 PARSERS_DECL_FOR_SINGLE( long long ) 0133 /// @see Gaudi::Parsers::parser( int&, const std::string& ) 0134 PARSERS_DECL_FOR_SINGLE( unsigned long long ) 0135 // ======================================================================== 0136 /** parse the <c>double</c> value 0137 * 0138 * @see Gaudi::Parsers::RealGrammar 0139 * @param result (output) double result 0140 * @param input (input) the string to be parsed 0141 * @return status code 0142 * 0143 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0144 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0145 * @date 2006-05-14 0146 */ 0147 PARSERS_DECL_FOR_SINGLE( double ) 0148 /// @see Gaudi::Parsers::parser( double&, const std::string& ) 0149 PARSERS_DECL_FOR_SINGLE( float ) 0150 /// @see Gaudi::Parsers::parser( double&, const std::string& ) 0151 PARSERS_DECL_FOR_SINGLE( long double ) 0152 // ======================================================================== 0153 /** parse the <c>std::string</c> value 0154 * 0155 * @see Gaudi::Parsers::StringGrammar 0156 * @param result (output) string result 0157 * @param input (input) the string to be parsed 0158 * @return status code 0159 * 0160 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0161 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0162 * @date 2006-05-14 0163 */ 0164 PARSERS_DECL_FOR_SINGLE( std::string ) 0165 // ======================================================================== 0166 0167 PARSERS_DECL_FOR_LIST( bool ) 0168 PARSERS_DECL_FOR_LIST( char ) 0169 PARSERS_DECL_FOR_LIST( unsigned char ) 0170 PARSERS_DECL_FOR_LIST( signed char ) 0171 0172 PARSERS_DECL_FOR_LIST( int ) 0173 PARSERS_DECL_FOR_LIST( short ) 0174 PARSERS_DECL_FOR_LIST( unsigned short ) 0175 PARSERS_DECL_FOR_LIST( unsigned int ) 0176 PARSERS_DECL_FOR_LIST( long ) 0177 PARSERS_DECL_FOR_LIST( unsigned long ) 0178 PARSERS_DECL_FOR_LIST( long long ) 0179 PARSERS_DECL_FOR_LIST( unsigned long long ) 0180 0181 PARSERS_DECL_FOR_LIST( double ) 0182 PARSERS_DECL_FOR_LIST( float ) 0183 PARSERS_DECL_FOR_LIST( long double ) 0184 0185 PARSERS_DECL_FOR_LIST( std::string ) 0186 0187 // ======================================================================== 0188 0189 PARSERS_DECL_FOR_SET( bool ) 0190 PARSERS_DECL_FOR_SET( char ) 0191 PARSERS_DECL_FOR_SET( unsigned char ) 0192 PARSERS_DECL_FOR_SET( signed char ) 0193 0194 PARSERS_DECL_FOR_SET( int ) 0195 PARSERS_DECL_FOR_SET( short ) 0196 PARSERS_DECL_FOR_SET( unsigned short ) 0197 PARSERS_DECL_FOR_SET( unsigned int ) 0198 PARSERS_DECL_FOR_SET( long ) 0199 PARSERS_DECL_FOR_SET( unsigned long ) 0200 PARSERS_DECL_FOR_SET( long long ) 0201 PARSERS_DECL_FOR_SET( unsigned long long ) 0202 0203 PARSERS_DECL_FOR_SET( double ) 0204 PARSERS_DECL_FOR_SET( float ) 0205 PARSERS_DECL_FOR_SET( long double ) 0206 0207 PARSERS_DECL_FOR_SET( std::string ) 0208 0209 // ======================================================================== 0210 // Advanced parses 0211 // ======================================================================== 0212 /** parse the <c>std::pair\<double,double\></c> value 0213 * 0214 * @see Gaudi::Parsers::PairGrammar 0215 * @see Gaudi::Parsers::RealGrammar 0216 * @param result (output) pair of doubles 0217 * @param input (input) the string to be parsed 0218 * @return status code 0219 * 0220 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0221 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0222 * @date 2006-05-14 0223 */ 0224 PARSERS_DECL_FOR_PAIR( double, double ) 0225 // ======================================================================== 0226 /** parse the <c>std::pair\<int,int\></c> value 0227 * 0228 * @see Gaudi::Parsers::PairGrammar 0229 * @see Gaudi::Parsers::IntGrammar 0230 * @param result (output) pair of integers 0231 * @param input (input) the string to be parsed 0232 * @return status code 0233 * 0234 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0235 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0236 * @date 2006-05-14 0237 */ 0238 PARSERS_DECL_FOR_PAIR( int, int ) 0239 // ======================================================================== 0240 /** parse the <c>std::vector\<std::pair\<double,double\> \></c> value 0241 * 0242 * @see Gaudi::Parsers::VectorGrammar 0243 * @see Gaudi::Parsers::PairGrammar 0244 * @see Gaudi::Parsers::RealGrammar 0245 * @param result (output) vector with pairs of doubles 0246 * @param input (input) the string to be parsed 0247 * @return status code 0248 * 0249 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0250 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0251 * @date 2006-05-14 0252 */ 0253 GAUDI_API StatusCode parse( std::vector<std::pair<double, double>>& result, std::string_view input ); 0254 // ======================================================================== 0255 /** parse the <c>std::vector\<std::pair\<int,int\> \></c> value 0256 * 0257 * @see Gaudi::Parsers::VectorGrammar 0258 * @see Gaudi::Parsers::PairGrammar 0259 * @see Gaudi::Parsers::IntGrammar 0260 * @param result (output) vector with pairs of int 0261 * @param input (input) the string to be parsed 0262 * @return status code 0263 * 0264 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0265 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0266 * @date 2006-05-14 0267 */ 0268 GAUDI_API StatusCode parse( std::vector<std::pair<int, int>>& result, std::string_view input ); 0269 // ======================================================================== 0270 // vector< vector< TYPE > > 0271 // ======================================================================== 0272 /** parse the <c>std::vector\<std::vector\<std::string\> \></c> value 0273 * 0274 * @see Gaudi::Parsers::VectorGrammar 0275 * @see Gaudi::Parsers::StringGrammar 0276 * @param result (output) vector with vectors of strings 0277 * @param input (input) the string to be parsed 0278 * @return status code 0279 * 0280 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0281 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0282 * @date 2006-05-14 0283 */ 0284 GAUDI_API StatusCode parse( std::vector<std::vector<std::string>>& result, std::string_view input ); 0285 // ======================================================================== 0286 /** parse the <c>std::vector\<std::vector\<double\> \></c> value 0287 * 0288 * @see Gaudi::Parsers::VectorGrammar 0289 * @see Gaudi::Parsers::RealGrammar 0290 * @param result (output) vector with vectors of doubles 0291 * @param input (input) the string to be parsed 0292 * @return status code 0293 * 0294 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0295 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0296 * @date 2006-05-14 0297 */ 0298 GAUDI_API StatusCode parse( std::vector<std::vector<double>>& result, std::string_view input ); 0299 // ======================================================================== 0300 /** parse the <c>std::vector\<std::vector\<int\> \></c> value 0301 * 0302 * @see Gaudi::Parsers::VectorGrammar 0303 * @see Gaudi::Parsers::IntGrammar 0304 * @param result (output) vector with vectors of ints 0305 * @param input (input) the string to be parsed 0306 * @return status code 0307 */ 0308 GAUDI_API StatusCode parse( std::vector<std::vector<int>>& result, std::string_view input ); 0309 // ======================================================================== 0310 // map< TYPE, TYPE > 0311 // ======================================================================== 0312 /** parse the <c>std::map\<int , int\></c> value 0313 * 0314 * @see Gaudi::Parsers::MapGrammar 0315 * @see Gaudi::Parsers::IntGrammar 0316 * @param result (output) map with integer key and double value 0317 * @param input (input) the string to be parsed 0318 * @return status code 0319 * 0320 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0321 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0322 * @date 2006-05-14 0323 */ 0324 GAUDI_API StatusCode parse( std::map<int, int>& result, std::string_view input ); 0325 // ======================================================================== 0326 /** parse the <c>std::map\<int , double\></c> value 0327 * 0328 * @see Gaudi::Parsers::MapGrammar 0329 * @see Gaudi::Parsers::IntGrammar 0330 * @see Gaudi::Parsers::RealGrammar 0331 * @param result (output) map with integer key and double value 0332 * @param input (input) the string to be parsed 0333 * @return status code 0334 * 0335 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0336 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0337 * @date 2006-05-14 0338 */ 0339 GAUDI_API StatusCode parse( std::map<int, double>& result, std::string_view input ); 0340 // ======================================================================== 0341 /** parse the <c>std::map\<std::string , std::string\></c> value 0342 * 0343 * @see Gaudi::Parsers::MapGrammar 0344 * @see Gaudi::Parsers::StringGrammar 0345 * @param result (output) map with string key and value 0346 * @param input (input) the string to be parsed 0347 * @return status code 0348 * 0349 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0350 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0351 * @date 2006-05-14 0352 */ 0353 GAUDI_API StatusCode parse( std::map<std::string, std::string>& result, std::string_view input ); 0354 GAUDI_API StatusCode parse( std::map<std::string, std::string, std::less<>>& result, std::string_view input ); 0355 // ======================================================================== 0356 /** parse the <c>std::map\<std::string , int\></c> value 0357 * 0358 * @see Gaudi::Parsers::MapGrammar 0359 * @see Gaudi::Parsers::StringGrammar 0360 * @see Gaudi::Parsers::IntGrammar 0361 * @param result (output) map with string key and integer value 0362 * @param input (input) the string to be parsed 0363 * @return status code 0364 * 0365 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0366 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0367 * @date 2006-05-14 0368 */ 0369 GAUDI_API StatusCode parse( std::map<std::string, int>& result, std::string_view input ); 0370 // ======================================================================== 0371 /** parse the <c>std::map\<std::string , double\></c> value 0372 * 0373 * @see Gaudi::Parsers::MapGrammar 0374 * @see Gaudi::Parsers::StringGrammar 0375 * @see Gaudi::Parsers::RealGrammar 0376 * @param result (output) map with string key and integer value 0377 * @param input (input) the string to be parsed 0378 * @return status code 0379 * 0380 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0381 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0382 * @date 2006-05-14 0383 */ 0384 GAUDI_API StatusCode parse( std::map<std::string, double>& result, std::string_view input ); 0385 // ======================================================================== 0386 /** parse the <c>std::map\<std::string , std::vector\<std::string\> \></c> 0387 * value 0388 * 0389 * @see Gaudi::Parsers::MapGrammar 0390 * @see Gaudi::Parsers::StringGrammar 0391 * @see Gaudi::Parsers::VectorGrammar 0392 * @param result (output) map with string value and 0393 * vector of strings as value 0394 * @param input (input) the string to be parsed 0395 * @return status code 0396 * 0397 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0398 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0399 * @date 2006-05-14 0400 */ 0401 GAUDI_API StatusCode parse( std::map<std::string, std::vector<std::string>>& result, std::string_view input ); 0402 // ======================================================================== 0403 /** parse the <c>std::map\<std::string , std::vector\<int\> \></c> value 0404 * 0405 * @see Gaudi::Parsers::MapGrammar 0406 * @see Gaudi::Parsers::StringGrammar 0407 * @see Gaudi::Parsers::VectorGrammar 0408 * @see Gaudi::Parsers::IntGrammar 0409 * @param result (output) map with string value and 0410 * vector of integers as value 0411 * @param input (input) the string to be parsed 0412 * @return status code 0413 * 0414 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0415 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0416 * @date 2006-05-14 0417 */ 0418 GAUDI_API StatusCode parse( std::map<std::string, std::vector<int>>& result, std::string_view input ); 0419 // ======================================================================== 0420 /** parse the <c>std::map\<std::string , std::vector\<double\> \></c> value 0421 * 0422 * @see Gaudi::Parsers::MapGrammar 0423 * @see Gaudi::Parsers::StringGrammar 0424 * @see Gaudi::Parsers::VectorGrammar 0425 * @see Gaudi::Parsers::RealGrammar 0426 * @param result (output) map with string value and 0427 * vector of doubles as value 0428 * @param input (input) the string to be parsed 0429 * @return status code 0430 * 0431 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0432 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0433 * @date 2006-05-14 0434 */ 0435 GAUDI_API StatusCode parse( std::map<std::string, std::vector<double>>& result, std::string_view input ); 0436 // ======================================================================== 0437 /** parse the <c>std::map\<int,std::string\> \></c> objects 0438 * 0439 * @see Gaudi::Parsers::MapGrammar 0440 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0441 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0442 * @date 2007-12-06 0443 */ 0444 GAUDI_API StatusCode parse( std::map<int, std::string>& result, std::string_view input ); 0445 // ======================================================================== 0446 /** parse the <c>std::map\<unsigned int,std::string\> \></c> objects 0447 * 0448 * @see Gaudi::Parsers::MapGrammar 0449 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0450 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0451 * @date 2007-12-06 0452 */ 0453 GAUDI_API StatusCode parse( std::map<unsigned int, std::string>& result, std::string_view input ); 0454 // ======================================================================== 0455 /** parse the <c>std::map\<unsigned int,std::string\> \></c> objects 0456 * 0457 * @see Gaudi::Parsers::MapGrammar 0458 */ 0459 GAUDI_API StatusCode parse( std::map<std::string, unsigned int>& result, std::string_view input ); 0460 // ======================================================================== 0461 /** parse the <c>GaudiUtils::Map\<K, V, M\></c> objects 0462 * 0463 * @see Gaudi::Parsers::MapGrammar 0464 */ 0465 template <typename K, typename V, typename M> 0466 GAUDI_API StatusCode parse( GaudiUtils::Map<K, V, M>& result, std::string_view input ) { 0467 return parse( (M&)result, input ); 0468 } 0469 // ======================================================================== 0470 /** parse the pair expression (map-component) " 'name' :value" 0471 * 0472 * @code 0473 * 0474 * const std::string input = "'PackageName':GaudiKernel" ; 0475 * std::string name ; 0476 * std::string value ; 0477 * StatusCode sc = Gaudi::Parsers::parse ( name , value , input ) ; 0478 * if ( sc.isFailure() ) { ... } 0479 * std::cout << "\tParsed name is " << name 0480 * << "\tParsed value is " << value << std::endl 0481 * @endcode 0482 * 0483 * @param name (output) the parsed name of the component, defined 0484 * as 'name' or "name" before the column symbol ":", 0485 * the leading and trailing blans are omitted 0486 * @param value (output) the parsed value of the component, 0487 * defined as everything after the column symbol ":" 0488 * till the end of the string 0489 * @param input (input) string to be parsed 0490 * @return status code 0491 * 0492 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0493 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0494 * @date 2006-05-12 0495 */ 0496 GAUDI_API StatusCode parse( std::string& name, std::string& value, std::string_view input ); 0497 // ======================================================================== 0498 /** helper function, needed for implementation of "Histogram Property" 0499 * @param histo the histogram description (output) 0500 * @param input the string to be parsed 0501 * @return status code 0502 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0503 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0504 * @date 2007-09-17 0505 */ 0506 GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, std::string_view input ); 0507 // ======================================================================== 0508 /** helper function, needed for implementation of "Histogram Property" 0509 * @param histos the map of the histogram descriptions (output) 0510 * @param input the string to be parsed 0511 * @return status code 0512 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0513 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0514 * @date 2007-09-17 0515 */ 0516 GAUDI_API StatusCode parse( std::map<std::string, Gaudi::Histo1DDef>& histos, std::string_view input ); 0517 // ======================================================================== 0518 /** helper function, needed for implementation of map of pairs 0519 * @param params the map of pair 0520 * @param input the string to be parsed 0521 * @return status code 0522 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl 0523 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0524 * @date 2009-05-19 0525 */ 0526 GAUDI_API StatusCode parse( std::map<std::string, std::pair<double, double>>& params, std::string_view input ); 0527 // ======================================================================== 0528 /** helper function, needed for implementation of map of pairs 0529 * @param params the map of pair 0530 * @param input the string to be parsed 0531 * @return status code 0532 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl 0533 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 0534 * @author David BACHER david.bacher@physics.ox.ac.uk 0535 * @date 2024-11-06 0536 */ 0537 GAUDI_API StatusCode parse( std::map<std::string, std::pair<int, int>>& params, std::string_view input ); 0538 // ======================================================================== 0539 /** parser function for C-arrays 0540 * @param params C-array 0541 * @param input the string to be parsed 0542 * @return status code 0543 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl 0544 * @date 2009-09-15 0545 */ 0546 template <class T, unsigned int N> 0547 StatusCode parse( T ( &result )[N], std::string_view input ) { 0548 typedef std::vector<T> _Vct; 0549 // create the temporary vector 0550 _Vct tmp; 0551 StatusCode sc = parse( tmp, input ); 0552 if ( sc.isFailure() ) { return sc; } // RETURN 0553 if ( N != tmp.size() ) { return StatusCode::FAILURE; } // RETURN 0554 // 0555 std::copy( tmp.begin(), tmp.end(), result ); 0556 // 0557 return StatusCode::SUCCESS; // RETURN 0558 } 0559 // ======================================================================== 0560 /** parser function for C-strings 0561 * @param params C-string 0562 * @param input the string to be parsed 0563 * @return status code 0564 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl 0565 * @date 2009-09-15 0566 */ 0567 template <unsigned int N> 0568 StatusCode parse( char ( &result )[N], std::string_view input ) { 0569 // clear the string 0570 std::fill_n( result, N, ' ' ); 0571 // create the temporary string 0572 std::string tmp; 0573 StatusCode sc = parse( tmp, input ); 0574 if ( sc.isFailure() ) { return sc; } // RETURN 0575 if ( N == tmp.size() ) { 0576 std::copy( tmp.begin(), tmp.end(), result ); 0577 } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) { 0578 std::copy( tmp.begin() + 1, tmp.end() - 1, result ); 0579 } else { 0580 return StatusCode::FAILURE; 0581 } 0582 // 0583 return StatusCode::SUCCESS; // RETURN 0584 } 0585 // ======================================================================== 0586 } // namespace Parsers 0587 // ========================================================================== 0588 } // end of namespace Gaudi
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|