[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.4.5 Archiving structures
If you don't know how the archiving of GiNaC objects is implemented, you should first read the next section and then come back here. You're back? Good.
To implement archiving for structures it is not enough to provide
specializations for the archive()
member function and the
unarchiving constructor (the unarchive()
function has a default
implementation). You also need to provide a unique name (as a string literal)
for each structure type you define. This is because in GiNaC archives,
the class of an object is stored as a string, the class name.
By default, this class name (as returned by the class_name()
member
function) is ‘structure’ for all structure classes. This works as long
as you have only defined one structure type, but if you use two or more you
need to provide a different name for each by specializing the
get_class_name()
member function. Here is a sample implementation
for enabling archiving of the scalar product type defined above:
const char *sprod::get_class_name() { return "sprod"; } void sprod::archive(archive_node & n) const { inherited::archive(n); n.add_ex("left", get_struct().left); n.add_ex("right", get_struct().right); } sprod::structure(const archive_node & n, lst & sym_lst) : inherited(n, sym_lst) { n.find_ex("left", get_struct().left, sym_lst); n.find_ex("right", get_struct().right, sym_lst); } |
Note that the unarchiving constructor is sprod::structure
and not
sprod::sprod
, and that we don't need to supply an
sprod::unarchive()
function.