Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

BoostArrayAsProperty.h

Go to the documentation of this file.
00001 // $Id: $
00002 // ============================================================================
00003 #ifndef GAUDIKERNEL_BOOSTARRAYASPROPERTY_H 
00004 #define GAUDIKERNEL_BOOSTARRAYASPROPERTY_H 1
00005 // ============================================================================
00006 // Include files
00007 // ============================================================================
00008 // STD & STL 
00009 // ============================================================================
00010 #include <algorithm>
00011 // ============================================================================
00012 // Boost 
00013 // ============================================================================
00014 #include "boost/array.hpp"
00015 // ============================================================================
00025 // ============================================================================
00026 // 1) Streamers : value -> string 
00027 // ============================================================================
00028 namespace Gaudi
00029 {
00030   // ==========================================================================
00031   namespace Utils
00032   {
00033     // ========================================================================
00034     template <class ITERATOR>
00035     inline std::ostream& toStream 
00036     ( ITERATOR           first ,                       // begin of the sequence 
00037       ITERATOR           last  ,                       //   end of the sequence 
00038       std::ostream&      s     ,                       //            the stream 
00039       const std::string& open  ,                       //               opening 
00040       const std::string& close ,                       //               closing 
00041       const std::string& delim ) ;                     //             delimiter
00042     // ========================================================================
00051     template <class TYPE, std::size_t N>
00052     inline std::ostream& toStream 
00053     ( const boost::array<TYPE,N>& obj , std::ostream& s ) 
00054     {
00055       return toStream 
00056         ( obj.begin () , obj.end   () , s , "( "  , " )"   , " , "  ) ;
00057     }
00058     // ========================================================================
00059   } //                                            end of namespace Gaudi::Utils 
00060   // ==========================================================================
00061 } //                                                     end of namespace Gaudi 
00062 // ============================================================================
00063 // 2) Parsers: string -> value 
00064 // ============================================================================
00065 // GaudiKernel
00066 // ============================================================================
00067 #include "GaudiKernel/Parsers.h"
00068 // ============================================================================
00069 namespace Gaudi
00070 {
00071   // ==========================================================================
00072   namespace Parsers 
00073   {
00074     // ========================================================================
00082     template <class TYPE, std::size_t N>
00083     StatusCode 
00084     parse ( boost::array<TYPE,N>& result , const std::string& input ) 
00085     {
00086       typedef std::vector<TYPE> _Vct ;
00087       // create the temporaty vector
00088       _Vct tmp ; 
00089       // parse the string 
00090       StatusCode sc = parse ( tmp , input ) ; 
00091       if ( sc.isFailure () ) { return sc ; }                         // RETURN 
00092       if ( N != tmp.size() ) 
00093       { return StatusCode ( StatusCode::FAILURE , true ) ; }         // RETURN   
00094       // copy vector into array 
00095       std::copy ( tmp.begin() , tmp.end() , result.begin() ) ;
00096       //
00097       return StatusCode::SUCCESS ;
00098     }
00099     // ========================================================================
00100   } //                                          end of namespace Gaudi::Parsers 
00101   // ==========================================================================
00102 } //                                                     end of namespace Gaudi
00103 // ============================================================================
00104 // 3) Assignements and constructors 
00105 // ============================================================================
00106 // GaudiKernel
00107 // ============================================================================
00108 #include "GaudiKernel/PropertyTypeTraits.h"
00109 // ============================================================================
00110 namespace Gaudi 
00111 {
00112   // ==========================================================================
00113   namespace Utils 
00114   {
00115     // ========================================================================
00122     template <class T, std::size_t N>
00123     struct PropertyTypeTraits<boost::array<T,N> >
00124     {
00125       // =======================================================================     
00126       typedef boost::array<T,N> TYPE ;
00127       typedef TYPE        Type  ;
00128       typedef const TYPE& PRef  ;
00129       typedef TYPE*       PVal  ;
00130       typedef const TYPE* CVal  ;
00131       // =======================================================================     
00133       static PVal new_ () 
00134       {
00135         PVal tmp = new Type ;
00136         std::fill_n ( tmp->begin() , N , T() ) ;
00137         return tmp ; 
00138       }
00140       static PVal new_ ( const Type& right ) 
00141       { 
00142         PVal tmp = new Type   ;
00143         assign ( *tmp , right ) ;
00144         return tmp ;
00145       }
00147       static void dele   ( PVal right , const bool own ) 
00148       { if ( own ) { delete right ; } }
00150       static PVal copy   ( PVal right , const bool  own ) 
00151       {
00152         if ( !own ) { return right ; }
00153         return new_ ( *right ) ;
00154       }   
00156       static void assign ( Type& v1 , const Type& v2 ) 
00157       { std::copy ( v2.begin() , v2.end() , v1.begin() ) ; }
00159       static bool less ( const Type& v1 , const Type& v2 )  
00160       { return std::lexicographical_compare 
00161           ( v1.begin() , v1.end () , v2.begin()  , v2.end() ) ; }
00162       // ======================================================================     
00163     } ;    
00164     // ========================================================================
00165   } //                                            end of namespace Gaudi::Utils 
00166   // ==========================================================================
00167 } //                                                     end of namespace Gaudi 
00168 // ============================================================================
00169 // The END 
00170 // ============================================================================
00171 #endif // GAUDIKERNEL_BOOSTARRAYASPROPERTY_H
00172 // ============================================================================
 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