maps and class types: extending a class factory

S

Simon Elliott

I have a class factory which maps various parameters onto static
creator functions:

typedef TbarAutoPtr (*TcreateBar)(const std::string& barName);
typedef std::map <std::string, TcreateBar> TbarMap;

TbarMap barMap_;

barMap_[TbarDerived1::GetStaticBarTypeName()] =
TbarDerived1::CreateInstance;

barMap_[TbarDerived2::GetStaticBarTypeName()] =
TbarDerived2::CreateInstance;

This lets me intantiate the classes:

TbarAutoPtr barInstance(0);
TbarMap::iterator createInstancePtr = barMap_.find("TbarDerived1");
if (createInstancePtr != barMap_.end())
{
barInstance = (*createInstancePtr).second("foo");
}

However, it turns out that the mappings in barMap_ are useful in other
ways, and the classes derived from TBar have a number of static
functions I'd like to be able to call, in addition to CreateInstance().

Thus instead of having the map containing a pointer to a static
function, I'd like the map to contain some sort of typedef. I'd like to
be able to search by name as above, and, without instantiating the
class, call static functions of that class.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top