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

CdbNTuple.hh

Go to the documentation of this file.
00001 #ifndef CDB_NTUPLE_HH
00002 #define CDB_NTUPLE_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbNTuple.hh,v 1.6 2004/04/02 07:41:27 gapon Exp $
00006 
00007 //#include "CdbBase/CdbItr.hh"
00008 #include "CdbBase/CdbCPtrBase.hh"
00009 
00010 #include "CdbTable/CdbNTupleBase.hh"
00011 
00012 // Forward declaration for the comparator interface used by the ::sort
00013 // method of the n-tuple.
00014 
00015 template < class T, unsigned int NCOL > class CdbNTupleIsLessComparator;
00016 
00017 /// An abstract base class for n-tuples.
00018 /**
00019   * This class provides a base interface of and common infrustructure for data
00020   * stored in this n-tuple facility.
00021   *
00022   * Specifically the roles of this class are:
00023   *
00024   * - It defines the base configuration of n-tuple, which includes a type of its
00025   *   elements and the width (the number of elements) of its rows.
00026   *
00027   * - It defines the behavior of n-tuple (finding elements, updating, replacing, etc.)
00028   *
00029   * - It provides metadata information about n-tuple through its base class CdbNTupleBase.
00030   *
00031   * Notes:
00032   *
00033   * - Since the width of n-tuple is specified through its template parameter
00034   *   then two n-tuples of the same element type but different width are NON-COMPATIBLE!!!
00035   *   That's a design decision to enforce proper use of n-tuples at compilation time.
00036   *
00037   * - The names of columns (either generated by default or explicitly passed to the corresponding
00038   *   constructor of n-tuple) can be used when doing queries on values of elements of the n-tuple.
00039   *
00040   * @see class CdbNTupleBase
00041   */
00042 template < class T, unsigned int NCOL >
00043 class CdbNTuple : public CdbNTupleBase {
00044 
00045 friend class CdbCPtrBase< CdbNTuple<T,NCOL> >;  // to destroy objects of this class
00046 
00047 public:
00048 
00049     typedef T element_type;
00050 
00051     enum { ncol = NCOL };
00052 
00053 protected:
00054 
00055   /// The default constructor
00056 
00057     CdbNTuple( );
00058 
00059   /// The constructor
00060   /**
00061     * The constructor will also assign default names to the columns. These names will be
00062     * derived from relative locations of the corresponding columns in a row. For example,
00063     * for an n-tuple of the width of 4 we would have:
00064     *
00065     *   "#0" "#1" "#2" "#3"
00066     */
00067     CdbNTuple( const std::string& theName,
00068                const std::string& theDescription );
00069 
00070   /// The constructor
00071   /**
00072     * This constructor can be used to specify the names of columns. The vector of names
00073     * passed as the first parameter can be of any length, where it would be shorter or longer
00074     * than the width of n-tuple.
00075     *
00076     * Notes:
00077     *
00078     * - Names passed in the vector must be unique. The default names assigned by the default
00079     *   descructor (see above) should not be used. A run-time assertion will happen in case
00080     *   of violation of this rule.
00081     *
00082     * - If the vector is shorter then elements of the vector will be used to name the first
00083     *   the rest of names will be filled with names derived from relative position of
00084     *   the corresponding column in a row. See the default constructor's description for details.
00085     *
00086     * - If the vector is longer - then the rest of the vector will be simply ignored.
00087     */
00088     CdbNTuple( const std::vector<std::string>& theCollumnNames,
00089                const std::string&              theName,
00090                const std::string&              theDescription );
00091 
00092   /// The copy constructor
00093   /**
00094     * Copy the local context.
00095     */
00096     CdbNTuple( const CdbNTuple<T,NCOL>& theOther );
00097 
00098   /// The assignment operator
00099   /**
00100     * Copy the local context.
00101     */
00102     CdbNTuple<T,NCOL>& operator=( const CdbNTuple<T,NCOL>& theOther );
00103 
00104 public:
00105 
00106   /// The destructor
00107   /**
00108     * Just to enforce the virtual destructor.
00109     */
00110     virtual ~CdbNTuple( );
00111 
00112   /// Make a ("deep") clone of a tuple
00113   /**
00114     * The method is defined here to cope with a hierarchy of possible
00115     * implementations of the current n-tuple interface.
00116     */
00117     virtual CdbNTuple<T,NCOL>* clone( ) const = 0;
00118 
00119   /// Get the current size (the number of rows) of n-tuple
00120 
00121     virtual unsigned int rows( ) const = 0;
00122 
00123   /// Resize the current size (the number of rows) of n-tuple
00124   /**
00125     * Notes:
00126     *
00127     * - if the new size is less than its current size then the rest of the n-tuple
00128     *   will be truncated and destructors for the removed elements will be called.
00129     *
00130     * - if the new size is more - then n-tuple will be extended and default constructors
00131     *   for new elements will be called.
00132     *
00133     * @return the completion status of the operation
00134     */
00135     virtual CdbStatus set_rows( unsigned int theNewSize ) = 0;
00136 
00137   /// Resize the current size (the number of rows) of n-tuple using a prototype
00138   /**
00139     * Unlike a previously defined method, this one would use a user defined value of
00140     * a prototype object to fill the new elements if new rows are to be created.
00141     */
00142     virtual CdbStatus set_rows( unsigned int theNewSize,
00143                                 const T&     thePrototype ) = 0;
00144 
00145   /// Append a new row
00146   /**
00147     * A vector passed as the parameter would extend n-tuple's size by one.
00148     *
00149     * Notes:
00150     *
00151     * - the vector is allowed to be less or greater than the width of n-tuple.
00152     *
00153     * - if the vector is shorter then the remaining elements will be padded
00154     *   using the new ones created using the default constructor of the current
00155     *   elements type.
00156     *
00157     * - if the vector is longer - the rest of the vector will be simply ignored.
00158     */
00159     virtual CdbStatus append_row( const std::vector<T>& theRow ) = 0;
00160 
00161   /// Insert a whole row of elements after the specified one
00162   /**
00163     * @return the method will CdbStatus::NotFound if the row does not exist.
00164     */
00165     virtual CdbStatus insert_row( const std::vector<T>& theRow,
00166                                   unsigned int          theRowNumber ) = 0;
00167 
00168   /// Replace a whole row of elements at specified position
00169   /**
00170     * @return the method will CdbStatus::NotFound if the row does not exist.
00171     */
00172     virtual CdbStatus replace_row( const std::vector<T>& theRow,
00173                                    unsigned int          theRowNumber ) = 0;
00174 
00175   /// Get a whole row of elements
00176 
00177     virtual CdbStatus get_row( std::vector<T>& theRow,
00178                                unsigned int    theRowNumber ) const = 0;
00179 
00180   /// Get a whole column by its number
00181 
00182     virtual CdbStatus get_column( std::vector<T>& theColumn,
00183                                   unsigned int    theColumnNumber ) const = 0;
00184 
00185   /// Get a whole column by its name
00186 
00187     virtual CdbStatus get_column( std::vector<T>&    theColumn,
00188                                   const std::string& theColumnName ) const = 0;
00189 
00190   /// Read an element (specify column by its number)
00191 
00192     virtual CdbStatus get_element( T&           theValue,
00193                                    unsigned int theRowNumber,
00194                                    unsigned int theColumnNumber ) const = 0;
00195 
00196   /// Read an element (specify column by its name)
00197 
00198     virtual CdbStatus get_element( T&                 theValue,
00199                                    unsigned int       theRowNumber,
00200                                    const std::string& theColumnName ) const = 0;
00201 
00202   /// Update a single an element (specify column by its number)
00203 
00204     virtual CdbStatus set_element( const T&     theValue,
00205                                    unsigned int theRowNumber,
00206                                    unsigned int theColumnNumber ) = 0;
00207 
00208   /// Update a single an element (specify column by its name)
00209 
00210     virtual CdbStatus set_element( const T&           theValue,
00211                                    unsigned int       theRowNumber,
00212                                    const std::string& theColumnName ) = 0;
00213 
00214 // TEMPORARY DISABLED DUE TO RTTI LINK PROBLEM ON SOLARIS
00215 //
00216 //  /// Find all rows whose elements at specified (by its number) column have this value
00217 //  /**
00218 //    * IMPORTANT NOTE: The current model of the iterator assumes that an n-tuple
00219 //    *                 in question stays immutable while the iterator is in use.
00220 //    *                 Otherwise the results may be unpredictable.
00221 //    */
00222 //    virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00223 //                                unsigned int          theColumnNumber,
00224 //                                const T&              theValue ) const = 0;
00225 //
00226 //  /// Find all rows whose elements at specified  (by its name) column have this value
00227 //  /**
00228 //    * See notes on the iterator in the previous method's description.
00229 //    */
00230 //    virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00231 //                                const std::string&    theColumnName,
00232 //                                const T&              theValue ) const = 0;
00233 
00234   /// Sort rows using specified comparator
00235   /**
00236     * @return the method will CdbStatus::Success in case of successfull completion.
00237     */
00238     virtual CdbStatus sort( const CdbNTupleIsLessComparator<T,NCOL>* theComparatorPtr ) = 0;
00239 };
00240 
00241 #ifdef     BABAR_COMP_INST
00242 #include "CdbTable/CdbNTuple.cc"
00243 #endif  // BABAR_COMP_INST
00244 
00245 #endif // CDB_NTUPLE_HH
00246 

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