CArrayAsProperty.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_CARRAYASPROPERTY_H
2 #define GAUDIKERNEL_CARRAYASPROPERTY_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <algorithm>
9 // ============================================================================
10 // GauidKernel
11 // ============================================================================
12 #include "GaudiKernel/PropertyTypeTraits.h"
13 #include "GaudiKernel/PropertyVerifier.h"
14 // ============================================================================
30 // ============================================================================
31 // 1) Streamers : value -> string , done in GausiKernel/ToStream.h
32 // ============================================================================
33 // 2) Parsers : string -> value , done in GaudiKernel/Parsers.h
34 // ============================================================================
35 // 3) assigements and copy
36 // ============================================================================
37 namespace Gaudi
38 {
39  // ==========================================================================
40  namespace Utils
41  {
42  // ========================================================================
43  template <class T, unsigned int N>
44  struct PropertyTypeTraits<T(&)[N]>
45  {
46  // ======================================================================
47  typedef T(&Type) [N] ;
48  typedef T(&PRef) [N] ;
49  typedef T(*PVal) [N] ;
50  typedef const T(&CRef) [N] ;
51  typedef const T(*CVal) [N] ;
52  // ======================================================================
53  public:
54  // ======================================================================
56  static PVal new_ () { return new T[N] ; }
58  static PVal new_ ( Type right )
59  {
60  PVal tmp = new_ () ;
61  assign ( tmp , right ) ;
62  return tmp ;
63  }
65  static PVal copy ( PVal* right , const bool own )
66  {
67  if ( !own ) { return right ; }
68  return new_ ( *right ) ;
69  }
71  static void dele ( PVal right , const bool own )
72  { if ( own ) { delete[] right ; } }
73  // ======================================================================
74  // assigenements
75  static void assign ( Type v1 , PRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
76  static void assign ( Type v1 , CRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
78  static bool less ( Type v1 , Type v2 )
79  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
80  static bool less ( Type v1 , CRef v2 )
81  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
82  static bool less ( CRef v1 , CRef v2 )
83  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
84  static bool less ( CRef v1 , Type v2 )
85  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
86  // ======================================================================
87  } ;
88  // ========================================================================
90  template <class T, unsigned int N>
91  struct PropertyTypeTraits<T[N]> : public PropertyTypeTraits<T(&)[N]>
92  {} ;
93  // ========================================================================
95  template <class T, unsigned int N>
96  struct PropertyTypeTraits< const T(&)[N]>
97  {} ;
99  template <unsigned int N>
100  struct PropertyTypeTraits<char(&)[N]>
101  {} ;
102  // ========================================================================
103  } // end of namespace Gaudi::Utils
104  // ==========================================================================
105 } // end of namespace Gaudi
106 // ============================================================================
107 // property verifier
108 // ============================================================================
110 template< class T, unsigned int N>
111 class BoundedVerifier<T[N]> : PropertyVerifier<T[N]>
112 {
113  // ==========================================================================
115  // Abstract derived class
116  // ==========================================================================
117 public:
119  BoundedVerifier()
120  : m_hasLowerBound ( false )
121  , m_hasUpperBound ( false )
122  {}
124  virtual ~BoundedVerifier() = default;
125 
127  bool isValid ( const typename Traits::CVal value ) const
128  {
129  return
130  ( ( m_hasLowerBound && Traits::less ( *value , m_lowerBound ) ) ? false : true )
131  &&
132  ( ( m_hasUpperBound && Traits::less ( m_upperBound , *value ) ) ? false : true ) ;
133  }
135  bool hasLower() const { return m_hasLowerBound; }
137  bool hasUpper() const { return m_hasUpperBound; }
139  typename Traits::CRef lower() const { return m_lowerBound; }
141  typename Traits::CRef upper() const { return m_upperBound; }
142 
144  void setLower( typename Traits::CRef value ) { m_hasLowerBound = true; Traits::assign ( m_lowerBound , value ) ; }
146  void setUpper( typename Traits::CRef value ) { m_hasUpperBound = true; Traits::assign ( m_upperBound , value ) ; }
148  void clearLower() { m_hasLowerBound = false; }
150  void clearUpper() { m_hasUpperBound = false; }
151 
153  void setBounds( typename Traits::CRef lower, typename Traits::CRef upper)
154  {
155  setLower( lower );
156  setUpper( upper );
157  }
158 
160  void clearBounds()
161  {
162  clearLower();
163  clearUpper();
164  }
165 
166  private:
167  // ==========================================================================
170  bool m_hasLowerBound ;
171  bool m_hasUpperBound ;
172  const T m_lowerBound [N] ;
173  const T m_upperBound [N] ;
174  // ==========================================================================
175 };
176 // ============================================================================
177 // The END
178 // ============================================================================
179 #endif // GAUDIKERNEL_CARRAYASPROPERTY_H
180 // ============================================================================
bool isValid(const typename Gaudi::Utils::PropertyTypeTraits< T >::CVal value) const override
Check if the value is within bounds.
Templated Verifier base class.
helper structure to define the types for properties
~BoundedVerifier() override=default
Destructor.
void clearLower()
Clear lower bound value.
bool m_hasLowerBound
Data and Function Members for This Class Implementation.
void setLower(const T &value)
Set lower bound value.
bool hasLower() const
Return if it has a lower bound.
void clearUpper()
Clear upper bound value.
void setBounds(const T &lower, const T &upper)
Set both bounds (lower and upper) at the same time.
int N
Definition: IOTest.py:90
const T & lower() const
Return the lower bound value.
bool hasUpper() const
Return if it has a lower bound.
const T & upper() const
Return the upper bound value.
void setUpper(const T &value)
Set upper bound value.
void clearBounds()
Clear both bounds (lower and upper) at the same time.
Type
the list of available types for ntuples
Definition: TupleObj.h:73
Helper functions to set/get the application return code.
Definition: __init__.py:1
BoundedVerifier()
Constructors.