RobinTrace
lpart_vec.h
Go to the documentation of this file.
1 
2 #ifndef LPART_VEC_H
3 #define LPART_VEC_H
4 
5 #include <vector>
6 #include <memory>
7 #include <iostream>
8 
12 class lpart_vec {
13  public:
15  std::vector<std::unique_ptr<lpart>> v;
16 
20  template <typename T>
21  void add_lpart(T part) {
22  static_assert(std::is_base_of<lpart, T>::value,
23  "T must be derived from lpart.");
24  v.push_back(std::make_unique<T>(part));
25  };
26 
28  lpart_vec cpy () const {
29  // Return a copy of the instance.
30  lpart_vec lv;
31  lv.v = clone_vec();
32  return lv;
33  };
34 
35  private:
37  std::vector<std::unique_ptr<lpart>> clone_vec () const {
38  // Return a copy of the internal vector.
39  std::vector<std::unique_ptr<lpart>> _v;
40  for (auto &ptr : v) {
41  _v.push_back(std::unique_ptr<lpart>(ptr->clone()));
42  }
43  return _v;
44  };
45 
47  friend std::ostream& operator<< (std::ostream &out, const lpart_vec &parts) {
48  out << "lpart_vec[";
49  int part_index = 0;
50  for (auto &part_ptr : parts.v) {
51  out << std::endl << "#" << part_index << ": " << *part_ptr;
52  part_index++;
53  }
54  out << "]";
55  return out;
56  };
57 };
58 
59 #endif // LPART_VEC_H
Vector of lparts.
Definition: lpart_vec.h:12
std::vector< std::unique_ptr< lpart > > clone_vec() const
Return a deep copy of the raw vector of lparts.
Definition: lpart_vec.h:37
friend std::ostream & operator<<(std::ostream &out, const lpart_vec &parts)
Printer.
Definition: lpart_vec.h:47
void add_lpart(T part)
Add a lpart to the vector.
Definition: lpart_vec.h:21
std::vector< std::unique_ptr< lpart > > v
Vector of lpart.
Definition: lpart_vec.h:15
lpart_vec cpy() const
Return a deep copy of the instance.
Definition: lpart_vec.h:28