StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StArray.h
1 #ifndef _StRegistry_
2 #define _StRegistry_
3 
4 
6 // //
7 // //
8 // //
10 
11 #include <assert.h>
12 #include "TString.h"
13 #include "TObject.h"
14 #include "StObject.h"
15 //#ifndef __CINT__
16 class TObject;
17 #include <vector>
18 #include <algorithm>
19  using std::vector;
20  using std::random_shuffle;
21  typedef vector<TObject*> VecTObj;
22 #ifndef __CINT__
23  typedef vector<TObject*>::iterator VecTObjIter;
24  typedef vector<TObject*>::const_iterator const_VecTObjIter;
25  typedef VecTObjIter StObjArrayIter;
26  typedef VecTObjIter StStrArrayIter;
27  typedef VecTObjIter StRefArrayIter;
28  typedef const_VecTObjIter const_StObjArrayIter;
29  typedef const_VecTObjIter const_StStrArrayIter;
30  typedef const_VecTObjIter const_StRefArrayIter;
31 #endif
33 #ifdef __CINT__NEVER
34  class VecTObj;
35  class VecTObjIter;
36  class const_VecTObjIter;
37  class StObjArrayIter;
38  class StStrArrayIter;
39  class StRefArrayIter;
40  class const_StObjArrayIter;
41  class const_StStrArrayIter;
42  class const_StRefArrayIter;
43 #endif /*__CINT__*/
44 
45 class StObjLink : public TObject
46 {
47 public:
48  StObjLink(const StObject *p=0) {fLink=(StObject*)p;}
49  StObjLink(const StObjLink &from):TObject() {fLink=(StObject*)from.fLink;}
50  ~StObjLink() {fLink=0;}
51 
52  StObjLink &operator=(StObjLink &from){fLink=from.fLink;return *this;}
53  StObjLink &operator=(StObject *obj) {fLink=obj; return *this;}
54  StObject &operator*() {return *fLink;}
55  StObject *operator->() {return fLink;}
56 // operator StObject *&() {return fLink;}
57 // operator const StObject *() const {return fLink;}
58  StObject* get() {return fLink;}
59 virtual Bool_t IsFolder() const {return 1;}
60 virtual void Browse(TBrowser* b);
61 // void Streamer(TBuffer &buf);
62 
63  StObject *fLink;
64  ClassDef(StObjLink,1)
65 };
66 
67 template<class T>
68  class StLink : public StObjLink {
69 public:
70  typedef T element_type;
71  StLink(T *p = 0):StObjLink(p){};
72  StLink<T> &operator=(T *obj) {fLink=obj; return *this;}
73  StLink<T> &operator=(const StLink<T> &fr) {fLink=(StObject*)fr.fLink; return *this;}
74  T &operator*() {return *((T*)fLink);}
75  T *operator->() {return (T*)fLink; }
76  const T *operator->() const {return (const T*)fLink; }
77  operator const T *() const{return (const T*)fLink; }
78  operator T *&() {return ( T*&)fLink; }
79 };
80 
81 
82 class StObjArray;
83 class StStrArray;
84 class StRefArray;
85 
86 
87 class StObjArray : public StObject {
88 public:
89  StObjArray(Int_t sz=0){if(sz) resize(sz);}
90  virtual ~StObjArray(){}
91 virtual void Browse(TBrowser *b);
92  void random_shuffle(int start=0,int end=0x7fffffff);
93  size_t capacity() const {return fV.capacity();}
94  size_t max_size() const {return fV.max_size();}
95  void clear() {fV.clear() ;}
96  void pop_back() {fV.pop_back() ;}
97  int empty() const {return fV.empty() ;}
98  size_t size () const {return fV.size() ;}
99  void reserve(size_t sz) {fV.reserve(sz) ;}
100  void resize(size_t sz,TObject *v=0) {fV.resize(sz,v);}
101 virtual Bool_t IsFolder() const;
102  TObject * &at(int i) {return fV[i];}
103  void put_at(TObject *obj,int i){fV[i]=obj;}
104 
105  TObject * const &front() const { return fV.front();}
106  TObject * &front() { return fV.front();}
107 
108  TObject * const &back() const { return fV.back();}
109  TObject * &back() { return fV.back();}
110  TObject * find(const char *name) const;
111 
112 #ifndef __CINT__
113  const_VecTObjIter begin() const {return fV.begin();}
114  VecTObjIter begin() {return fV.begin();}
115 const_VecTObjIter end() const {return fV.end();}
116  VecTObjIter end() {return fV.end();}
117  TObject** Erase(TObject** it ,int del);
118  TObject** Erase(TObject** fst,TObject** lst,int del);
119 #endif
121  TObject *& operator[](Int_t i) {return fV[i];}
122  TObject * const &operator[](Int_t i) const {return fV[i];}
123 void push_back(const TObject * const to){fV.push_back((TObject*)to);}
124  Int_t getEntries() const;
125 void ls(const char *tit="") const;
126 void Print(const char *tit="") const { ls(tit); }
127 protected:
128 //#ifndef __CINT__
129 VecTObj fV;
130 //#endif //_CINT__
131 ClassDef(StObjArray,4)
132 };
133 
134 
135 class StStrArray : public StObjArray {
136 protected:
137 
138 //NONMONO void Book(TObject* obj,int idx);
139 
140 public:
141  StStrArray(Int_t sz=0);
142  StStrArray(const StStrArray &from);
143  virtual ~StStrArray();
144  void operator=(const StStrArray &a);
145 
146  void push_back(const TObject *to);
147  void put_at(TObject *obj,int i);
148  void clear();
149  virtual void makeZombie(int flg);
150 private:
151 ClassDef(StStrArray,3)
152 };
153 
154 
155 class StRefArray : public StObjArray
156 {
157 public:
158  StRefArray(Int_t sz=0);
159  StRefArray(const StRefArray &from);
160  ~StRefArray(){};
161 ClassDef(StRefArray,3)
162 };
163 
164 // Utilities
165 
166 // Macros
167 
168 #ifndef __CINT__
169 #define StCollectionDef(QWERTY) \
170 class St ## QWERTY;\
171 typedef St ## QWERTY** St ## QWERTY ## Iterator;\
172 typedef St ## QWERTY * const * const_St ## QWERTY ## Iterator;\
173 \
174 class StPtrVec ## QWERTY : public StRefArray \
175 { \
176 public: \
177 StPtrVec ## QWERTY(Int_t sz=0):StRefArray(sz){};\
178 StPtrVec ## QWERTY(const StPtrVec ## QWERTY &from):StRefArray(from){};\
179 virtual ~StPtrVec ## QWERTY(){};\
180 \
181  St ## QWERTY * const &at(Int_t idx) const {return (St ## QWERTY * const &)fV[idx];}\
182  St ## QWERTY * &at(Int_t idx) {return (St ## QWERTY * &)fV[idx];}\
183 \
184  St ## QWERTY * const &front() const {return (St ## QWERTY * const &)fV.front();}\
185  St ## QWERTY * &front() {return (St ## QWERTY * &)fV.front();}\
186 \
187  St ## QWERTY * const &back() const {return (St ## QWERTY * const &)fV.back();}\
188  St ## QWERTY * &back() {return (St ## QWERTY * &)fV.back();}\
189 \
190 const_St ## QWERTY ## Iterator begin() const {return (const_St ## QWERTY ## Iterator)&(*(fV.begin()));}\
191  St ## QWERTY ## Iterator begin() {return ( St ## QWERTY ## Iterator)&(*(fV.begin()));}\
192 const_St ## QWERTY ## Iterator end() const {return (const_St ## QWERTY ## Iterator)&(*(fV.end()));}\
193  St ## QWERTY ## Iterator end() {return ( St ## QWERTY ## Iterator)&(*(fV.end()));}\
194  St ## QWERTY ## Iterator erase(St ## QWERTY ## Iterator it)\
195  {return (St ## QWERTY ## Iterator)Erase((TObject**)it,0);}\
196  St ## QWERTY ## Iterator erase(St ## QWERTY ## Iterator fst,St ## QWERTY ## Iterator lst)\
197  {return (St ## QWERTY ## Iterator)Erase((TObject**)fst,(TObject**)lst,0);}\
198  St ## QWERTY * &operator[](Int_t i) {return at(i);}\
199  St ## QWERTY * const &operator[](Int_t i) const {return at(i);}\
200 void push_back(const St ## QWERTY * const to){fV.push_back((TObject*const)to);}\
201 \
202 ClassDef(StPtrVec ## QWERTY ,1) \
203 };\
204 \
205 \
206 class StSPtrVec ## QWERTY : public StStrArray \
207 { \
208 public: \
209 StSPtrVec ## QWERTY(Int_t sz=0):StStrArray(sz){};\
210 StSPtrVec ## QWERTY(const StSPtrVec ## QWERTY &from):StStrArray(from){};\
211 \
212  St ## QWERTY * const &at(Int_t idx) const {return (St ## QWERTY * const &)fV[idx];}\
213  St ## QWERTY * &at(Int_t idx) {return (St ## QWERTY * &)fV[idx];}\
214 \
215  St ## QWERTY * const &front() const {return (St ## QWERTY * const &)fV.front();}\
216  St ## QWERTY * &front() {return (St ## QWERTY * &)fV.front();}\
217 \
218  St ## QWERTY * const &back() const {return (St ## QWERTY * const &)fV.back();}\
219  St ## QWERTY * &back() {return (St ## QWERTY * &)fV.back();}\
220 \
221 const_St ## QWERTY ## Iterator begin() const {return (const_St ## QWERTY ## Iterator)&(*(fV.begin()));}\
222  St ## QWERTY ## Iterator begin() {return ( St ## QWERTY ## Iterator)&(*(fV.begin()));}\
223 const_St ## QWERTY ## Iterator end() const {return (const_St ## QWERTY ## Iterator)&(*(fV.end()));}\
224  St ## QWERTY ## Iterator end() {return ( St ## QWERTY ## Iterator)&(*(fV.end()));}\
225  St ## QWERTY ## Iterator erase(St ## QWERTY ## Iterator it)\
226  {return (St ## QWERTY ## Iterator)Erase((TObject**)it,1);}\
227  St ## QWERTY ## Iterator erase(St ## QWERTY ## Iterator fst,St ## QWERTY ## Iterator lst)\
228  {return (St ## QWERTY ## Iterator)Erase((TObject**)fst,(TObject**)lst,1);}\
229  St ## QWERTY * &operator[](Int_t i) {return at(i);}\
230  St ## QWERTY * const &operator[](Int_t i) const {return at(i);}\
231 void push_back(const St ## QWERTY *to){StStrArray::push_back((TObject*)to);}\
232 \
233 ClassDef(StSPtrVec ## QWERTY,1) \
234 };\
235 typedef St ## QWERTY ## Iterator StPtrVec ## QWERTY ## Iterator;\
236 typedef const_St ## QWERTY ## Iterator StPtrVec ## QWERTY ## ConstIterator;\
237 typedef St ## QWERTY ## Iterator StSPtrVec ## QWERTY ## Iterator;\
238 typedef const_St ## QWERTY ## Iterator StSPtrVec ## QWERTY ## ConstIterator;\
239 
240 //______________________________________________________________
241 #define StCollectionImp(QWERTY) \
242 \
243 ClassImpUnique(StPtrVec ## QWERTY ,1 ) \
244 void StPtrVec ## QWERTY::Streamer(TBuffer& b){StRefArray::Streamer(b);} \
245 \
246 ClassImpUnique(StSPtrVec ## QWERTY , 2 ) \
247 \
248 void StSPtrVec ## QWERTY::Streamer(TBuffer& b){StStrArray::Streamer(b);} \
249 
250 #endif /*End not __CINT__*/
251 #endif
252 
TObject *& operator[](Int_t i)
Definition: StArray.h:121