LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCCollectionVec.cc
Go to the documentation of this file.
1 
2 #include "IMPL/LCCollectionVec.h"
3 #include "EVENT/LCIO.h"
4 #include <iostream>
5 
6 // #include "UTIL/LCTOOLS.h"
7 
8 using namespace EVENT ;
9 
10 namespace IMPL {
11 
12 
13 LCCollectionVec::LCCollectionVec( const std::string& type ) :
14  _typeName( type ),
15  _flag(0) {}
16 
17 
18  // overwrite the default implementation
19  // set flag in all elements
20  void LCCollectionVec::setReadOnly(bool readOnly){
21 
22  AccessChecked::setReadOnly(readOnly ) ;
23 
24  LCObjectVec::iterator iter = begin() ;
25  while( iter != end() ){
26  AccessChecked* element = dynamic_cast<AccessChecked*>(*iter++) ;
27  if(element){
28  element->setReadOnly( readOnly ) ;
29  }
30  }
31  }
32 
34 
35  if( ! isSubset() ){
36  // delete all elements
37  LCObjectVec::const_iterator iter = begin() ;
38  // std::cout << "deleting collection "
39  // << std::endl ;
40  // UTIL::LCTOOLS::printParameters( parameters() ) ;
41 
42  while( iter != end() ){
43  delete *iter++ ;
44  }
45  }
46 }
47 
48 
50  return size() ;
51 }
52 
53 
55  return _typeName ;
56 }
57 
58 
59 
61  return this->operator[](index) ;
62 }
63 
65  return (_flag & (1<<BITTransient) ) ;
66 }
67 
69  if(val) _flag |= (1<<BITTransient) ;
70  else _flag &= ~(1<<BITTransient) ;
71 }
72 
73 
75  return (_flag & (1<<BITDefault) ) ;
76 }
77 
79  if(val) _flag |= (1<<BITDefault) ;
80  else _flag &= ~(1<<BITDefault) ;
81 }
82 
84  return (_flag & (1<<BITSubset) ) ;
85 }
86 
88  if(val) _flag |= (1<<BITSubset) ;
89  else _flag &= ~(1<<BITSubset) ;
90 }
91 
92 
94  return _flag ;
95 }
96 
97 
98 void LCCollectionVec::setFlag(int flag){
99  _flag = flag ;
100 }
101 
102 
104 
105  // if(_access != LCIO::UPDATE )
106  // throw ReadOnlyException("LCCollectionVec::addElement: event is read only") ;
107  checkAccess("LCCollectionVec::addElement") ;
108  this->push_back( obj ) ;
109  }
110 
112 
113  // if(_access != LCIO::UPDATE )
114  // throw ReadOnlyException("LCCollectionVec::addElement: event is read only") ;
115  checkAccess("LCCollectionVec::removeElementAt") ;
116  this->erase( begin() + i ) ;
117 
118  }
119 
120 } // namespace IMPL
121 
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
virtual int getNumberOfElements() const
Returns the number of entries in the collection.
void setSubset(bool val=true)
Sets the subset flag for this collection.
virtual EVENT::LCObject * getElementAt(int index) const
Returns pointer to element at index - no range check !.
void setDefault(bool val=true)
Sets the default flag for this collection.
virtual bool isDefault() const
True if collection is the default collection for the given type.
LCObject * end(LCObject *...args)
void setTransient(bool val=true)
Sets the transient flag for this collection.
void setFlag(int flag)
Sets the flag word for this collection.
STL class.
void setReadOnly(bool readOnly)
virtual ~LCCollectionVec()
Destructor.
LCObject * push_back(LCObject *...args)
virtual const std::string & getTypeName() const
Returns the type name of the collection - valid names are defined in LCIO.
static const int BITTransient
Transient bit in flag word.
Definition: LCCollection.h:68
LCObject * erase(LCObject *...args)
virtual bool isSubset() const
True if the collection holds a subset of objects from other collections.
virtual void addElement(EVENT::LCObject *obj)
Adds the given element to (end of) the collection.
LCObject * size(LCObject *...args)
virtual void setReadOnly(bool readOnly)
virtual int getFlag() const
Returns flag word for collection.
LCObject * begin(LCObject *...args)
virtual void removeElementAt(int i)
Removes the i-th element from the collection.
Controls access to objects.
Definition: AccessChecked.h:18
virtual bool isTransient() const
True if collection is transient, i.e.
static const int BITDefault
Definition: LCCollection.h:69
static const int BITSubset
Definition: LCCollection.h:70
LCObject * operator[](LCObject *...args)