Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbNTupleSimpleImpl.hh

Go to the documentation of this file.
00001 #ifndef CDB_NTUPLE_SIMPLE_IMPL_HH
00002 #define CDB_NTUPLE_SIMPLE_IMPL_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbNTupleSimpleImpl.hh,v 1.6 2005/07/26 00:13:41 gapon Exp $
00006 
00007 #include "CdbBase/CdbItr.hh"
00008 
00009 #include "CdbTable/CdbNTuple.hh"
00010 
00011 #include <vector>
00012 
00013 /// The simple implementation for an abstract n-tuple class.
00014 /**
00015   * This implementation stores n-tuple as an STL vector of rows.
00016   *
00017   * @see class CdbNTuple
00018   */
00019 template < class T,
00020            unsigned int NCOL >
00021 class CdbNTupleSimpleImpl : public CdbNTuple<T,NCOL> {
00022 
00023 friend class CdbNTupleFactory<T,NCOL>;  // to create objects of this class
00024 
00025 protected:
00026 
00027   /// The default constructor
00028   /**
00029     * @see CdbNTuple::CdbNTuple()
00030     */
00031     CdbNTupleSimpleImpl( );
00032 
00033   /// The constructor
00034   /**
00035     * @see CdbNTuple::CdbNTuple()
00036     */
00037     CdbNTupleSimpleImpl( const std::string& theName,
00038                          const std::string& theDescription );
00039 
00040   /// The constructor
00041   /**
00042     * @see CdbNTuple::CdbNTuple()
00043     */
00044     CdbNTupleSimpleImpl( const std::vector<std::string>& theCollumnNames,
00045                          const std::string&              theName,
00046                          const std::string&              theDescription );
00047 
00048   /// The copy constructor
00049   /**
00050     * Copy the local context.
00051     */
00052     CdbNTupleSimpleImpl( const CdbNTupleSimpleImpl<T,NCOL>& theOther );
00053 
00054   /// The assignment operator
00055   /**
00056     * Copy the local context.
00057     */
00058     CdbNTupleSimpleImpl<T,NCOL>& operator=( const CdbNTupleSimpleImpl<T,NCOL>& theOther );
00059 
00060   /// The destructor
00061   /**
00062     */
00063     virtual ~CdbNTupleSimpleImpl( );
00064 
00065 public:
00066 
00067   /// Make a ("deep") clone of a tuple
00068   /**
00069     * @see CdbNTuple::rows()
00070     */
00071     virtual CdbNTuple<T,NCOL>* clone( ) const;
00072 
00073   /// Get the current size (the number of rows) of n-tuple
00074   /**
00075     * @see CdbNTuple::rows()
00076     */
00077     virtual unsigned int rows( ) const;
00078 
00079   /// Resize the current size (the number of rows) of n-tuple
00080   /**
00081     * @see CdbNTuple::set_rows()
00082     */
00083     virtual CdbStatus set_rows( unsigned int theNewSize );
00084 
00085   /// Resize the current size (the number of rows) of n-tuple using a prototype
00086   /**
00087     * @see CdbNTuple::set_rows()
00088     */
00089     virtual CdbStatus set_rows( unsigned int theNewSize,
00090                                 const T&     thePrototype );
00091 
00092   /// Append a new row
00093   /**
00094     * @see CdbNTuple::append_row()
00095     */
00096     virtual CdbStatus append_row( const std::vector<T>& theRow );
00097 
00098   /// Insert a whole row of elements after the specified one
00099   /**
00100     * @see CdbNTuple::insert_row()
00101     */
00102     virtual CdbStatus insert_row( const std::vector<T>& theRow,
00103                                   unsigned int          theRowNumber );
00104 
00105   /// Replace a whole row of elements at specified position
00106   /**
00107     * @see CdbNTuple::replace_row()
00108     */
00109     virtual CdbStatus replace_row( const std::vector<T>& theRow,
00110                                    unsigned int          theRowNumber );
00111 
00112   /// Get a whole row of elements
00113   /**
00114     * @see CdbNTuple::get_row()
00115     */
00116     virtual CdbStatus get_row( std::vector<T>& theRow,
00117                                unsigned int    theRowNumber ) const;
00118 
00119   /// Get a whole column by its number
00120   /**
00121     * @see CdbNTuple::get_column()
00122     */
00123     virtual CdbStatus get_column( std::vector<T>& theColumn,
00124                                   unsigned int    theColumnNumber ) const;
00125 
00126   /// Get a whole column by its name
00127   /**
00128     * @see CdbNTuple::get_column()
00129     */
00130     virtual CdbStatus get_column( std::vector<T>&    theColumn,
00131                                   const std::string& theColumnName ) const;
00132 
00133   /// Read an element (specify column by its number)
00134   /**
00135     * @see CdbNTuple::get_element()
00136     */
00137     virtual CdbStatus get_element( T&           theValue,
00138                                    unsigned int theRowNumber,
00139                                    unsigned int theColumnNumber ) const;
00140 
00141   /// Read an element (specify column by its name)
00142   /**
00143     * @see CdbNTuple::get_element()
00144     */
00145     virtual CdbStatus get_element( T&                 theValue,
00146                                    unsigned int       theRowNumber,
00147                                    const std::string& theColumnName ) const;
00148 
00149   /// Update a single an element (specify column by its number)
00150   /**
00151     * @see CdbNTuple::set_element()
00152     */
00153     virtual CdbStatus set_element( const T&     theValue,
00154                                    unsigned int theRowNumber,
00155                                    unsigned int theColumnNumber );
00156 
00157   /// Update a single an element (specify column by its name)
00158   /**
00159     * @see CdbNTuple::set_element()
00160     */
00161     virtual CdbStatus set_element( const T&           theValue,
00162                                    unsigned int       theRowNumber,
00163                                    const std::string& theColumnName );
00164 
00165   /// Find all rows whose elements at specified (by its number) column have this value
00166   /**
00167     * @see CdbNTuple::find_row()
00168     */
00169     virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00170                                 unsigned int          theColumnNumber,
00171                                 const T&              theValue ) const;
00172 
00173   /// Find all rows whose elements at specified  (by its name) column have this value
00174   /**
00175     * @see CdbNTuple::find_row()
00176     */
00177     virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00178                                 const std::string&    theColumnName,
00179                                 const T&              theValue ) const;
00180 
00181   /// Sort rows using specified comparator
00182   /**
00183     * @see CdbNTuple::sort()
00184     */
00185     virtual CdbStatus sort( const CdbNTupleIsLessComparator<T,NCOL>* theComparatorPtr );
00186 
00187 public:
00188 
00189   /// The internal reprsentation of a raw in the n-tuple.
00190   /**
00191     * NOTE: This class is made public since it's used ouside the current template
00192     *       in the internal implementation of the "sort" method.
00193     */
00194     struct Row {
00195 
00196       // Constructors
00197 
00198         Row( )
00199         { };
00200 
00201         Row( const T& thePrototypeElement )
00202         {
00203             for( unsigned int i = 0; i < NCOL; ++i ) element[i] = thePrototypeElement;
00204         }
00205 
00206         Row( const std::vector<T>& theRow )
00207         {
00208             const unsigned int num = theRow.size( );
00209             const unsigned int num2copy = ( num < NCOL ? num : NCOL );
00210 
00211             for( unsigned int i = 0; i < num2copy; ++i ) element[i] = theRow[i];
00212         }
00213 
00214         Row( const std::vector<T>& theRow,
00215              const T&              thePrototypeElement )
00216         {
00217             const unsigned int num = theRow.size( );
00218             const unsigned int num2copy = ( num < NCOL ? num : NCOL );
00219 
00220             for( unsigned int i = 0;        i < num2copy; ++i ) element[i] = theRow[i];
00221             for( unsigned int i = num2copy; i < NCOL;     ++i ) element[i] = thePrototypeElement;
00222         }
00223 
00224         Row( const Row& theOther )
00225         {
00226             for( unsigned int i = 0; i < NCOL; ++i ) element[i] = theOther.element[i];
00227         }
00228 
00229       // Destructor
00230 
00231         ~Row( )
00232         { };
00233 
00234       // Operators
00235 
00236         Row& operator=( const Row& theOther )
00237         {
00238             if( &theOther != this )
00239                 for( unsigned int i = 0; i < NCOL; ++i ) element[i] = theOther.element[i];
00240 
00241             return *this;
00242         }
00243 
00244       // Methods
00245 
00246         void toVector( std::vector<T>& theRow ) const
00247         {
00248             theRow.clear( );
00249             for( unsigned int i = 0; i < NCOL; ++i ) theRow.push_back( element[i] );
00250         }
00251 
00252       // Data storage for elements
00253 
00254         T element[NCOL];
00255     };
00256 
00257 private:
00258 
00259   // The data storage for the n-tuple as a vector of rows
00260 
00261     std::vector< Row > _data;
00262 };
00263 
00264 #ifdef     BABAR_COMP_INST
00265 #include "CdbTable/CdbNTupleSimpleImpl.cc"
00266 #endif  // BABAR_COMP_INST
00267 
00268 #endif // CDB_NTUPLE_SIMPLE_IMPL_HH
00269 

Generated on Mon Dec 5 18:22:07 2005 for CDB by doxygen1.3-rc3