All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // ============================================================================
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>
114 {
115  // ==========================================================================
117  // Abstract derived class
118  // ==========================================================================
119 public:
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  // ==========================================================================
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 // ============================================================================
static void dele(PVal right, const bool own)
"smart" pseudo-destructor
Templated Verifier base class.
helper structure to define the types for properties
static bool less(Type v1, CRef v2)
bool m_hasLowerBound
Data and Function Members for This Class Implementation.
void clearBounds()
Clear both bounds (lower and upper) at the same time.
void clearLower()
Clear lower bound value.
static bool less(Type v1, Type v2)
comparison (needed for bounded verifier)
void clearUpper()
Clear upper bound value.
void clearLower()
Clear lower bound value.
Traits::CRef upper() const
Return the upper bound value.
const T & lower() const
Return the lower bound value.
virtual ~BoundedVerifier()
Destructor.
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
static void assign(Type v1, CRef v2)
void setUpper(const T &value)
Set upper bound value.
static void assign(Type v1, PRef v2)
const T & upper() const
Return the upper bound value.
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)
static PVal copy(PVal *right, const bool own)
some kind of "smart"-pseudo-constructor
bool hasLower() const
Return if it has a lower bound.
bool m_hasLowerBound
Data and Function Members for This Class Implementation.
bool hasUpper() const
Return if it has a lower bound.
void setLower(const T &value)
Set lower bound value.
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
Gaudi::Utils::PropertyTypeTraits< T[N]> Traits
Type
the list of available types for ntuples
Definition: TupleObj.h:63
void setUpper(typename Traits::CRef value)
Set upper bound value.
void clearUpper()
Clear upper bound value.
Traits::CRef lower() const
Return the lower bound value.
BoundedVerifier()
Constructors.
static bool less(CRef v1, Type v2)