The Gaudi Framework  master (41389df7)
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
35#define PARSERS_DECL_FOR_STRMAP( ValueType ) \
36 GAUDI_API StatusCode parse( std::map<std::string, ValueType>& result, std::string_view input ); \
37 GAUDI_API StatusCode parse( std::map<std::string, ValueType, std::less<>>& result, std::string_view input );
38
70namespace Gaudi {
71 class Histo1DDef;
72 namespace Parsers {
97 PARSERS_DECL_FOR_SINGLE( unsigned char )
99 PARSERS_DECL_FOR_SINGLE( signed char )
115 PARSERS_DECL_FOR_SINGLE( unsigned short )
117 PARSERS_DECL_FOR_SINGLE( unsigned int )
121 PARSERS_DECL_FOR_SINGLE( unsigned long )
123 PARSERS_DECL_FOR_SINGLE( long long )
125 PARSERS_DECL_FOR_SINGLE( unsigned long long )
141 PARSERS_DECL_FOR_SINGLE( long double )
153 PARSERS_DECL_FOR_SINGLE( std::string )
154
157 PARSERS_DECL_FOR_LIST( unsigned char )
158 PARSERS_DECL_FOR_LIST( signed char )
159
161 PARSERS_DECL_FOR_LIST( short )
162 PARSERS_DECL_FOR_LIST( unsigned short )
163 PARSERS_DECL_FOR_LIST( unsigned int )
165 PARSERS_DECL_FOR_LIST( unsigned long )
166 PARSERS_DECL_FOR_LIST( long long )
167 PARSERS_DECL_FOR_LIST( unsigned long long )
168
169 PARSERS_DECL_FOR_LIST( double )
170 PARSERS_DECL_FOR_LIST( float )
171 PARSERS_DECL_FOR_LIST( long double )
172
173 PARSERS_DECL_FOR_LIST( std::string )
174
177 PARSERS_DECL_FOR_SET( unsigned char )
178 PARSERS_DECL_FOR_SET( signed char )
179
181 PARSERS_DECL_FOR_SET( short )
182 PARSERS_DECL_FOR_SET( unsigned short )
183 PARSERS_DECL_FOR_SET( unsigned int )
185 PARSERS_DECL_FOR_SET( unsigned long )
186 PARSERS_DECL_FOR_SET( long long )
187 PARSERS_DECL_FOR_SET( unsigned long long )
188
189 PARSERS_DECL_FOR_SET( double )
190 PARSERS_DECL_FOR_SET( float )
191 PARSERS_DECL_FOR_SET( long double )
192
193 PARSERS_DECL_FOR_SET( std::string )
194
195 // Parsers for std::map<std::string, T>
196 PARSERS_DECL_FOR_STRMAP( std::string )
198 PARSERS_DECL_FOR_STRMAP( unsigned int )
200 PARSERS_DECL_FOR_STRMAP( std::vector<std::string> )
201 PARSERS_DECL_FOR_STRMAP( std::vector<int> )
202 PARSERS_DECL_FOR_STRMAP( std::vector<double> )
203 using IntPair = std::pair<int, int>; // needed to avoid macro parsing error due to brackets
204 using DoublePair = std::pair<double, double>;
208
221 PARSERS_DECL_FOR_PAIR( double, double )
234 PARSERS_DECL_FOR_PAIR( int, int )
248 GAUDI_API StatusCode parse( std::vector<std::pair<double, double>>& result, std::string_view input );
262 GAUDI_API StatusCode parse( std::vector<std::pair<int, int>>& result, std::string_view input );
275 GAUDI_API StatusCode parse( std::vector<std::vector<std::string>>& result, std::string_view input );
288 GAUDI_API StatusCode parse( std::vector<std::vector<double>>& result, std::string_view input );
297 GAUDI_API StatusCode parse( std::vector<std::vector<int>>& result, std::string_view input );
298 // map< TYPE, TYPE >
311 GAUDI_API StatusCode parse( std::map<int, int>& result, std::string_view input );
325 GAUDI_API StatusCode parse( std::map<int, double>& result, std::string_view input );
333 GAUDI_API StatusCode parse( std::map<int, std::string>& result, std::string_view input );
341 GAUDI_API StatusCode parse( std::map<unsigned int, std::string>& result, std::string_view input );
346 template <typename K, typename V, typename M>
347 GAUDI_API StatusCode parse( GaudiUtils::Map<K, V, M>& result, std::string_view input ) {
348 return parse( static_cast<M&>( result ), input );
349 }
350
376 GAUDI_API StatusCode parse( std::string& name, std::string& value, std::string_view input );
385 GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, std::string_view input );
393 template <class T, unsigned int N>
394 StatusCode parse( T ( &result )[N], std::string_view input ) {
395 typedef std::vector<T> _Vct;
396 // create the temporary vector
397 _Vct tmp;
398 StatusCode sc = parse( tmp, input );
399 if ( sc.isFailure() ) { return sc; }
400 if ( N != tmp.size() ) { return StatusCode::FAILURE; }
401 //
402 std::copy( tmp.begin(), tmp.end(), result );
403 //
404 return StatusCode::SUCCESS;
405 }
406
413 template <unsigned int N>
414 StatusCode parse( char ( &result )[N], std::string_view input ) {
415 // clear the string
416 std::fill_n( result, N, ' ' );
417 // create the temporary string
418 std::string tmp;
419 StatusCode sc = parse( tmp, input );
420 if ( sc.isFailure() ) { return sc; }
421 if ( N == tmp.size() ) {
422 std::copy( tmp.begin(), tmp.end(), result );
423 } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
424 std::copy( tmp.begin() + 1, tmp.end() - 1, result );
425 } else {
426 return StatusCode::FAILURE;
427 }
428 //
429 return StatusCode::SUCCESS;
430 }
431 } // namespace Parsers
432} // 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 PARSERS_DECL_FOR_STRMAP(ValueType)
#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
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
STL class.
std::pair< int, int > IntPair
parse the bool value
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::pair< double, double > DoublePair
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.