The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
CommonParsers.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14#include <GaudiKernel/Map.h>
16#include <list>
17#include <map>
18#include <set>
19#include <string>
20#include <unordered_set>
21#include <vector>
22
23#define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, std::string_view input );
24
25#define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \
26 GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, std::string_view input );
27
28#define PARSERS_DECL_FOR_LIST( InnerType ) \
29 GAUDI_API StatusCode parse( std::vector<InnerType>& result, std::string_view input );
30
31#define PARSERS_DECL_FOR_SET( InnerType ) \
32 GAUDI_API StatusCode parse( std::set<InnerType>& result, std::string_view input ); \
33 GAUDI_API StatusCode parse( std::unordered_set<InnerType>& result, std::string_view input );
34
66namespace Gaudi {
67 class Histo1DDef;
68 namespace Parsers {
93 PARSERS_DECL_FOR_SINGLE( unsigned char )
95 PARSERS_DECL_FOR_SINGLE( signed char )
111 PARSERS_DECL_FOR_SINGLE( unsigned short )
113 PARSERS_DECL_FOR_SINGLE( unsigned int )
117 PARSERS_DECL_FOR_SINGLE( unsigned long )
119 PARSERS_DECL_FOR_SINGLE( long long )
121 PARSERS_DECL_FOR_SINGLE( unsigned long long )
137 PARSERS_DECL_FOR_SINGLE( long double )
149 PARSERS_DECL_FOR_SINGLE( std::string )
150
153 PARSERS_DECL_FOR_LIST( unsigned char )
154 PARSERS_DECL_FOR_LIST( signed char )
155
157 PARSERS_DECL_FOR_LIST( short )
158 PARSERS_DECL_FOR_LIST( unsigned short )
159 PARSERS_DECL_FOR_LIST( unsigned int )
161 PARSERS_DECL_FOR_LIST( unsigned long )
162 PARSERS_DECL_FOR_LIST( long long )
163 PARSERS_DECL_FOR_LIST( unsigned long long )
164
165 PARSERS_DECL_FOR_LIST( double )
166 PARSERS_DECL_FOR_LIST( float )
167 PARSERS_DECL_FOR_LIST( long double )
168
169 PARSERS_DECL_FOR_LIST( std::string )
170
173 PARSERS_DECL_FOR_SET( unsigned char )
174 PARSERS_DECL_FOR_SET( signed char )
175
177 PARSERS_DECL_FOR_SET( short )
178 PARSERS_DECL_FOR_SET( unsigned short )
179 PARSERS_DECL_FOR_SET( unsigned int )
181 PARSERS_DECL_FOR_SET( unsigned long )
182 PARSERS_DECL_FOR_SET( long long )
183 PARSERS_DECL_FOR_SET( unsigned long long )
184
185 PARSERS_DECL_FOR_SET( double )
186 PARSERS_DECL_FOR_SET( float )
187 PARSERS_DECL_FOR_SET( long double )
188
189 PARSERS_DECL_FOR_SET( std::string )
190
191 // ========================================================================
192 // Advanced parses
193 // ========================================================================
206 PARSERS_DECL_FOR_PAIR( double, double )
219 PARSERS_DECL_FOR_PAIR( int, int )
233 GAUDI_API StatusCode parse( std::vector<std::pair<double, double>>& result, std::string_view input );
247 GAUDI_API StatusCode parse( std::vector<std::pair<int, int>>& result, std::string_view input );
260 GAUDI_API StatusCode parse( std::vector<std::vector<std::string>>& result, std::string_view input );
273 GAUDI_API StatusCode parse( std::vector<std::vector<double>>& result, std::string_view input );
282 GAUDI_API StatusCode parse( std::vector<std::vector<int>>& result, std::string_view input );
283 // map< TYPE, TYPE >
296 GAUDI_API StatusCode parse( std::map<int, int>& result, std::string_view input );
310 GAUDI_API StatusCode parse( std::map<int, double>& result, std::string_view input );
323 GAUDI_API StatusCode parse( std::map<std::string, std::string>& result, std::string_view input );
324 GAUDI_API StatusCode parse( std::map<std::string, std::string, std::less<>>& result, std::string_view input );
338 GAUDI_API StatusCode parse( std::map<std::string, int>& result, std::string_view input );
352 GAUDI_API StatusCode parse( std::map<std::string, double>& result, std::string_view input );
368 GAUDI_API StatusCode parse( std::map<std::string, std::vector<std::string>>& result, std::string_view input );
384 GAUDI_API StatusCode parse( std::map<std::string, std::vector<int>>& result, std::string_view input );
400 GAUDI_API StatusCode parse( std::map<std::string, std::vector<double>>& result, std::string_view input );
408 GAUDI_API StatusCode parse( std::map<int, std::string>& result, std::string_view input );
416 GAUDI_API StatusCode parse( std::map<unsigned int, std::string>& result, std::string_view input );
421 GAUDI_API StatusCode parse( std::map<std::string, unsigned int>& result, std::string_view input );
426 template <typename K, typename V, typename M>
427 GAUDI_API StatusCode parse( GaudiUtils::Map<K, V, M>& result, std::string_view input ) {
428 return parse( static_cast<M&>( result ), input );
429 }
430
456 GAUDI_API StatusCode parse( std::string& name, std::string& value, std::string_view input );
465 GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, std::string_view input );
474 GAUDI_API StatusCode parse( std::map<std::string, Gaudi::Histo1DDef>& histos, std::string_view input );
483 GAUDI_API StatusCode parse( std::map<std::string, std::pair<double, double>>& params, std::string_view input );
493 GAUDI_API StatusCode parse( std::map<std::string, std::pair<int, int>>& params, std::string_view input );
501 template <class T, unsigned int N>
502 StatusCode parse( T ( &result )[N], std::string_view input ) {
503 typedef std::vector<T> _Vct;
504 // create the temporary vector
505 _Vct tmp;
506 StatusCode sc = parse( tmp, input );
507 if ( sc.isFailure() ) { return sc; }
508 if ( N != tmp.size() ) { return StatusCode::FAILURE; }
509 //
510 std::copy( tmp.begin(), tmp.end(), result );
511 //
512 return StatusCode::SUCCESS;
513 }
514
521 template <unsigned int N>
522 StatusCode parse( char ( &result )[N], std::string_view input ) {
523 // clear the string
524 std::fill_n( result, N, ' ' );
525 // create the temporary string
526 std::string tmp;
527 StatusCode sc = parse( tmp, input );
528 if ( sc.isFailure() ) { return sc; }
529 if ( N == tmp.size() ) {
530 std::copy( tmp.begin(), tmp.end(), result );
531 } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
532 std::copy( tmp.begin() + 1, tmp.end() - 1, result );
533 } else {
534 return StatusCode::FAILURE;
535 }
536 //
537 return StatusCode::SUCCESS;
538 }
539 } // namespace Parsers
540} // namespace Gaudi
#define PARSERS_DECL_FOR_SET(InnerType)
#define PARSERS_DECL_FOR_SINGLE(Type)
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
#define PARSERS_DECL_FOR_LIST(InnerType)
#define GAUDI_API
Definition Kernel.h:49
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition HistoDef.h:30
Extension of the STL map.
Definition Map.h:83
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1