Menu

Problems with factory registering

2008-01-17
2013-04-08
  • Nobody/Anonymous

    Hi, I'm trying to get my types registered at a Loki::SingletonHolder< Loki::Factory< Loader, std::string > >. Problem is that I can't seem to get the register function to fire. I have a .h file with an implementation of Loader. At the bottom of this header is an anonymous namespace with:

    const bool = MyFactor::Instance().RegisterShape( "Key", CreateKeyLoader );

    Only problem is that this code never seems to be called. Later on when I try to create an object with "Key" OnUnknownType triggers, and using my debugger I can clearly see that the associations_ container is empty. I'm beginning to think that perhaps the compiler is optimizing it away even if optimization is disabled.

    Any help greatly appreciated.

     
    • Nobody/Anonymous

      Oops, just noticed there's a help sub forum as well. Feel free to move if possible.

      Anyway, I did some reading in the help forum and after some thinking I'm pretty certain of what the problem is. Basicly I'm trying to do a factory which clients of my lib can use, while hiding implementation details of all my types. I can't think of any neat way to accomplish this due to the problems of running scattered static start up code resident in the library. I've taken a look at the Register solution, but from what I can discern it seems that I need to maintain a class list in addition to the usual factory maintnance. Which only makes it slightly better than the problem it's trying to solve, to maintain a switch/case.

       

Log in to post a comment.