I'm new to boost::python so please forgive me if I'm asking a stupid question. I'm trying to bind a Container and an Iterator classes to Python. My container is like a matrix of items where each row can be accessed through a method called Iterate() which returns a boost::iterator_range of my Iterator. Iterator has implemented various operators: ++, !=, == and * operator to get an Accessor instance which can access to the item's data. The code is like following:
class Accessor {
ItemValue get_value_item() {...}
};
class Iterator {
public:
Iterator &operator++();
Iterator &operator++(int);
bool operator==(...);
bool operator!=(...);
Accessor operator*() const {
return Accessor(idx_);
}
private:
int idx_;
};
class Container {
public:
boost::iterator_range<Iterator> Iterate(int id) {
return boost::iterator_range<Iterator>(Iterator(...), Iterator(...));
}
};
I expect the Python code to be like:
container = Container()
def func(id):
for record in container.Iterate(id):
print(record.get_accessor.get_value_item())
I'm only able to bind the Container class and get stuck when binding Iterator class because I have no idea how to bind those operator to Python. I'm not familiar with Python so I don't quite understand how iterating work in Python.
How should I expose the Iterator and boost::iterator_range to Python?