J
jesper
Hi.
This might be to basic, or of topic, or just plain silly. But, Is there
a nice way to
construct objects dynamically from a data stream (file, socket, memory)
without
prior enumerating classes?
With enumerating classes I mean solutions like:
(pseudo code 1)
class B
{
tClasses type;
B(tClasses iType=classB){}
};
class Dublic B
{
D():B(classD){}
};
B* CreateObject(tClasses Class)
{
switch(Class)
{
case classD: return new D;
}
}
(end pseudo code 1)
or
(pseudo code 2)
map<tClasses,CreateObjectFunctionPtr> CreateFunctions;
....
D(){CreateFunctions[tClasses]=CreateClassDObject;}
....
(end pseudo code 2)
My question is, is there a way in the standard that involves less work?
(I might be
as lazy as they come), I have a project with a map of objects which can
be any of 200 or so classes. Now I need to save this map to file and
restore it. Any Input?
This might be to basic, or of topic, or just plain silly. But, Is there
a nice way to
construct objects dynamically from a data stream (file, socket, memory)
without
prior enumerating classes?
With enumerating classes I mean solutions like:
(pseudo code 1)
class B
{
tClasses type;
B(tClasses iType=classB){}
};
class Dublic B
{
D():B(classD){}
};
B* CreateObject(tClasses Class)
{
switch(Class)
{
case classD: return new D;
}
}
(end pseudo code 1)
or
(pseudo code 2)
map<tClasses,CreateObjectFunctionPtr> CreateFunctions;
....
D(){CreateFunctions[tClasses]=CreateClassDObject;}
....
(end pseudo code 2)
My question is, is there a way in the standard that involves less work?
(I might be
as lazy as they come), I have a project with a map of objects which can
be any of 200 or so classes. Now I need to save this map to file and
restore it. Any Input?