Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
13 #include <GaudiKernel/HistoDef.h>
14 #include <GaudiKernel/Map.h>
15 #include <GaudiKernel/StatusCode.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 
66 namespace Gaudi {
67  class Histo1DDef;
68  namespace Parsers {
93  PARSERS_DECL_FOR_SINGLE( unsigned char )
95  PARSERS_DECL_FOR_SINGLE( signed char )
109  PARSERS_DECL_FOR_SINGLE( short )
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 )
133  PARSERS_DECL_FOR_SINGLE( double )
135  PARSERS_DECL_FOR_SINGLE( float )
137  PARSERS_DECL_FOR_SINGLE( long double )
149  PARSERS_DECL_FOR_SINGLE( std::string )
150 
151  PARSERS_DECL_FOR_LIST( bool )
152  PARSERS_DECL_FOR_LIST( char )
153  PARSERS_DECL_FOR_LIST( unsigned char )
154  PARSERS_DECL_FOR_LIST( signed char )
155 
156  PARSERS_DECL_FOR_LIST( int )
157  PARSERS_DECL_FOR_LIST( short )
158  PARSERS_DECL_FOR_LIST( unsigned short )
159  PARSERS_DECL_FOR_LIST( unsigned int )
160  PARSERS_DECL_FOR_LIST( long )
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 
171  PARSERS_DECL_FOR_SET( bool )
172  PARSERS_DECL_FOR_SET( char )
173  PARSERS_DECL_FOR_SET( unsigned char )
174  PARSERS_DECL_FOR_SET( signed char )
175 
176  PARSERS_DECL_FOR_SET( int )
177  PARSERS_DECL_FOR_SET( short )
178  PARSERS_DECL_FOR_SET( unsigned short )
179  PARSERS_DECL_FOR_SET( unsigned int )
180  PARSERS_DECL_FOR_SET( long )
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( (M&)result, input );
429  }
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  }
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
PARSERS_DECL_FOR_LIST
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: CommonParsers.h:28
IOTest.N
N
Definition: IOTest.py:112
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
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:27
StatusCode.h
PARSERS_DECL_FOR_SINGLE
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: CommonParsers.h:23
HistoDef.h
Gaudi::Histo1DDef
Definition: HistoDef.h:30
StatusCode
Definition: StatusCode.h:64
GaudiUtils::Map
Definition: Map.h:82
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:31
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
compareRootHistos.histos
histos
Definition: compareRootHistos.py:26
PARSERS_DECL_FOR_PAIR
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: CommonParsers.h:25
PARSERS_DECL_FOR_SET
#define PARSERS_DECL_FOR_SET(InnerType)
Definition: CommonParsers.h:31
Map.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49