The Gaudi Framework  v33r0 (d5ea422b)
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  // ========================================================================
315  // ========================================================================
330  // ========================================================================
345  // ========================================================================
362  // ========================================================================
379  // ========================================================================
396  // ========================================================================
405  // ========================================================================
414  // ========================================================================
420  // ========================================================================
425  template <typename K, typename V, typename M>
427  return parse( (M&)result, input );
428  }
429  // ========================================================================
457  // ========================================================================
466  GAUDI_API StatusCode parse( Gaudi::Histo1DDef& histo, const std::string& input );
467  // ========================================================================
477  // ========================================================================
490  // ========================================================================
498  template <class T, unsigned int N>
499  StatusCode parse( T ( &result )[N], const std::string& input ) {
500  typedef std::vector<T> _Vct;
501  // create the temporary vector
502  _Vct tmp;
503  StatusCode sc = parse( tmp, input );
504  if ( sc.isFailure() ) { return sc; } // RETURN
505  if ( N != tmp.size() ) { return StatusCode::FAILURE; } // RETURN
506  //
507  std::copy( tmp.begin(), tmp.end(), result );
508  //
509  return StatusCode::SUCCESS; // RETURN
510  }
511  // ========================================================================
519  template <unsigned int N>
520  StatusCode parse( char ( &result )[N], const std::string& input ) {
521  // clear the string
522  std::fill_n( result, N, ' ' );
523  // create the temporary string
524  std::string tmp;
525  StatusCode sc = parse( tmp, input );
526  if ( sc.isFailure() ) { return sc; } // RETURN
527  if ( N == tmp.size() ) {
528  std::copy( tmp.begin(), tmp.end(), result );
529  } else if ( N + 2 == tmp.size() && ( '\'' == tmp[0] || '\"' == tmp[0] ) && ( tmp[0] == tmp[tmp.size() - 1] ) ) {
530  std::copy( tmp.begin() + 1, tmp.end() - 1, result );
531  } else {
532  return StatusCode::FAILURE;
533  }
534  //
535  return StatusCode::SUCCESS; // RETURN
536  }
537  // ========================================================================
538  } // namespace Parsers
539  // ==========================================================================
540 } // end of namespace Gaudi
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: CommonParsers.h:33
Extension of the STL map.
Definition: Map.h:91
T copy(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
T end(T... args)
STL class.
STL class.
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: CommonParsers.h:30
int N
Definition: IOTest.py:110
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition: HistoDef.h:41
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: CommonParsers.h:28
T size(T... args)
STL class.
T begin(T... args)
T fill_n(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool isFailure() const
Definition: StatusCode.h:141
#define GAUDI_API
Definition: Kernel.h:81
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1