Thread View: comp.lang.c++.moderated
1 messages
1 total messages
Started by Bowden Wise
Fri, 19 Jan 1996 22:55
Singleton Registry Revisited
Author: Bowden Wise
Date: Fri, 19 Jan 1996 22:55
Date: Fri, 19 Jan 1996 22:55
70 lines
3146 bytes
3146 bytes
Thanks to those of you who responded to my query about a hierarchy
of Singletons. Recall, that my plan is to have a hierarchy of
Singletons.
All of the singletons share some base functionality, which I have
placed in a base class: BaseResource ... this class is also
abstract, so I can only use BaseResource's as pointers and references.
Say we have two resources, derived from that one,
class Resource1 : public BaseResource;
class Resource2 : public BaseResource;
I have placed the singleton code in a template class, so that I
can instantiate singleton instances of resources like this:
static Singleton<Resource1> singletonResource1;
static Singleton<Resource2> singletonResource2;
This all works great.
Now, the problem at hand is to implement a SingletonRegistry.
However, I believe I cannot do this since I have separated the
singleton functionality from the base class functionality. It
appears to me that I must not use a template to separate the
singleton functionality from the BaseResource class. Since
the way it is set up now, there is no way to create a map from
resource names -> resource instances
I am going in circles here trying to figure out what I need, here
is some of my ramblings ...
I plan to use the STL map container, and was trying to develop my
map entries:
typedef map < string, Singleton<BaseResource&>* > MyMap;
but I dont think this will work, since the above Singletons
are not derived from a Singleton<BaseResource>
Maybe what I need instead is to make the singletons like this:
typedef map < string, Singleton<BaseResource*>* > MyMap
and then
when a concrete singleton resource is created, such as the,
Singleton<Resource1> have it register itself like this in the
constructor perhaps:
Singleton<Resource1>::Singleton<Resource1>
{
// but I cannot access the base part of Resource1 from here ??
// so no way to call
// this is not what we want since it is not derived from
// Singleton<BaseaResource*>
registry.Register ("Resource1", this );
}
Any ideas anyone? I'll keep thinking ...
Bowden
--------------------------------------------------------------------
G. Bowden Wise
Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
Email: wiseb@cs.rpi.edu WWW: http://www.cs.rpi.edu/~wiseb/
[ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
[ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
[ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
[ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads