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

CdbBdbSTimeLineP.ddl

Go to the documentation of this file.
00001 #ifndef CDBBDBSHARED_TIMELINE_P_HH
00002 #define CDBBDBSHARED_TIMELINE_P_HH
00003 // File and Version Information:
00004 //      $Id: CdbBdbSTimeLineP.ddl,v 1.7 2004/08/06 05:54:25 bartoldu Exp $
00005 
00006 #include "BdbUtil/Bdb.hh"
00007 
00008 #include "CdbBase/CdbItr.hh"
00009 
00010 #include "CdbBdbShared/CdbBdbSTimeLineInterval.hh"
00011 #include "CdbBdbShared/CdbBdbSTimeLineNode.hh"
00012 #include "CdbBdbShared/CdbBdbSPagedVarrayP.hh"
00013 #include "CdbBdbShared/CdbBdbSBtreeP_InterVal_ULong.hh"
00014 
00015 #include "BdbTime/BdbTime.hh"
00016 
00017 /// Persistent TimeLine class.
00018 /**
00019   * This is a persistent implementation for the timeline of intervals.
00020   */
00021 template< class V >
00022 class CdbBdbSTimeLineP : public BdbPersObj {
00023 
00024 private:
00025 
00026     typedef CdbBdbSTimeLineNode< V > Node;
00027 
00028     typedef CdbBdbSInterValBte   BTreeEntry;
00029     typedef CdbBdbSInterValBtFCP BTreeEntryFCP;
00030 
00031 public:
00032 
00033   /// Type definitions for the TimeLine's iterators
00034   /**
00035     * These types are being introduced here to facilitate more flexible
00036     * type parametrisation of the class's clients (including its
00037     * direct and indirect subclasses).
00038     */
00039     typedef CdbItr< CdbBdbSTimeLineInterval<V> > IteratorOfIntervals;
00040 
00041 public:
00042 
00043   /// Default constructor
00044   /**
00045     * The timeline will be initialized with the value constructed according
00046     * the default constriuctor of the corresponding class.
00047     */
00048     CdbBdbSTimeLineP( );
00049 
00050   /// Normal constructor
00051   /**
00052     * This form of the constructor lets a client to specify the initial value
00053     * to be put into the timeline. This value will be covering the whole timeline
00054     * from the -Infinity to +Infinity.
00055     */
00056     CdbBdbSTimeLineP( const V& theInitialValue );
00057 
00058   // Destructor
00059 
00060     virtual ~CdbBdbSTimeLineP( );
00061 
00062   /// Insert an interval into the collection
00063   /**
00064     * This method will "cut in" the specified interval.
00065     */
00066     CdbStatus insert( const BdbTime& theBeginTime,  /**< the begin time of the interval */
00067                       const BdbTime& theEndTime,    /**< the end   time of the interval */
00068                       const V&       theValue       /**< the value associated with this interval */
00069                     );
00070 
00071   /// Insert an interval into the collection
00072   /**
00073     * This method will "cut in" the specified interval.
00074     */
00075     CdbStatus insert( const CdbBdbSTimeLineInterval<V>& theInterval     /**< the interval to insert */
00076                     );
00077 
00078   /// Find an interval in the TimeLine
00079   /**
00080     * This method will only return "true" if specified time macthes to
00081     * the begin time of an interval in the TimeLine.
00082     */
00083     bool findAtBegin( CdbBdbSTimeLineInterval<V>& theInterval,
00084                       const BdbTime&              theTime ) const;
00085 
00086   /// Find an interval in the TimeLine
00087   /**
00088     * This method if successfull (returned value is TRUE) will return the information
00089     * about the interval where the specified time falls into.
00090     */
00091     bool find( CdbBdbSTimeLineInterval<V>& theInterval,
00092                const BdbTime&              theTime ) const;
00093 
00094   /// Get the first interval in the TimeLine
00095   /**
00096     * Return CdbStatus::NotFound if there is no intervals in the collection.
00097     */
00098     CdbStatus first( CdbBdbSTimeLineInterval<V>& theInterval            /**< the value of the interval to be returned */
00099                    ) const;
00100 
00101   /// Get the last interval in the TimeLine
00102   /**
00103     * Return CdbStatus::NotFound if there is no intervals in the collection.
00104     */
00105     CdbStatus last( CdbBdbSTimeLineInterval<V>& theInterval             /**< the value of the interval to be returned */
00106                   ) const;
00107 
00108   /// Get an instance of an iterator for intervals
00109   /**
00110     * The intervals delivered via this iterator are sorted in
00111     * the TimeLIne dimension. The first interval in the list will include the specified
00112     * begin time.
00113     */
00114     IteratorOfIntervals iterator( const BdbTime& theBeginTime = BdbTime::minusInfinity ) const;
00115 
00116   /// Dump the contents of the collection
00117   /**
00118     * The range of the dumped interval is controlled by mean of two
00119     * optional parameters.
00120     */
00121     void dump( std::ostream&       o,                                        /**< the output stream */
00122                const BdbTime& theBeginTime = BdbTime::minusInfinity,    /**< the begin time of the interval */
00123                const BdbTime& theEndTime   = BdbTime::plusInfinity      /**< the end   time of the interval */
00124              );
00125 
00126   /// Clone the timeline object
00127   /**
00128     * An exact copy of the current object will be created
00129     * at specified location. If the default value for the hint is chosen
00130     * then an objects will be created next to the current one.
00131     *
00132     * This operation may return a error status in case of problems
00133     * during the cloning (memory management) or any inconsistency at the
00134     * internal structure of the current object.
00135     */
00136     CdbStatus clone( BdbRef(CdbBdbSTimeLineP<V>)& theRef,           /**< the reference onto created clone */
00137                      const BdbRefAny&             theHint = 0       /**< the location of the clone */
00138                    ) const;
00139 
00140 private:
00141 
00142   /// Initialize the timeline
00143   /**
00144     * The timeline will be initialized with one interval covering the whole
00145     * timeline and carrying specified value.
00146     */
00147     void initialize( const V& theInitialValue );
00148 
00149   /// Remove specified visible interval and insert a new one
00150   /**
00151     * This method installs a new "visible" instead of the specified one.
00152     */
00153     void insertAndRemoveOne( d_ULong        begin,          /**< the interval to be removed */
00154                              const BdbTime& beginTime,      /**< the begin time of the new interval */
00155                              const BdbTime& endTime,        /**< the end   time of the new interval */
00156                              const V&       value           /**< the value to be set up */
00157                            );
00158 
00159   /// Remove a range of visible intervals and insert a new one
00160   /**
00161     * This method installs a new "visible" instead of a sequence of specofied ones.
00162     * The sequence is defined by the first and last interval, and includes any intervals
00163     * in between.
00164     */
00165     void insertAndRemoveMany( d_ULong        begin,         /**< the first interval to be removed */
00166                               d_ULong        end,           /**< the last  interval to be removed */
00167                               const BdbTime& beginTime,     /**< the begin time of the new interval */
00168                               const BdbTime& endTime,       /**< the end   time of the new interval */
00169                               const V&       value          /**< the value to be set up */
00170                             );
00171 
00172   /// Allocator
00173   /**
00174     * Allocate an element from a list of free ones. The method will return
00175     * an index of the allocated element.
00176     */
00177     d_ULong allocate( d_ULong next = 0 );
00178 
00179   /// Disposer
00180   /**
00181     * Return specified element back to the list of free ones.
00182     */
00183     void release( d_ULong element );
00184 
00185   /// Extend a list of free elements
00186   /**
00187     * This list is only extended if it's empty.
00188     */
00189     void extend_free_list( );
00190 
00191 private:
00192 
00193   /// B-tree index of timeline intervals
00194   /**
00195     * This index is updated coherently with the list of intervals
00196     * defined below. Remember, that elements of this index are objects of
00197     * the above defined "B-tree Entry" class, each having the corresponding link
00198     * as an index in a paged v-array defined below) back to the interval.
00199     */
00200     Bdb2Ref( CdbBdbSBtreeP< BTreeEntry, BTreeEntryFCP > ) _indexRef;
00201 
00202   /// The actual storage for timeline intervals
00203   /**
00204     * The first element of the array (index = 0) is not used, because
00205     * this number is meant to simulate "null pointer".
00206     *
00207     * Initially spare elements begin from the index = 1.
00208     * This will also change as the tree will expand.
00209     */
00210     BdbRef( CdbBdbSPagedVarrayP< Node > ) _bufRef;
00211 
00212   /// An index of the first & last elements of the list
00213 
00214     d_ULong _first;
00215     d_ULong _last;
00216 
00217   /// An indx of the first spare element
00218   /**
00219     * These nodes form a linked list. So the first spare element is actually
00220     * the head of the list.
00221     */
00222     d_ULong _free;
00223 };
00224 
00225 /// Macros for the xplicit template instantiation.
00226 /**
00227   * The macro will provide all the nessesary declarations for specified
00228   * type of elements (first paremeter). It will also introduce new type
00229   * as required by the second parameter.
00230   */
00231 #define EXPLICIT_INSTANTIATE_CdbBdbSTimeLineP_1( V ) \
00232 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( CdbBdbSTimeLineNode< V > ); \
00233 template class CdbBdbSTimeLineP< V >
00234 
00235 // Template class implementation
00236 
00237 #ifdef    BABAR_COMP_INST
00238 #include "CdbBdbShared/CdbBdbSTimeLineP.cc"
00239 #endif /* BABAR_COMP_INST */
00240 
00241 #endif /* CDBBDBSHARED_TIMELINE_P_HH */

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