Re: Is there a design pattern for holding the same pointers in many arrays?
On 11/8/2010 4:23 AM, Ulrich Eckhardt wrote:
Hakusa@gmail.com wrote:
Is there a design pattern for holding the same pointers in many
arrays? The obvious answer is to use a smart pointer, but i am and
there's more to it.
I'm making a real-time graphical application (video game) and i want a
list of every graphical object, a list of every circular object,
square object, every physical object, etc. Many applications even have
so-called buckets, which ensure that certain objects are updated
before others.
I guess the answer is performance, but still I'll ask the question: Why do
you need these lists? You could store the objects in a single list and when
you want to access all circular objects, you visit every object with an
according visitor (look up "visitor pattern" aka "double dispatch") that
does nothing for non-circular objects.
Alternatively, since list iterators don't get invalidated, you could
maintain everything in a global list, and maintain lists of iterators
into the global list for various shapes, if you really needed that.
i.e.:
std::list<shape*> global_list;
std::list< std::list<shape*>::iterator> circles;
std::list< std::list<shape*>::iterator> rectangles;
etc...
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]