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