I spent all my day studying this topic, so with some scattered knowledge on this topic, I came to you with this request. Let me describe what I'm trying to accomplish, and perhaps you can either offer a solution to the immediate question, or another way to completely solve the problem.
I am trying to imitate something related to how XAML files work in WPF , where you essentially instantiate an object tree from an XML definition. If this is not correct, report it. This problem is otherwise not related to WPF , C #, or something controlled - I mention this only because it is a similar concept.
So, I already created an XML parser class and generated a node tree based on ObjectNode objects. An ObjectNode object contains a string value of type , and they have std :: vector children of ObjectNode objects.
The next step is to create an instance of the object tree based on the data in the ObjectNode tree. This intermediate ObjectNode tree is necessary because the same ObjectNode tree can be created several times or delayed as needed. The tree of created objects is such that the nodes in the tree are descendants of a common base class, which can now be called MyBase . Leaf nodes can be of any type, not necessarily obtained from MyBase .
To make this more complicated, I will not know what types of objects can be involved in the tree, so I need to allow registration of new types with the factory.
I am aware of a factory upgrade. Their documents have an interesting little design paragraph on this page :
<i> o We may need a factory that takes some arguments that are redirected to the constructor,
o we probably want to use smart pointers,
o we may want several member functions to create objects of different types,
o we may not need a polymorphic base class for objects,
o, as we will see, we donโt need the factory base class at all,
o we could just call the constructor - without # new # to create an object on the stack and
o Finally, we might want to use individual memory management.
I might not get it all right, but it seems like I'm arguing that what I'm trying to do can be achieved using boost factory. But all the examples I cite seem to describe factories where all the objects are made from the base type.
Any advice on this would be greatly appreciated.
Thank you for your time!