Helios++
Helios software for LiDAR simulations
PyIntegerList.h
1 #pragma once
2 
3 #ifdef PYTHON_BINDING
4 
5 #include <PyHeliosUtils.h>
6 #include <list>
7 
8 namespace pyhelios{
9 
10 
19 public:
20  // *** ATTRIBUTES *** //
21  // ******************** //
22  std::list<int> &list;
23 
24  // *** CONSTRUCTION *** //
25  // ********************** //
26  PyIntegerList(std::list<int> &list) : list(list) {}
27  virtual ~PyIntegerList() {}
28 
29  // *** GETTERS and SETTERS *** //
30  // ***************************** //
31  int get(long _index){
32  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
33  std::list<int>::iterator it = list.begin();
34  for(size_t i = 0 ; i < index ; i++)it++;
35  return *it;
36  }
37  void set(long _index, int value){
38  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
39  std::list<int>::iterator it = list.begin();
40  for(size_t i = 0 ; i < index ; i++)it++;
41  *it = value;
42  }
43  void insert(long _index, int value){
44  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
45  std::list<int>::iterator it = list.begin();
46  for(size_t i = 0 ; i < index ; i++)it++;
47  list.insert(it, value);
48  }
49  void erase(long _index){
50  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
51  std::list<int>::iterator it = list.begin();
52  for(size_t i = 0 ; i < index ; i++)it++;
53  list.erase(it);
54  }
55  size_t length() {return list.size();}
56 };
57 
58 }
59 
60 #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
Wrapper for std::list<int> class.
Definition: PyIntegerList.h:18