GiNaC  1.6.2
Classes | Namespaces | Defines | Typedefs | Functions | Variables
archive.h File Reference

Archiving of GiNaC expressions. More...

#include "ex.h"
#include <iosfwd>
#include <map>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

class  GiNaC::archive_node
 This class stores all properties needed to record/retrieve the state of one object of class basic (or a derived class). More...
struct  GiNaC::archive_node::property_info
 Information about a stored property. More...
struct  GiNaC::archive_node::property
 Archived property (data type, name and associated data) More...
class  GiNaC::unarchive_table_t
class  GiNaC::archive
 This class holds archived versions of GiNaC expressions (class ex). More...
struct  GiNaC::archive::archived_ex
 Archived expression descriptor. More...

Namespaces

namespace  GiNaC
 

CRC32 hash function.


Defines

#define GINAC_DECLARE_UNARCHIVER(classname)
 Helper macros to register a class with (un)archiving (a.k.a.
#define GINAC_BIND_UNARCHIVER(classname)

Typedefs

typedef unsigned GiNaC::archive_node_id
 Numerical ID value to refer to an archive_node.
typedef unsigned GiNaC::archive_atom
 Numerical ID value to refer to a string.
typedef basic *(* GiNaC::synthesize_func )()
typedef std::map< std::string,
synthesize_func > 
GiNaC::unarchive_map_t

Functions

std::ostream & GiNaC::operator<< (std::ostream &os, const archive &ar)
 Write archive to binary data stream.
std::istream & GiNaC::operator>> (std::istream &is, archive &ar)
 Read archive from binary data stream.

Variables

static unarchive_table_t GiNaC::unarch_table_instance

Detailed Description

Archiving of GiNaC expressions.

Definition in file archive.h.


Define Documentation

#define GINAC_DECLARE_UNARCHIVER (   classname)
Value:
class classname ## _unarchiver                  \
{                               \
    static int usecount;                    \
public:                             \
    static GiNaC::basic* create();              \
    classname ## _unarchiver();             \
    ~ classname ## _unarchiver();               \
};                              \
static classname ## _unarchiver classname ## _unarchiver_instance

Helper macros to register a class with (un)archiving (a.k.a.

(de)serialization).

Usage: put

GINAC_DECLARE_UNARCHIVER(myclass);

into the header file (in the global or namespace scope), and

GINAC_BIND_UNARCHIVER(myclass);

into the source file.

Effect: the `myclass' (being a class derived directly or indirectly from GiNaC::basic) can be archived and unarchived.

Note: you need to use GINAC_{DECLARE,BIND}_UNARCHIVER incantations in order to make your class (un)archivable _even if your class does not overload `read_archive' method_. Sorry for inconvenience.

How it works:

The `basic' class has a `read_archive' virtual method which reads an expression from archive. Derived classes can overload that method. There's a small problem, though. On unarchiving all we have is a set of named byte streams. In C++ the class name (as written in the source code) has nothing to do with its actual type. Thus, we need establish a correspondence ourselves. To do so we maintain a `class_name' => `function_pointer' table (see the unarchive_table_t class above). Every function in this table is supposed to create a new object of the `class_name' type. The `archive_node' class uses that table to construct an object of correct type. Next it invokes read_archive virtual method of newly created object, which does the actual job.

Note: this approach is very simple-minded (it does not handle classes with same names from different namespaces, multiple inheritance, etc), but it happens to work surprisingly well.

Definition at line 214 of file archive.h.

#define GINAC_BIND_UNARCHIVER (   classname)
Value:
classname ## _unarchiver::classname ## _unarchiver()        \
{                               \
    static GiNaC::unarchive_table_t table;          \
    if (usecount++ == 0) {                  \
        table.insert(std::string(#classname),       \
            &(classname ## _unarchiver::create));   \
    }                           \
}                               \
GiNaC::basic* classname ## _unarchiver::create()        \
{                               \
    return new classname();                 \
}                               \
classname ## _unarchiver::~ classname ## _unarchiver() { }  \
int classname ## _unarchiver::usecount = 0

Definition at line 225 of file archive.h.


This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.