StdArrayAsProperty.h
Go to the documentation of this file.
1 // $Id: $
2 // ============================================================================
3 #ifndef GAUDIKERNEL_STDARRAYASPROPERTY_H
4 #define GAUDIKERNEL_STDARRAYASPROPERTY_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // STD & STL
9 // ============================================================================
10 #include <algorithm>
11 #include <array>
12 // ============================================================================
24 // ============================================================================
25 // 1) Streamers : value -> string
26 // ============================================================================
27 namespace Gaudi
28 {
29  // ==========================================================================
30  namespace Utils
31  {
32  // ========================================================================
33  template <class ITERATOR>
34  inline std::ostream& toStream
35  ( ITERATOR first , // begin of the sequence
36  ITERATOR last , // end of the sequence
37  std::ostream& s , // the stream
38  const std::string& open , // opening
39  const std::string& close , // closing
40  const std::string& delim ) ; // delimiter
41  // ========================================================================
50  template <class TYPE, std::size_t N>
51  inline std::ostream& toStream
52  ( const std::array<TYPE,N>& obj , std::ostream& s )
53  {
54  return toStream
55  ( obj.begin () , obj.end () , s , " ( " , " )" , " , " ) ;
56  }
57  // ========================================================================
58  } // end of namespace Gaudi::Utils
59  // ==========================================================================
60 } // end of namespace Gaudi
61 // ============================================================================
62 // 2) Parsers: string -> value
63 // ============================================================================
64 // GaudiKernel
65 // ============================================================================
66 #include "GaudiKernel/Parsers.h"
67 // ============================================================================
68 namespace Gaudi
69 {
70  // ==========================================================================
71  namespace Parsers
72  {
73  // ========================================================================
81  template <class TYPE, std::size_t N>
83  parse ( std::array<TYPE,N>& result , const std::string& input )
84  {
85  typedef std::vector<TYPE> _Vct ;
86  // create the temporaty vector
87  _Vct tmp ;
88  // parse the string
89  StatusCode sc = parse ( tmp , input ) ;
90  if ( sc.isFailure () ) { return sc ; } // RETURN
91  if ( N != tmp.size() )
92  { return StatusCode ( StatusCode::FAILURE , true ) ; } // RETURN
93  // copy vector into array
94  std::copy ( tmp.begin() , tmp.end() , result.begin() ) ;
95  //
96  return StatusCode::SUCCESS ;
97  }
98  // ========================================================================
99  } // end of namespace Gaudi::Parsers
100  // ==========================================================================
101 } // end of namespace Gaudi
102 // ============================================================================
103 // 3) Assignements and constructors
104 // ============================================================================
105 // GaudiKernel
106 // ============================================================================
108 // ============================================================================
109 namespace Gaudi
110 {
111  // ==========================================================================
112  namespace Utils
113  {
114  // ========================================================================
121  template <class T, std::size_t N>
122  struct PropertyTypeTraits<std::array<T,N> >
123  {
124  // =======================================================================
125  typedef std::array<T,N> TYPE ;
126  typedef TYPE Type ;
127  typedef const TYPE& PRef ;
128  typedef TYPE* PVal ;
129  typedef const TYPE* CVal ;
130  // =======================================================================
132  static PVal new_ ()
133  {
134  PVal tmp = new Type ;
135  std::fill_n ( tmp->begin() , N , T() ) ;
136  return tmp ;
137  }
139  static PVal new_ ( const Type& right )
140  {
141  PVal tmp = new Type ;
142  assign ( *tmp , right ) ;
143  return tmp ;
144  }
146  static void dele ( PVal right , const bool own )
147  { if ( own ) { delete right ; } }
149  static PVal copy ( PVal right , const bool own )
150  {
151  if ( !own ) { return right ; }
152  return new_ ( *right ) ;
153  }
155  static void assign ( Type& v1 , const Type& v2 )
156  { std::copy ( v2.begin() , v2.end() , v1.begin() ) ; }
158  static bool less ( const Type& v1 , const Type& v2 )
159  { return std::lexicographical_compare
160  ( v1.begin() , v1.end () , v2.begin() , v2.end() ) ; }
161  // ======================================================================
162  } ;
163  // ========================================================================
164  } // end of namespace Gaudi::Utils
165  // ==========================================================================
166 } // end of namespace Gaudi
167 // ============================================================================
168 // The END
169 // ============================================================================
170 #endif // GAUDIKERNEL_STDARRAYASPROPERTY_H
171 // ============================================================================
helper structure to define the types for properties
static PVal copy(PVal right, const bool own)
"smart" copy-constructor
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
static PVal new_()
some kind of default constructor
STL namespace.
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
static void dele(PVal right, const bool own)
"smart" destructor
static bool less(const Type &v1, const Type &v2)
comparison (needed for bounded verifier) NON-TRIVIAL
int N
Definition: IOTest.py:90
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:341
static void assign(Type &v1, PRef v2)
assignment
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
static PVal new_()
some kind of default constructor NON-TRIVIAL
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
string s
Definition: gaudirun.py:217
static PVal new_(const Type &right)
some kind of copy constructor NON-TRIVIAL
Helper functions to set/get the application return code.
Definition: __init__.py:1
static void assign(Type &v1, const Type &v2)
assignement NON-TRIVIAL