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 
16 public:
17  // *** ATTRIBUTES *** //
18  // ******************** //
19  std::list<int> &list;
20 
21  // *** CONSTRUCTION *** //
22  // ********************** //
23  PyIntegerList(std::list<int> &list) : list(list) {}
24  virtual ~PyIntegerList() {}
25 
26  // *** GETTERS and SETTERS *** //
27  // ***************************** //
28  int get(long _index){
29  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
30  std::list<int>::iterator it = list.begin();
31  for(size_t i = 0 ; i < index ; i++)it++;
32  return *it;
33  }
34  void set(long _index, int value){
35  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
36  std::list<int>::iterator it = list.begin();
37  for(size_t i = 0 ; i < index ; i++)it++;
38  *it = value;
39  }
40  void insert(long _index, int value){
41  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
42  std::list<int>::iterator it = list.begin();
43  for(size_t i = 0 ; i < index ; i++)it++;
44  list.insert(it, value);
45  }
46  void erase(long _index){
47  size_t index = PyHeliosUtils::handlePythonIndex(_index, list.size());
48  std::list<int>::iterator it = list.begin();
49  for(size_t i = 0 ; i < index ; i++)it++;
50  list.erase(it);
51  }
52  size_t length() {return list.size();}
53 };
54 
55 #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:14
Wrapper for std::list<int> class.
Definition: PyIntegerList.h:15