Boost logo

Boost Users :

From: Jonathan Oulds (jonathan.oulds_at_[hidden])
Date: 2004-08-10 09:47:42


Timothy Perrigo wrote:
...
> I need to create a kind of registry to keep track of
> instances of variables of different types (actually, several of these
> registries, representing different system states); variables of a type
> would be identified by an unique (integer) id. In other words, the
> variables within a particular registry represent the state of the system
> at a given point in time, so although each registry would have variables
> of the same types and ids, the values of the variables in different
> registries may be different. If the variables were all of the same
> type, a simple map would work. What I would like is a way of asking
> this registry for a variable of a specified type and id, and get back
> the appropriate instance (of the appropriate type). I.e., something
> like the following would be ideal:
>
> MyType mt = registry.get<MyType>(my_id);
>

why not create a templated registry? surely that would solve your
problem if each registry could only hold a particular type then instead
of typing

MyType mt = registry.get<MyType>(my_id);

you could type:

MyType mt = registry<MyType>.get(my_id);

but if you want to have lots of registries of type MyType why not have a
static factory function within each registry class, lets say we want a
particular registry based upon a integer id, then you could write:

MyType mt = registry<MyType>::GetInstance(5).get(my_id);

jonathan oulds


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net