Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

CArrayAsProperty.h

Go to the documentation of this file.
00001 // $Id: $
00002 // ============================================================================
00003 #ifndef GAUDIKERNEL_CARRAYASPROPERTY_H 
00004 #define GAUDIKERNEL_CARRAYASPROPERTY_H 1
00005 // ============================================================================
00006 // Include files
00007 // ============================================================================
00008 // STD & STL 
00009 // ============================================================================
00010 #include <algorithm>
00011 // ============================================================================
00012 // GauidKernel
00013 // ============================================================================
00014 #include "GaudiKernel/PropertyTypeTraits.h"
00015 #include "GaudiKernel/PropertyVerifier.h"
00016 // ============================================================================
00032 // ============================================================================
00033 // 1) Streamers : value  -> string , done in GausiKernel/ToStream.h
00034 // ============================================================================
00035 // 2) Parsers   : string -> value  , done in GaudiKernel/Parsers.h
00036 // ============================================================================
00037 // 3) assigements and copy 
00038 // ============================================================================
00039 namespace Gaudi
00040 {
00041   // ==========================================================================
00042   namespace Utils 
00043   {
00044     // ========================================================================
00045     template <class T, unsigned int N>
00046     struct PropertyTypeTraits<T(&)[N]>
00047     {
00048       // ======================================================================
00049       typedef       T(&Type) [N] ;
00050       typedef       T(&PRef) [N] ;
00051       typedef       T(*PVal) [N] ;
00052       typedef const T(&CRef) [N] ;
00053       typedef const T(*CVal) [N] ;
00054       // ======================================================================
00055     public:
00056       // ======================================================================
00058       static PVal new_ () { return new T[N] ; }
00060       static PVal new_ ( Type right )
00061         { 
00062           PVal tmp = new_ () ;
00063           assign ( tmp , right ) ;
00064           return tmp ;
00065         }
00067       static PVal copy ( PVal* right , const bool  own ) 
00068         {
00069           if ( !own ) { return right ; }
00070           return new_ ( *right ) ;
00071         }
00073       static void dele   ( PVal right , const bool own ) 
00074         { if ( own ) { delete[] right ; } }
00075       // ======================================================================
00076       // assigenements 
00077       static void assign ( Type v1 , PRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
00078       static void assign ( Type v1 , CRef v2 ) { std::copy ( v2 , v2 + N , v1 ) ; }
00080       static bool less   ( Type v1 , Type v2 )  
00081         { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
00082       static bool less   ( Type v1 , CRef v2 )  
00083         { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
00084       static bool less   ( CRef v1 , CRef v2 )  
00085         { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
00086       static bool less   ( CRef v1 , Type v2 )  
00087         { return std::lexicographical_compare ( v1 , v1 + N , v2 , v2 + N ) ; }
00088       // ======================================================================
00089     } ;
00090     // ========================================================================
00092     template <class T, unsigned int N>
00093     struct PropertyTypeTraits<T[N]> : public PropertyTypeTraits<T(&)[N]>
00094     {} ;
00095     // ========================================================================
00097     template <class T, unsigned int N>
00098     struct PropertyTypeTraits< const T(&)[N]> 
00099     {} ;
00101     template <unsigned int N>
00102     struct PropertyTypeTraits<char(&)[N]> 
00103     {} ;    
00104     // ========================================================================
00105   } //                                            end of namespace Gaudi::Utils 
00106   // ==========================================================================
00107 } //                                                     end of namespace Gaudi
00108 // ============================================================================
00109 // property verifier 
00110 // ============================================================================
00112 template< class T, unsigned int N>
00113 class BoundedVerifier<T[N]> : PropertyVerifier<T[N]> 
00114 {    
00115   // ==========================================================================
00116   typedef Gaudi::Utils::PropertyTypeTraits<T[N]>  Traits ;
00117   // Abstract derived class
00118   // ==========================================================================
00119 public:
00121   BoundedVerifier() 
00122     : m_hasLowerBound ( false )
00123     , m_hasUpperBound ( false )
00124   {}
00126   virtual ~BoundedVerifier() { }
00127   
00129   bool isValid ( const typename Traits::CVal value ) const 
00130   { 
00131     return   
00132       ( ( m_hasLowerBound && Traits::less ( *value , m_lowerBound ) ) ? false : true ) 
00133       &&
00134       ( ( m_hasUpperBound && Traits::less ( m_upperBound , *value ) ) ? false : true ) ;
00135   }
00137   bool        hasLower() const { return m_hasLowerBound; }
00139   bool        hasUpper() const { return m_hasUpperBound; }
00141   typename Traits::CRef lower()    const { return m_lowerBound; }
00143   typename Traits::CRef upper()    const { return m_upperBound; }
00144   
00146   void setLower( typename Traits::CRef value ) { m_hasLowerBound = true; Traits::assign ( m_lowerBound , value ) ; }
00148   void setUpper( typename Traits::CRef value ) { m_hasUpperBound = true; Traits::assign ( m_upperBound , value ) ; }
00150   void clearLower()  { m_hasLowerBound = false; }
00152   void clearUpper()  { m_hasUpperBound = false; }
00153   
00155   void setBounds( typename Traits::CRef lower, typename Traits::CRef upper) 
00156     {
00157       setLower( lower ); 
00158       setUpper( upper ); 
00159   }
00160   
00162   void clearBounds() 
00163     {
00164       clearLower(); 
00165       clearUpper(); 
00166     }
00167   
00168  private:
00169   // ==========================================================================
00172   bool    m_hasLowerBound  ;
00173   bool    m_hasUpperBound  ;
00174   const T m_lowerBound [N] ;
00175   const T m_upperBound [N] ;
00176   // ==========================================================================
00177 };
00178 // ============================================================================
00179 // The END
00180 // ============================================================================
00181 #endif // GAUDIKERNEL_CARRAYASPROPERTY_H
00182 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:19 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004