The Gaudi Framework
v41r0 (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
CommonParsers.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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
13
#include <
GaudiKernel/HistoDef.h
>
14
#include <
GaudiKernel/Map.h
>
15
#include <
GaudiKernel/StatusCode.h
>
16
#include <list>
17
#include <map>
18
#include <nlohmann/json_fwd.hpp>
19
#include <set>
20
#include <string>
21
#include <unordered_set>
22
#include <vector>
23
24
#define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, std::string_view input );
25
26
#define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \
27
GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, std::string_view input );
28
29
#define PARSERS_DECL_FOR_LIST( InnerType ) \
30
GAUDI_API StatusCode parse( std::vector<InnerType>& result, std::string_view input );
31
32
#define PARSERS_DECL_FOR_SET( InnerType ) \
33
GAUDI_API StatusCode parse( std::set<InnerType>& result, std::string_view input ); \
34
GAUDI_API StatusCode parse( std::unordered_set<InnerType>& result, std::string_view input );
35
36
#define PARSERS_DECL_FOR_STRMAP( ValueType ) \
37
GAUDI_API StatusCode parse( std::map<std::string, ValueType>& result, std::string_view input ); \
38
GAUDI_API StatusCode parse( std::map<std::string, ValueType, std::less<>>& result, std::string_view input );
39
71
namespace
Gaudi
{
72
class
Histo1DDef;
73
namespace
Parsers {
84
PARSERS_DECL_FOR_SINGLE
(
bool
)
96
PARSERS_DECL_FOR_SINGLE
(
char
)
98
PARSERS_DECL_FOR_SINGLE
(
unsigned
char
)
100
PARSERS_DECL_FOR_SINGLE
(
signed
char
)
112
PARSERS_DECL_FOR_SINGLE
(
int
)
114
PARSERS_DECL_FOR_SINGLE
(
short
)
116
PARSERS_DECL_FOR_SINGLE
(
unsigned
short
)
118
PARSERS_DECL_FOR_SINGLE
(
unsigned
int
)
120
PARSERS_DECL_FOR_SINGLE
(
long
)
122
PARSERS_DECL_FOR_SINGLE
(
unsigned
long
)
124
PARSERS_DECL_FOR_SINGLE
(
long
long
)
126
PARSERS_DECL_FOR_SINGLE
(
unsigned
long
long
)
138
PARSERS_DECL_FOR_SINGLE
(
double
)
140
PARSERS_DECL_FOR_SINGLE
(
float
)
142
PARSERS_DECL_FOR_SINGLE
(
long
double
)
154
PARSERS_DECL_FOR_SINGLE
( std::string )
155
PARSERS_DECL_FOR_SINGLE
( nlohmann::json )
156
157
PARSERS_DECL_FOR_LIST
(
bool
)
158
PARSERS_DECL_FOR_LIST
(
char
)
159
PARSERS_DECL_FOR_LIST
(
unsigned
char
)
160
PARSERS_DECL_FOR_LIST
(
signed
char
)
161
162
PARSERS_DECL_FOR_LIST
(
int
)
163
PARSERS_DECL_FOR_LIST
(
short
)
164
PARSERS_DECL_FOR_LIST
(
unsigned
short
)
165
PARSERS_DECL_FOR_LIST
(
unsigned
int
)
166
PARSERS_DECL_FOR_LIST
(
long
)
167
PARSERS_DECL_FOR_LIST
(
unsigned
long
)
168
PARSERS_DECL_FOR_LIST
(
long
long
)
169
PARSERS_DECL_FOR_LIST
(
unsigned
long
long
)
170
171
PARSERS_DECL_FOR_LIST
(
double
)
172
PARSERS_DECL_FOR_LIST
(
float
)
173
PARSERS_DECL_FOR_LIST
(
long
double
)
174
175
PARSERS_DECL_FOR_LIST
( std::string )
176
177
PARSERS_DECL_FOR_SET
(
bool
)
178
PARSERS_DECL_FOR_SET
(
char
)
179
PARSERS_DECL_FOR_SET
(
unsigned
char
)
180
PARSERS_DECL_FOR_SET
(
signed
char
)
181
182
PARSERS_DECL_FOR_SET
(
int
)
183
PARSERS_DECL_FOR_SET
(
short
)
184
PARSERS_DECL_FOR_SET
(
unsigned
short
)
185
PARSERS_DECL_FOR_SET
(
unsigned
int
)
186
PARSERS_DECL_FOR_SET
(
long
)
187
PARSERS_DECL_FOR_SET
(
unsigned
long
)
188
PARSERS_DECL_FOR_SET
(
long
long
)
189
PARSERS_DECL_FOR_SET
(
unsigned
long
long
)
190
191
PARSERS_DECL_FOR_SET
(
double
)
192
PARSERS_DECL_FOR_SET
(
float
)
193
PARSERS_DECL_FOR_SET
(
long
double
)
194
195
PARSERS_DECL_FOR_SET
( std::string )
196
197
// Parsers for std::map<std::string, T>
198
PARSERS_DECL_FOR_STRMAP
( std::string )
199
PARSERS_DECL_FOR_STRMAP
(
int
)
200
PARSERS_DECL_FOR_STRMAP
(
unsigned
int
)
201
PARSERS_DECL_FOR_STRMAP
(
double
)
202
PARSERS_DECL_FOR_STRMAP
( std::vector<std::string> )
203
PARSERS_DECL_FOR_STRMAP
( std::vector<int> )
204
PARSERS_DECL_FOR_STRMAP
( std::vector<double> )
205
using
IntPair
=
std
::pair<
int
,
int
>;
// needed to avoid macro parsing error due to brackets
206
using
DoublePair
=
std
::pair<
double
,
double
>;
207
PARSERS_DECL_FOR_STRMAP
(
IntPair
)
208
PARSERS_DECL_FOR_STRMAP
(
DoublePair
)
209
PARSERS_DECL_FOR_STRMAP
(
Gaudi
::
Histo1DDef
)
210
223
PARSERS_DECL_FOR_PAIR
(
double
,
double
)
236
PARSERS_DECL_FOR_PAIR
(
int
,
int
)
250
GAUDI_API
StatusCode
parse
(
std
::
vector
<
std
::pair<
double
,
double
>>& result,
std
::string_view input );
264
GAUDI_API
StatusCode
parse
(
std
::
vector
<
std
::pair<
int
,
int
>>& result,
std
::string_view input );
277
GAUDI_API
StatusCode
parse
(
std
::
vector
<
std
::
vector
<
std
::
string
>>& result,
std
::string_view input );
290
GAUDI_API
StatusCode
parse
(
std
::
vector
<
std
::
vector
<
double
>>& result,
std
::string_view input );
299
GAUDI_API
StatusCode
parse
(
std
::
vector
<
std
::
vector
<
int
>>& result,
std
::string_view input );
300
// map< TYPE, TYPE >
313
GAUDI_API
StatusCode
parse
(
std
::map<
int
,
int
>& result,
std
::string_view input );
327
GAUDI_API
StatusCode
parse
(
std
::map<
int
,
double
>& result,
std
::string_view input );
335
GAUDI_API
StatusCode
parse
(
std
::map<
int
,
std
::
string
>& result,
std
::string_view input );
343
GAUDI_API
StatusCode
parse
(
std
::map<
unsigned
int
,
std
::
string
>& result,
std
::string_view input );
348
template <typename K, typename V, typename M>
349
GAUDI_API
StatusCode
parse
(
GaudiUtils
::Map<K, V, M>& result,
std
::string_view input ) {
350
return
parse
(
static_cast<
M&
>
( result ), input );
351
}
352
378
GAUDI_API
StatusCode
parse
( std::string& name, std::string& value, std::string_view input );
387
GAUDI_API
StatusCode
parse
(
Gaudi::Histo1DDef
& histo, std::string_view input );
395
template
<
class
T,
unsigned
int
N>
396
StatusCode
parse
( T ( &result )[N], std::string_view input ) {
397
typedef
std::vector<T> _Vct;
398
// create the temporary vector
399
_Vct tmp;
400
StatusCode
sc =
parse
( tmp, input );
401
if
( sc.
isFailure
() ) {
return
sc; }
402
if
( N != tmp.size() ) {
return
StatusCode::FAILURE
; }
403
//
404
std::copy( tmp.begin(), tmp.end(), result );
405
//
406
return
StatusCode::SUCCESS
;
407
}
408
415
template
<
unsigned
int
N>
416
StatusCode
parse
(
char
( &result )[N], std::string_view input ) {
417
// clear the string
418
std::fill_n( result, N,
' '
);
419
// create the temporary string
420
std::string tmp;
421
StatusCode
sc =
parse
( tmp, input );
422
if
( sc.
isFailure
() ) {
return
sc; }
423
if
( N == tmp.size() ) {
424
std::copy( tmp.begin(), tmp.end(), result );
425
}
else
if
( N + 2 == tmp.size() && (
'\''
== tmp[0] ||
'\"'
== tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
426
std::copy( tmp.begin() + 1, tmp.end() - 1, result );
427
}
else
{
428
return
StatusCode::FAILURE
;
429
}
430
//
431
return
StatusCode::SUCCESS
;
432
}
433
}
// namespace Parsers
434
}
// namespace Gaudi
PARSERS_DECL_FOR_SET
#define PARSERS_DECL_FOR_SET(InnerType)
Definition
CommonParsers.h:32
PARSERS_DECL_FOR_SINGLE
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition
CommonParsers.h:24
PARSERS_DECL_FOR_PAIR
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition
CommonParsers.h:26
PARSERS_DECL_FOR_LIST
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition
CommonParsers.h:29
PARSERS_DECL_FOR_STRMAP
#define PARSERS_DECL_FOR_STRMAP(ValueType)
Definition
CommonParsers.h:36
HistoDef.h
GAUDI_API
#define GAUDI_API
Definition
Kernel.h:49
Map.h
StatusCode.h
Gaudi::Histo1DDef
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition
HistoDef.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
vector
STL class.
Gaudi::Parsers::IntPair
std::pair< int, int > IntPair
parse the bool value
Definition
CommonParsers.h:205
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition
DODBasicMapper.cpp:21
Gaudi::Parsers::DoublePair
std::pair< double, double > DoublePair
Definition
CommonParsers.h:206
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
GaudiUtils
Definition
Allocator.h:62
std
STL namespace.
GaudiKernel
include
Gaudi
Parsers
CommonParsers.h
Generated on
for The Gaudi Framework by
1.17.0