PandaRoot
PndSTDMutableContainer.h
Go to the documentation of this file.
1 
15 #ifndef PNDSTDMUTABLECONTAINER_HH
16 #define PNDSTDMUTABLECONTAINER_HH
17 
18 #include <stdexcept>
19 #include <vector>
20 
21 #include "TString.h"
22 
23 #include "FairLogger.h"
24 #include "FairRootManager.h"
25 
26 #include "PndMutableContainerI.h"
27 
36 template <class T>
38  public:
45  PndSTDMutableContainer(const TString &t_foldername = "", Bool_t t_persistency = kTRUE) : PndMutableContainerI<T>(t_foldername, t_persistency) {}
46 
52 
59  virtual T *GetElement(Int_t t_idx) const final
60  {
61  if (fSTD != nullptr) {
62  return &(fSTD->at(t_idx));
63  }
64  return nullptr;
65  }
66 
72  virtual ssize_t GetSize() const final
73  {
74  if (fSTD != nullptr) {
75  return fSTD->size();
76  }
77  return 0;
78  }
79 
86  virtual T *CreateCopy(const T &t_element)
87  {
88  if (fSTD != nullptr) {
89  fSTD->push_back(T{t_element});
90  } else {
91  LOG(error) << "PndSTDMutableContainer::CreateCopy() no underlying std::vector";
92  return nullptr;
93  }
94  return GetElement(GetSize() - 1);
95  }
96 
102  virtual void RemoveAt(Int_t t_index) final
103  {
104  if (this->fSTD != nullptr) {
105  this->fSTD->erase(this->fSTD->begin() + t_index);
106  }
107  }
108 
113  virtual void Compress() {}
114 
119  virtual void Reset() final
120  {
121  if (this->fSTD != nullptr) {
122  this->fSTD->clear();
123  }
124  }
125 
131  void SetData(std::vector<T> *t_container) { fSTD = t_container; }
132 
138  std::vector<T> *GetData() { return fSTD; }
139 
140  private:
141  std::vector<T> *fSTD{nullptr};
142 };
143 
144 #endif /*PNDSTDMUTABLECONTAINER_HH*/
std::vector< T > * GetData()
Get the Data.
virtual T * CreateCopy(const T &t_element)
Create a Copy object of t_element and return pointer to copy.
void SetData(std::vector< T > *t_container)
Set the Data.
virtual void Reset() final
"Delete" all elements
virtual void RemoveAt(Int_t t_index) final
remove t_index element
virtual ~PndSTDMutableContainer()
Destroy the PndSTDMutableContainer object.
PndSTDMutableContainer(const TString &t_foldername="", Bool_t t_persistency=kTRUE)
Construct a new PndSTDMutableContainer object.
virtual ssize_t GetSize() const final
Get the number of elements.
virtual T * GetElement(Int_t t_idx) const final
Get the t_idx Element.
PndSTDMutableContainer implementation of PndMutableContainerI<T> for FairRootManager and std::vector<...
virtual void Compress()
Compress.