Helios++
Helios software for LiDAR simulations
PyStringVector.h
1 #pragma once
2 
3 #ifdef PYTHON_BINDING
4 
5 #include <PyHeliosUtils.h>
6 #include <vector>
7 #include <string>
8 
9 namespace pyhelios{
10 
11 
13 public:
14  // *** ATTRIBUTES *** //
15  // ******************** //
16  std::vector<std::string> *vec = nullptr;
17  bool release = true;
18 
19  // *** CONSTRUCTION / DESTRUCTION *** //
20  // ************************************ //
21  PyStringVector(std::vector<std::string> *vec) : vec(vec), release(false) {}
22  PyStringVector(std::vector<std::string> const vec){
23  this->vec = new std::vector<std::string>(vec);
24  release = true;
25  }
26  virtual ~PyStringVector(){if(release && vec != nullptr) free(vec);}
27 
28  // *** GETTERs and SETTERs *** //
29  // ***************************** //
30  std::string get(long _index){
31  size_t index = PyHeliosUtils::handlePythonIndex(_index, vec->size());
32  return (*vec)[index];
33  }
34  void set(long _index, std::string value){
35  size_t index = PyHeliosUtils::handlePythonIndex(_index, vec->size());
36  (*vec)[index] = value;
37  }
38  void insert(std::string value){vec->push_back(value);}
39  void erase(long _index){
40  size_t index = PyHeliosUtils::handlePythonIndex(_index, vec->size());
41  vec->erase(vec->begin() + index);
42  }
43  size_t length() {return vec->size();}
44 };
45 
46 }
47 
48 #endif
static size_t handlePythonIndex(long _index, size_t n)
Translate received index from python, where negative values have a special meaning (i....
Definition: PyHeliosUtils.h:16
Definition: PyStringVector.h:12