Hi, I have a class named Particle which has a std::set as a member. The class looks like this:
class Particle {
private:
std::set<vtkIdType> cells;
std::set<vtkIdType>::iterator ipc;
public:
Particle() {};
enum state {EXISTS = -1, SUCCESS = 0, ERROR = 1};
state addCell(const vtkIdType cell);
int numCells() { return static_cast<int>(cells.size()); }
vtkIdType getFirstCell() { return (*(ipc = this->cells.begin()));}
vtkIdType getNextCell() { return *(++ipc); }
vtkIdType hasNextCell() { ++ipc; if (ipc == this->cells.end()) return false; --ipc; return true; }
std::string getOutput();
};
I'm very unhappy with the getFirstCell()
, getNextCell()
and especially hasNextCell()
, they exist because I don't want to expose the set itself. I had to use the way through ++ipc
and --ipc
because if((ipc+1) == this->cells.end())
gives a compiler error, ipc+1 seems to be the problem.
What would be a good way to encapsulate a set and access it? Also, is there a nice way to get rid of the getFirstCell()
function?
Thanks in advance.
Edit: The code I posted is just an example of the classes structure. The "real" class contains more sets and other data that is not that important for this question (I assumed).