maps and class types: extending a class factory

Discussion in 'C++' started by Simon Elliott, Jan 11, 2005.

  1. 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?

    --
    Simon Elliott http://www.ctsn.co.uk
    Simon Elliott, Jan 11, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Medi Montaseri
    Replies:
    17
    Views:
    838
    Medi Montaseri
    Sep 3, 2003
  2. Simon Elliott
    Replies:
    4
    Views:
    1,146
    Simon Elliott
    Mar 10, 2005
  3. Marcus
    Replies:
    2
    Views:
    579
    Marcus
    Dec 9, 2005
  4. C#
    Replies:
    4
    Views:
    389
  5. Henrik Skak Pedersen

    Data types in Pattern & Practices Web Service Software Factory

    Henrik Skak Pedersen, Dec 13, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    164
    Steven Cheng[MSFT]
    Dec 14, 2006
Loading...

Share This Page