pioneerspacesim/pioneer — pull request #2783 by lwho (2014-02-22 17:57:51+00:00)
Title: IterationProxy: Enable safe access to embedded containers

When I changed the attributes of ```SystemBody``` to private recently, and during my ongoing work to do the same for ```StarSystem``` I noticed that access to embedded containers gets a bit ugly.

Providing methods like ```ChildrenBegin``` and ```ChildrenEnd``` seems like a natural choice at first. But you can not use *range-based for* with that. Writing a ```GetChildren``` that returns a reference to the underlying container would just make it public again by another name (and with an uglier interface).

So, I wrote a proxy template class that just forwards the iterator functions to the underlying container. If the container provides random access it also provides a bracket operator (```operator[](int)```) to access an element at a given index.

The methods like ```GetChildren``` return such a proxy object instead of the container. So, the container is not exposed, but you can still do something like that:

```
SystemBody* parent = xxx;
for (SystemBody* kid : parent->GetChildren()) {
kid->do_something();
}
```

Since I had to use some template meta-programming magic, I would be grateful, if somebody could check, if that compiles with MSVC (I think, it should, but you never know).

### Notes

- The methods of ```IterationProxy``` use lowercase thus violating our code-style. This is **required** to match the language standards (e.g. for *range-based for* to work).
- I did not provide reverse iterators as we don't use them anywhere in our code base. Those would require further specialization of the template class for containers that do support bi-directional iterations and for those that don't. No need to make it more complicated than needed now.