Helios++
Helios software for LiDAR simulations
DynSequence.h
1 #ifndef _DYN_SEQUENCE_H_
2 
3 #include <string>
4 #include <vector>
5 #include <memory>
6 
7 using std::string;
8 using std::vector;
9 using std::shared_ptr;
10 
36 template <typename T>
37 class DynSequence {
38 private:
39  // *** SERIALIZATION *** //
40  // *********************** //
41  friend class boost::serialization::access;
48  template <typename Archive>
49  void serialize(Archive &ar, const unsigned int version){
50  ar &id;
51  ar &next;
52  ar &loop;
53  ar &sequence;
54  ar &iteration;
55  }
56 
57 protected:
58  // *** ATTRIBUTES *** //
59  // ******************** //
63  string id;
71  string next;
76  size_t loop;
80  vector<shared_ptr<T>> sequence;
86  size_t iteration = 0;
87 
88 public:
89  // *** CONSTRUCTION / DESTRUCTION *** //
90  // ************************************ //
94  DynSequence() : DynSequence("id", "", 1) {}
104  DynSequence(string id, string next, size_t loop) :
105  id(id), next(next), loop(loop), iteration(0)
106  {}
107  virtual ~DynSequence() {}
108 
109  // *** DYNAMIC SEQUENCING *** //
110  // **************************** //
114  vector<shared_ptr<T>> nextStep();
119  void restart();
120 
121  // *** GETTERs and SETTERs *** //
122  // ***************************** //
128  inline void append(shared_ptr<T> element) {sequence.push_back(element);}
135  inline void append(vector<shared_ptr<T>> elements)
136  {sequence.insert(sequence.end(), elements.begin(), elements.end());}
143  inline shared_ptr<T> get(size_t index) const {return sequence[index];}
150  inline void set(size_t index, shared_ptr<T> element)
151  {sequence[index = element];}
157  inline void remove(size_t index)
158  {sequence.erase(sequence.begin()+index);}
164  inline size_t size() const {return sequence.size();}
169  inline typename vector<T>::iterator begin() {return sequence.begin();}
174  inline typename vector<T>::iterator end() {return sequence.end();}
178  inline void clear() {sequence.clear();}
184  inline size_t getIteration() const {return iteration;}
190  inline size_t getLoop() const {return loop;}
196  inline void setLoop(size_t const loop) {this->loop = loop;}
202  inline string getId() const {return id;}
208  inline void setId(string const & id) const {this->id = id;}
213  inline string getNext() const {return next;}
218  inline void setNext(string const & next) {this->next = next;}
219 };
220 
221 #include <scene/dynamic/DynSequence.tpp>
222 #define _DYN_SEQUENCE_H_
223 #endif
Dynamic sequence is a set of elements that must be applied during dynamic simulations to provide dyna...
Definition: DynSequence.h:37
vector< shared_ptr< T > > nextStep()
Obtain sequence corresponding to next step.
shared_ptr< T > get(size_t index) const
Obtain element at given index in the sequence.
Definition: DynSequence.h:143
size_t size() const
Obtain the number of elements composing the sequence.
Definition: DynSequence.h:164
void serialize(Archive &ar, const unsigned int version)
Serialize a dynamic sequence to a stream of bytes.
Definition: DynSequence.h:49
DynSequence(string id, string next, size_t loop)
Dynamic sequence basic constructor.
Definition: DynSequence.h:104
size_t iteration
Current iteration. It is used to control the dynamic sequence application loop. By default,...
Definition: DynSequence.h:86
void remove(size_t index)
Remove element at given index in the sequence.
Definition: DynSequence.h:157
void set(size_t index, shared_ptr< T > element)
Set element at given index in the sequence.
Definition: DynSequence.h:150
vector< T >::iterator end()
Obtain a iterator pointing to the last dynamic sequence element.
Definition: DynSequence.h:174
string id
Unique identifier for the dynamic sequence.
Definition: DynSequence.h:63
void append(shared_ptr< T > element)
Append an element to the sequence.
Definition: DynSequence.h:128
DynSequence()
Default constructor for the dynamic sequence.
Definition: DynSequence.h:94
void clear()
Remove all elements composing the sequence.
Definition: DynSequence.h:178
string getNext() const
Get next identifier for the dynamic sequence.
Definition: DynSequence.h:213
void setNext(string const &next)
Set next identifier for the dynamic sequence.
Definition: DynSequence.h:218
vector< T >::iterator begin()
Obtain a iterator pointing to the first dynamic sequence element.
Definition: DynSequence.h:169
void setLoop(size_t const loop)
Set loop value (max iterations)
Definition: DynSequence.h:196
vector< shared_ptr< T > > sequence
The elements composing the dynamic sequence.
Definition: DynSequence.h:80
void setId(string const &id) const
Set identifier for the dynamic sequence.
Definition: DynSequence.h:208
size_t getLoop() const
Get loop value (max iterations)
Definition: DynSequence.h:190
string getId() const
Get current identifier for the dynamic sequence.
Definition: DynSequence.h:202
string next
Unique identifier for dynamic sequence that must come after this one.
Definition: DynSequence.h:71
void restart()
Restart the dynamic sequence so when nextStep is called again it will start from the first iteration.
void append(vector< shared_ptr< T >> elements)
Append vector of elements to the end of the sequence.
Definition: DynSequence.h:135
size_t loop
Specify for how long the dynamic sequence must be repeated, using simulation steps as unit.
Definition: DynSequence.h:76
size_t getIteration() const
Get current iteration.
Definition: DynSequence.h:184