GiNaC  1.8.0
Classes | Namespaces | Macros | 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...
 
struct  GiNaC::archive_node::archive_node_cit_range
 
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

 GiNaC
 

Macros

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

Typedefs

typedef unsigned GiNaC::archive_node_id
 Numerical ID value to refer to an archive_node. More...
 
typedef unsigned GiNaC::archive_atom
 Numerical ID value to refer to a string. More...
 
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. More...
 
std::istream & GiNaC::operator>> (std::istream &is, archive &ar)
 Read archive from binary data stream. More...
 

Variables

static unarchive_table_t GiNaC::unarch_table_instance
 

Detailed Description

Archiving of GiNaC expressions.

Definition in file archive.h.

Macro Definition Documentation

◆ GINAC_DECLARE_UNARCHIVER

#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 219 of file archive.h.

◆ GINAC_BIND_UNARCHIVER

#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 230 of file archive.h.

GiNaC::unarchive_table_t::insert
void insert(const std::string &classname, synthesize_func f)
Definition: archive.cpp:584
GiNaC::unarchive_table_t
Definition: archive.h:170
GiNaC::basic
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105

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