ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataCont/interface/Vector.h
Revision: 1.1
Committed: Tue Jul 29 10:36:21 2008 UTC (16 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: MITHEP_2_0_x
Log Message:
Added submodule for containers only

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2     // $Id: Vector.h,v 1.14 2008/07/14 20:55:19 loizides Exp $
3     //
4     // Vector
5     //
6     // Implementation of Collection interface using std:vector class.
7     //
8     // Note, in case you one to store pointers to allocated objects on heap,
9     // you should use the class PVector.
10     //
11     // Authors: C.Loizides
12     //--------------------------------------------------------------------------------------------------
13    
14     #ifndef DATATREE_VECTOR_H
15     #define DATATREE_VECTOR_H
16    
17     #include <vector>
18     #include <Rtypes.h>
19     #include "MitAna/DataCont/interface/Collection.h"
20    
21     namespace mithep
22     {
23     template<class ArrayElement>
24     class Vector : public Collection<ArrayElement>
25     {
26     public:
27     Vector(UInt_t rsv=0) : fV(0) { fV.reserve(rsv); }
28     Vector(std::vector<ArrayElement> &v) : fV(v) {}
29     ~Vector() {}
30    
31     void AddCopy(const ArrayElement &ae) { fV.push_back(ae); }
32     void AddCopy(const ArrayElement *ae) { fV.push_back(*ae); }
33     ArrayElement *At(UInt_t idx) { return &fV.at(idx); }
34     const ArrayElement *At(UInt_t idx) const { return &fV.at(idx); }
35     void Clear(Option_t *opt="");
36     UInt_t Entries() const { return fV.size(); }
37     UInt_t GetEntries() const { return fV.size(); }
38     Bool_t IsOwner() const { return kTRUE; }
39     ArrayElement &Ref(UInt_t idx) { return fV.at(idx); }
40     const ArrayElement &Ref(UInt_t idx) const { return fV.at(idx); }
41     void Reset() { fV.clear(); }
42     void Trim();
43     ArrayElement *UncheckedAt(UInt_t idx) { return &fV[idx]; }
44     const ArrayElement *UncheckedAt(UInt_t idx) const { return &fV[idx]; }
45     const std::vector<ArrayElement> &Vect() const { return fV; }
46     std::vector<ArrayElement> &Vect() { return fV; }
47    
48     ArrayElement *operator[](UInt_t idx) { return &fV.at(idx); }
49     const ArrayElement *operator[](UInt_t idx) const { return &fV.at(idx); }
50    
51     protected:
52     std::vector<ArrayElement> fV; //std::vector
53    
54     private:
55     Vector(const Vector &v);
56    
57     ClassDefT(Vector, 1) // Wrapper around std::vector class
58     };
59     }
60    
61     //--------------------------------------------------------------------------------------------------
62     template<class ArrayElement>
63     inline void mithep::Vector<ArrayElement>::Clear(Option_t */*opt*/)
64     {
65     // Destruct container.
66    
67     using namespace std;
68     fV.~vector<ArrayElement>();
69     }
70    
71     //--------------------------------------------------------------------------------------------------
72     template<class ArrayElement>
73     inline void mithep::Vector<ArrayElement>::Trim()
74     {
75     // Trim vector to minimal needed size.
76    
77     std::vector<ArrayElement>(fV).swap(fV);
78     }
79     #endif