Hi, I'm an experienced C programmer dipping my toes in OO design (specifically C++). I have a particular piece of code I hate and would like to clean up using C++.
The code implements a display tree for use in a 3d graphics app. It is a linked list of entries which have a type field specifying whether the entry is a window, geometry feature or light etc. In particular geometry features can either be a single piece of geometry of a collection of sub features, which is indicated by the presence of a separate structure.
Being a linked list it is a flat structure but the order implies hierarchy. Also, each entry has an attribute structure which is able to be propagated down the list.
A separate function allows this list to be traversed and a provided function pointer to be executed on traversal of the list. Each function used in this way must take proper care to maintain the attribute structure as it is propagated down the list and this is a frequent cause of rendering bugs (usually things not realising they should be redrawn because they are part of a group of entries, for example)
While some aspects of OO design jump right out at me I am interested to hear:
how i would best implement being able to pass a function pointer down a list (or vector - are STL vectors ok for lists like this?)
whether i would be right to implement windows and geometry features as related (or even the same) classes
how to best design a class that can have a collection of itself
any suggestions regarding attribute transferral between objects (e.g color, scale). the desired behaviour is that modifying a feature will alter the attributes of that feature and any sub-features it contains, and modifying a sub-feature will only modify that feature.
I realize this is a long and broad question, so appreciate your thoughts on any of the above queries. thanks!