HDTree  0.5.2
HDTree C++ API
VectorBranch.h
1 #pragma once
2 
3 namespace hdtree {
4 
16 template <typename ContentType>
17 class Branch<std::vector<ContentType>>
18  : public AbstractBranch<std::vector<ContentType>> {
20 
21  public:
29  explicit Branch(const std::string& branch_name,
30  std::vector<ContentType>* handle = nullptr)
31  : AbstractBranch<std::vector<ContentType>>(branch_name, handle),
32  size_{branch_name + "/" + constants::SIZE_NAME},
33  data_{branch_name + "/data"} {}
34 
35  void attach(Reader& f) final override {
36  this->load_type_ = f.type(this->name_);
37  size_.attach(f);
38  data_.attach(f);
39  }
50  void load() final override {
51  size_.load();
52  this->handle_->resize(size_.get());
53  for (std::size_t i_vec{0}; i_vec < size_.get(); i_vec++) {
54  data_.load();
55  (*(this->handle_))[i_vec] = data_.get();
56  }
57  }
58 
68  void save() final override {
69  size_.update(this->handle_->size());
70  size_.save();
71  for (std::size_t i_vec{0}; i_vec < this->handle_->size(); i_vec++) {
72  data_.update(this->handle_->at(i_vec));
73  data_.save();
74  }
75  }
76 
77  void attach(Writer& f) final override {
78  f.structure(this->name_, this->save_type_);
79  size_.attach(f);
80  data_.attach(f);
81  }
82 
83  private:
88 }; // Branch<std::vector>
89 
90 } // namespace hdtree
#define hdtree_class_version(VERS)
define the version number for a class
Definition: ClassVersion.h:85
Type-specific base class to hold common data methods.
Definition: AbstractBranch.h:87
std::pair< std::string, int > save_type_
type this data that is being used to write
Definition: AbstractBranch.h:244
std::optional< std::pair< std::string, int > > load_type_
type this data is loading from
Definition: AbstractBranch.h:242
DataType * handle_
handle on current object in memory
Definition: AbstractBranch.h:247
std::string name_
name of branch
Definition: AbstractBranch.h:74
void attach(Reader &f) final override
pure virtual method for loading data from the input file
Definition: VectorBranch.h:35
Branch(const std::string &branch_name, std::vector< ContentType > *handle=nullptr)
We create two child data sets, one to hold the successive sizes of the vectors and one to hold all of...
Definition: VectorBranch.h:29
void load() final override
Load a vector from the input file.
Definition: VectorBranch.h:50
void attach(Writer &f) final override
pure virtual method for saving structure
Definition: VectorBranch.h:77
Branch< std::size_t > size_
the data set of sizes of the vectors
Definition: VectorBranch.h:85
void save() final override
Save a vector to the output file.
Definition: VectorBranch.h:68
Branch< ContentType > data_
the data set holding the content of all the vectors
Definition: VectorBranch.h:87
General data set.
Definition: GeneralBranch.h:46
Reading a file generated by fire.
Definition: Reader.h:24
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:21
Geant4 does a GLOBAL definition of the keyword TRUE.
Definition: Atomic.cxx:3
Structure constants vital to serialization method.
Definition: Constants.h:15