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 // ============================================================================
14 // ============================================================================
29 // ============================================================================
30 // 1) Streamers : value -> string , done in GausiKernel/ToStream.h
31 // ============================================================================
32 // 2) Parsers : string -> value , done in GaudiKernel/Parsers.h
33 // ============================================================================
34 // 3) assignments and copy
35 // ============================================================================
36 namespace Gaudi
37 {
38  // ==========================================================================
39  namespace Utils
40  {
41  // ========================================================================
42  template <class T, unsigned int N>
43  struct PropertyTypeTraits<T(&)[N]>
44  {
45  // ======================================================================
46  typedef T(&Type) [N] ;
47  typedef T(&PRef) [N] ;
48  typedef T(*PVal) [N] ;
49  typedef const T(&CRef) [N] ;
50  typedef const T(*CVal) [N] ;
51  // ======================================================================
52  public:
53  // ======================================================================
55  static PVal new_ () { return new T[N] ; }
57  static PVal new_ ( Type right )
58  {
59  PVal tmp = new_ () ;
60  assign ( tmp , right ) ;
61  return tmp ;
62  }
64  static PVal copy ( PVal* right , const bool own )
65  {
66  if ( !own ) { return right ; }
67  return new_ ( *right ) ;
68  }
70  static void dele ( PVal right , const bool own )
71  { if ( own ) { delete[] right ; } }
72  // ======================================================================
73  // assigenements
74  static void assign ( Type v1 , PRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
75  static void assign ( Type v1 , CRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
77  static bool less ( Type v1 , Type v2 )
78  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
79  static bool less ( Type v1 , CRef v2 )
80  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
81  static bool less ( CRef v1 , CRef v2 )
82  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
83  static bool less ( CRef v1 , Type v2 )
84  { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
85  // ======================================================================
86  } ;
87  // ========================================================================
89  template <class T, unsigned int N>
90  struct PropertyTypeTraits<T[N]> : public PropertyTypeTraits<T(&)[N]>
91  {} ;
92  // ========================================================================
94  template <class T, unsigned int N>
95  struct PropertyTypeTraits< const T(&)[N]>
96  {} ;
98  template <unsigned int N>
99  struct PropertyTypeTraits<char(&)[N]>
100  {} ;
101  // ========================================================================
102  } // end of namespace Gaudi::Utils
103  // ==========================================================================
104 } // end of namespace Gaudi
105 // ============================================================================
106 // property verifier
107 // ============================================================================
109 template< class T, unsigned int N>
111 {
112  // ==========================================================================
114  // Abstract derived class
115  // ==========================================================================
116 public:
119  : m_hasLowerBound ( false )
120  , m_hasUpperBound ( false )
121  {}
123  virtual ~BoundedVerifier() = default;
124 
126  bool isValid ( const typename Traits::CVal value ) const
127  {
128  return
129  ( ( m_hasLowerBound && Traits::less ( *value , m_lowerBound ) ) ? false : true )
130  &&
131  ( ( m_hasUpperBound && Traits::less ( m_upperBound , *value ) ) ? false : true ) ;
132  }
134  bool hasLower() const { return m_hasLowerBound; }
136  bool hasUpper() const { return m_hasUpperBound; }
138  typename Traits::CRef lower() const { return m_lowerBound; }
140  typename Traits::CRef upper() const { return m_upperBound; }
141 
143  void setLower( typename Traits::CRef value ) { m_hasLowerBound = true; Traits::assign ( m_lowerBound , value ) ; }
145  void setUpper( typename Traits::CRef value ) { m_hasUpperBound = true; Traits::assign ( m_upperBound , value ) ; }
147  void clearLower() { m_hasLowerBound = false; }
149  void clearUpper() { m_hasUpperBound = false; }
150 
152  void setBounds( typename Traits::CRef lower, typename Traits::CRef upper)
153  {
154  setLower( lower );
155  setUpper( upper );
156  }
157 
159  void clearBounds()
160  {
161  clearLower();
162  clearUpper();
163  }
164 
165  private:
166  // ==========================================================================
171  const T m_lowerBound [N] ;
172  const T m_upperBound [N] ;
173  // ==========================================================================
174 };
175 // ============================================================================
176 // The END
177 // ============================================================================
178 #endif // GAUDIKERNEL_CARRAYASPROPERTY_H
179 // ============================================================================
static void dele(PVal right, const bool own)
"smart" pseudo-destructor
Templated Verifier base class.
helper structure to define the types for properties
~BoundedVerifier() override=default
Destructor.
static bool less(Type v1, CRef v2)
T copy(T...args)
bool m_hasLowerBound
Data and Function Members for This Class Implementation.
void clearBounds()
Clear both bounds (lower and upper) at the same time.
static bool less(Type v1, Type v2)
comparison (needed for bounded verifier)
void clearUpper()
Clear upper bound value.
void clearLower()
Clear lower bound value.
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.
void clearUpper()
Clear upper bound value.
Traits::CRef upper() const
Return the upper bound value.
void setBounds(typename Traits::CRef lower, typename Traits::CRef upper)
Set both bounds (lower and upper) at the same time.
static PVal new_(Type right)
some kind of "copy" constructor
int N
Definition: IOTest.py:90
const T & lower() const
Return the lower bound value.
static void assign(Type v1, CRef v2)
static void assign(Type v1, PRef v2)
void setLower(typename Traits::CRef value)
Set lower bound value.
static PVal new_()
some kind of "default" constructor
bool isValid(const typename Traits::CVal value) const
Check if the value is within bounds.
static bool less(CRef v1, CRef v2)
T lexicographical_compare(T...args)
const T & upper() const
Return the upper bound value.
static PVal copy(PVal *right, const bool own)
some kind of "smart"-pseudo-constructor
bool hasLower() const
Return if it has a lower bound.
void setUpper(const T &value)
Set upper bound value.
bool hasUpper() const
Return if it has a lower bound.
Gaudi::Utils::PropertyTypeTraits< T[N]> Traits
Type
the list of available types for ntuples
Definition: TupleObj.h:79
void setUpper(typename Traits::CRef value)
Set upper bound value.
Helper functions to set/get the application return code.
Definition: __init__.py:1
Traits::CRef lower() const
Return the lower bound value.
BoundedVerifier()
Constructors.
static bool less(CRef v1, Type v2)