Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
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-2019 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 files
14 // ============================================================================
15 // STD & STL
16 // ============================================================================
17 #include <list>
18 #include <map>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 // ============================================================================
24 #include "GaudiKernel/HistoDef.h"
25 #include "GaudiKernel/Map.h"
26 #include "GaudiKernel/StatusCode.h"
27 // ============================================================================
28 #define PARSERS_DECL_FOR_SINGLE( Type ) GAUDI_API StatusCode parse( Type& result, const std::string& input );
29 
30 #define PARSERS_DECL_FOR_PAIR( FirstType, SecondType ) \
31  GAUDI_API StatusCode parse( std::pair<FirstType, SecondType>& result, const std::string& input );
32 
33 #define PARSERS_DECL_FOR_LIST( InnerType ) \
34  GAUDI_API StatusCode parse( std::vector<InnerType>& result, const std::string& input );
35 // ============================================================================
67 // ============================================================================
68 namespace Gaudi {
69  // ==========================================================================
70  class Histo1DDef;
71  // ==========================================================================
72  namespace Parsers {
73  // ========================================================================
85  // ========================================================================
99  PARSERS_DECL_FOR_SINGLE( unsigned char )
101  PARSERS_DECL_FOR_SINGLE( signed char )
102  // ========================================================================
116  PARSERS_DECL_FOR_SINGLE( short )
118  PARSERS_DECL_FOR_SINGLE( unsigned short )
120  PARSERS_DECL_FOR_SINGLE( unsigned int )
124  PARSERS_DECL_FOR_SINGLE( unsigned long )
126  PARSERS_DECL_FOR_SINGLE( long long )
128  PARSERS_DECL_FOR_SINGLE( unsigned long long )
129  // ========================================================================
141  PARSERS_DECL_FOR_SINGLE( double )
143  PARSERS_DECL_FOR_SINGLE( float )
145  PARSERS_DECL_FOR_SINGLE( long double )
146  // ========================================================================
159  // ========================================================================
160 
161  PARSERS_DECL_FOR_LIST( bool )
162  PARSERS_DECL_FOR_LIST( char )
163  PARSERS_DECL_FOR_LIST( unsigned char )
164  PARSERS_DECL_FOR_LIST( signed char )
165 
166  PARSERS_DECL_FOR_LIST( int )
167  PARSERS_DECL_FOR_LIST( short )
168  PARSERS_DECL_FOR_LIST( unsigned short )
169  PARSERS_DECL_FOR_LIST( unsigned int )
170  PARSERS_DECL_FOR_LIST( long )
171  PARSERS_DECL_FOR_LIST( unsigned long )
172  PARSERS_DECL_FOR_LIST( long long )
173  PARSERS_DECL_FOR_LIST( unsigned long long )
174 
175  PARSERS_DECL_FOR_LIST( double )
176  PARSERS_DECL_FOR_LIST( float )
177  PARSERS_DECL_FOR_LIST( long double )
178 
180  // ========================================================================
181  // Advanced parses
182  // ========================================================================
195  PARSERS_DECL_FOR_PAIR( double, double )
196  // ========================================================================
209  PARSERS_DECL_FOR_PAIR( int, int )
210  // ========================================================================
225  // ========================================================================
240  // ========================================================================
241  // vector< vector< TYPE > >
242  // ========================================================================
256  // ========================================================================
270  // ========================================================================
271  // map< TYPE, TYPE >
272  // ========================================================================
285  GAUDI_API StatusCode parse( std::map<int, int>& result, const std::string& input );
286  // ========================================================================
301  // ========================================================================
316  // ========================================================================
331  // ========================================================================
346  // ========================================================================
363  // ========================================================================
380  // ========================================================================
397  // ========================================================================
406  // ========================================================================
415  // ========================================================================
421  // ========================================================================
426  template <typename K, typename V, typename M>
428  return parse( (M&)result, input );
429  }
430  // ========================================================================
458  // ========================================================================
467  GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, const std::string& input );
468  // ========================================================================
478  // ========================================================================
491  // ========================================================================
499  template <class T, unsigned int N>
500  StatusCode parse( T ( &result )[N], const std::string& input ) {
501  typedef std::vector<T> _Vct;
502  // create the temporary vector
503  _Vct tmp;
504  StatusCode sc = parse( tmp, input );
505  if ( sc.isFailure() ) { return sc; } // RETURN
506  if ( N != tmp.size() ) { return StatusCode::FAILURE; } // RETURN
507  //
508  std::copy( tmp.begin(), tmp.end(), result );
509  //
510  return StatusCode::SUCCESS; // RETURN
511  }
512  // ========================================================================
520  template <unsigned int N>
521  StatusCode parse( char ( &result )[N], const std::string& input ) {
522  // clear the string
523  std::fill_n( result, N, ' ' );
524  // create the temporary string
525  std::string tmp;
526  StatusCode sc = parse( tmp, input );
527  if ( sc.isFailure() ) { return sc; } // RETURN
528  if ( N == tmp.size() ) {
529  std::copy( tmp.begin(), tmp.end(), result );
530  } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
531  std::copy( tmp.begin() + 1, tmp.end() - 1, result );
532  } else {
533  return StatusCode::FAILURE;
534  }
535  //
536  return StatusCode::SUCCESS; // RETURN
537  }
538  // ========================================================================
539  } // namespace Parsers
540  // ==========================================================================
541 } // end of namespace Gaudi
PARSERS_DECL_FOR_LIST
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: CommonParsers.h:33
std::string
STL class.
IOTest.N
N
Definition: IOTest.py:110
bug_34121.name
name
Definition: bug_34121.py:20
std::pair< double, double >
std::vector
STL class.
std::string::size
T size(T... args)
std::less
StatusCode.h
PARSERS_DECL_FOR_SINGLE
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: CommonParsers.h:28
HistoDef.h
Gaudi::Histo1DDef
Definition: HistoDef.h:41
StatusCode
Definition: StatusCode.h:65
GaudiUtils::Map
Definition: Map.h:91
std::copy
T copy(T... args)
std::map< int, int >
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
compareRootHistos.histos
histos
Definition: compareRootHistos.py:26
std::string::begin
T begin(T... args)
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:21
PARSERS_DECL_FOR_PAIR
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: CommonParsers.h:30
std::string::end
T end(T... args)
Map.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
std::fill_n
T fill_n(T... args)
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81