on my process on writing the serialisiation class I hang
on the following problem:
class Serializable { [...]
suid_t suid() const;
}
class Hoomer : public Serializable { [...] }
class Bart : public Serializable { [...] }
class SerializableFactory {
[...]
template <class _Tp> static Serializable* creator() {
return new _Tp;
}
Serializable* create(Serializable::suid_t id) const;
};
int main() {
[...]
is >> id;
Bart* bart = static_cast<Bart*>(factory.create(id));
is >> *bart;
[...]
}
But it could be a Hoomer as well. How can I cast using an id ?
The SerializableFactory::create() creates Barts or Hoomers on
the given id using an allways registered creator. The assoziation
between ids and loaders is done by a map. The solution could
be a template but, how could it look ?
Thanks
Olaf
Possible:
Serializable * s = factory.create(id);
then use virtual methods.
The solution probably can't be a template, as the types for templates need
to be known at compile-time.
BYW, why are you bothering writing this? There are a lot of existing
solutions to persistent object storage already out there.
NeilB
> The solution probably can't be a template, as the types for templates need
> to be known at compile-time.
Yep.
> BYW, why are you bothering writing this? There are a lot of existing
> solutions to persistent object storage already out there.
Please, could you give some URL for suitable solutions ? I Have some
articles about, but they give not the secrets I'm looking for (like
the above). Or they give only the way in principle, no working solution.
The only lib which can handle with persistance objects
I know is the commonc++ lib, here a part of the source (persist.cpp):
bool BaseObject::Write(Engine& archive) const
{
// Do nothing
return true; // Successfully
}
and other jokes etc.
BTW, this isn't bothering for me. Here I discuss only parts of
the problem due to the long listing, and I have to be portable,
therefore
no MS MFC solutions (which has inspirated commonc++ persistence objects
?)
Regards
Olaf
You should evaluate the use of an OO database, which will do everything you
want and more. Examples with free single-user products (alast time I looked)
can be found at www.odi.com and www.poet.com - there are several others.
NeilB
Serializable* something = factory.create(id);
> is >> *something;
> [...]
> }
>
> But it could be a Hoomer as well. How can I cast using an id ?
You can't predict what it will be. So you have to work only threw
base class pointers, and later on (when object is loaded
you can perform dynamic_cast to see what type you got).
> The SerializableFactory::create() creates Barts or Hoomers on
> the given id using an allways registered creator. The assoziation
> between ids and loaders is done by a map. The solution could
> be a template but, how could it look ?
You don't need a template in this case.
>
> Thanks
> Olaf
Greetings, Bane.
AFAIK, they're all either commercial or don't do quite what you need.
:-P
BTW, you wouldn't happen to know about any Open-Source XML-based
serialization libraries/frameworks worth their salt?
--
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
)____(stud.techn.;ind.øk.data)||(softwareDeveloper.at(Trustix))_(
/"Opinions expressed are mine and not those of my Employer, "\
( "the University, my girlfriend, stray cats, banana fruitflies, " )
\"nor the frontal lobe of my left cerebral hemisphere. "/