CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/CondCore/ORA/interface/PVector.h

Go to the documentation of this file.
00001 #ifndef INCLUDE_ORA_PVECTOR_H
00002 #define INCLUDE_ORA_PVECTOR_H
00003 
00004 //
00005 #include <vector>
00006 
00007 namespace ora {
00008 
00009 
00017   template <typename Tp> class PVector 
00018   {
00019 
00020     public:
00021 
00022     // typedefs forwarded to std::vector
00023     typedef typename std::vector<Tp>::size_type size_type;
00024 
00025     typedef typename std::vector<Tp>::const_reference const_reference;
00026 
00027     typedef typename std::vector<Tp>::reference reference;
00028 
00029     typedef typename std::vector<Tp>::const_iterator const_iterator;
00030 
00031     typedef typename std::vector<Tp>::iterator iterator;
00032 
00033     typedef typename std::vector<Tp>::const_reverse_iterator const_reverse_iterator;
00034 
00035     typedef typename std::vector<Tp>::reverse_iterator reverse_iterator;
00036 
00037     typedef typename std::vector<Tp>::value_type value_type;
00038 
00039     // ora specific typedef
00040     typedef typename std::vector<Tp> store_type;
00041 
00042     public:
00043 
00044     // default constructor
00045     PVector();
00046 
00047     // constructor
00048     explicit PVector(size_type n, const Tp& value=Tp());
00049 
00050     // copy constructor
00051     PVector(const PVector<Tp>&);
00052 
00053     // destructor
00054     virtual ~PVector(){
00055     }
00056 
00057     // assignment operator
00058     PVector<Tp>& operator=(const PVector<Tp>&);
00059 
00060     public:
00061     // methods forwarded to std::vector
00062     iterator begin()
00063     {
00064       return m_vec.begin();
00065     }
00066 
00067     iterator end()
00068     {
00069       return m_vec.end();
00070     }
00071 
00072     const_iterator begin() const 
00073     {
00074       return m_vec.begin();
00075     }
00076 
00077     const_iterator end() const 
00078     {
00079       return m_vec.end();
00080     }
00081 
00082     reverse_iterator rbegin()
00083     {
00084       return m_vec.rbegin();
00085     }
00086 
00087     reverse_iterator rend()
00088     {
00089       return m_vec.rend();
00090     }
00091 
00092     const_reverse_iterator rbegin() const 
00093     {
00094       return m_vec.rbegin();
00095     }
00096 
00097     const_reverse_iterator rend() const 
00098     {
00099       return m_vec.rend();
00100     }
00101 
00102     size_type size() const 
00103     {
00104       return m_vec.size();
00105     }
00106 
00107     size_type max_size() const 
00108     {
00109       return m_vec.max_size();
00110     }
00111 
00112     void resize(size_type n, const Tp& value=Tp())
00113     {
00114       m_vec.resize(n,value);
00115     }
00116 
00117     size_type capacity() const 
00118     {
00119       return m_vec.capacity();
00120     }
00121 
00122     bool empty() const 
00123     {
00124       return m_vec.empty();
00125     }
00126 
00127     void reserve(size_type n) 
00128     {
00129       m_vec.reserve(n);
00130     }
00131 
00132     reference operator[] ( size_type n ) 
00133     {
00134       return m_vec[n];
00135     }
00136 
00137     const_reference operator[] ( size_type n ) const 
00138     {
00139       return m_vec[n];
00140     }
00141 
00142     const_reference at( size_type n ) const 
00143     {
00144       return m_vec.at(n);
00145     }
00146 
00147     reference at( size_type n ) 
00148     {
00149       return m_vec.at(n);
00150     }
00151 
00152     reference front ( ) 
00153     {
00154       return m_vec.front();
00155     }
00156 
00157     const_reference front ( ) const 
00158     {
00159       return m_vec.front();
00160     }
00161 
00162     reference back ( ) 
00163     {
00164       return m_vec.back();
00165     }
00166 
00167     const_reference back ( ) const 
00168     {
00169       return m_vec.back();
00170     }
00171 
00172     void assign ( size_type n, const Tp& u ) 
00173     {
00174       m_vec.assign(n,u);
00175     }
00176 
00177     void push_back ( const Tp& x ) 
00178     {
00179       m_vec.push_back(x);
00180     }
00181 
00182     void pop_back () 
00183     {
00184       m_vec.pop_back();
00185     }
00186 
00187     void clear ( )
00188     {
00189       m_vec.clear();
00190     }
00191 
00192     // equals operator
00193     bool operator==(const PVector& vec) const 
00194     {
00195       return m_vec==vec.m_vec;
00196     }
00197 
00198     bool operator!=(const PVector& vec) const 
00199     {
00200       return m_vec!=vec.m_vec;
00201     }
00202 
00203     // ORA specific methods
00204     public:
00205 
00206     const void* storageAddress() const 
00207     {
00208       return &m_vec;
00209     }
00210 
00211     // access to persistent size
00212     size_type persistentSize() const 
00213     {
00214       return m_persistentSize;
00215     }
00216 
00217     // ORA specific attributes
00218     private:
00219 
00220     // private std::vector instance
00221     std::vector<Tp> m_vec;
00222 
00223     // persistent size
00224     size_type m_persistentSize;
00225     
00226   };
00227 }
00228 
00229 
00230 template <class Tp> ora::PVector<Tp>::PVector():m_vec(),m_persistentSize(0){
00231 }
00232 
00233 template <class Tp> ora::PVector<Tp>::PVector(size_type n, const Tp& value):m_vec(n,value),m_persistentSize(0){
00234 }
00235 
00236 template <class Tp> ora::PVector<Tp>::PVector(const PVector<Tp>& v):m_vec(v.m_vec),m_persistentSize(v.m_persistentSize){
00237 }
00238 
00239 template <class Tp> ora::PVector<Tp>& ora::PVector<Tp>::operator=(const PVector<Tp>& v){
00240 
00241   m_vec = v.m_vec;
00242   m_persistentSize = v.m_persistentSize;
00243   return *this;
00244 }
00245 
00246 #endif  
00247