GiNaC 1.8.7
Classes | Public Member Functions | Private Types | Private Attributes | Friends | List of all members
GiNaC::archive Class Reference

This class holds archived versions of GiNaC expressions (class ex). More...

#include <archive.h>

Classes

struct  archived_ex
 Archived expression descriptor. More...
 

Public Member Functions

 archive ()
 
 ~archive ()
 
 archive (const ex &e)
 Construct archive from expression using the default name "ex". More...
 
 archive (const ex &e, const char *n)
 Construct archive from expression using the specified name. More...
 
void archive_ex (const ex &e, const char *name)
 Archive an expression. More...
 
ex unarchive_ex (const lst &sym_lst, const char *name) const
 Retrieve expression from archive by name. More...
 
ex unarchive_ex (const lst &sym_lst, unsigned index=0) const
 Retrieve expression from archive by index. More...
 
ex unarchive_ex (const lst &sym_lst, std::string &name, unsigned index=0) const
 Retrieve expression and its name from archive by index. More...
 
unsigned num_expressions () const
 Return number of archived expressions. More...
 
const archive_nodeget_top_node (unsigned index=0) const
 Return reference to top node of an expression specified by index. More...
 
void clear ()
 Clear all archived expressions. More...
 
archive_node_id add_node (const archive_node &n)
 Add archive_node to archive if the corresponding expression is not already archived. More...
 
archive_nodeget_node (archive_node_id id)
 Retrieve archive_node by ID. More...
 
void forget ()
 Delete cached unarchived expressions in all archive_nodes (mainly for debugging). More...
 
void printraw (std::ostream &os) const
 Print archive to stream in ugly raw format (for debugging). More...
 
archive_atom atomize (const std::string &s) const
 Atomize a string (i.e. More...
 
const std::string & unatomize (archive_atom id) const
 Unatomize a string (i.e. More...
 

Private Types

typedef std::map< std::string, archive_atom >::const_iterator inv_at_cit
 The map of from strings to indices of the atoms vectors allows for faster archiving. More...
 

Private Attributes

std::vector< archive_nodenodes
 Vector of archived nodes. More...
 
std::vector< archived_exexprs
 Vector of archived expression descriptors. More...
 
std::vector< std::string > atoms
 Vector of atomized strings (using a vector allows faster unarchiving). More...
 
std::map< std::string, archive_atominverse_atoms
 
std::map< ex, archive_node_id, ex_is_lessexprtable
 Map of stored expressions to nodes for faster archiving. More...
 

Friends

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

Detailed Description

This class holds archived versions of GiNaC expressions (class ex).

An archive can be constructed from an expression and then written to a stream; or it can be read from a stream and then unarchived, yielding back the expression. Archives can hold multiple expressions which can be referred to by name or index number. The main component of the archive class is a vector of archive_nodes which each store one object of class basic (or a derived class).

Definition at line 254 of file archive.h.

Member Typedef Documentation

◆ inv_at_cit

typedef std::map<std::string,archive_atom>::const_iterator GiNaC::archive::inv_at_cit
private

The map of from strings to indices of the atoms vectors allows for faster archiving.

Definition at line 333 of file archive.h.

Constructor & Destructor Documentation

◆ archive() [1/3]

GiNaC::archive::archive ( )
inline

Definition at line 260 of file archive.h.

◆ ~archive()

GiNaC::archive::~archive ( )
inline

Definition at line 261 of file archive.h.

◆ archive() [2/3]

GiNaC::archive::archive ( const ex e)
inline

Construct archive from expression using the default name "ex".

Definition at line 264 of file archive.h.

References archive_ex().

◆ archive() [3/3]

GiNaC::archive::archive ( const ex e,
const char *  n 
)
inline

Construct archive from expression using the specified name.

Definition at line 267 of file archive.h.

References archive_ex(), and n.

Member Function Documentation

◆ archive_ex()

void GiNaC::archive::archive_ex ( const ex e,
const char *  name 
)

Archive an expression.

Parameters
ethe expression to be archived
namename under which the expression is stored

Definition at line 35 of file archive.cpp.

References add_node(), atomize(), and exprs.

Referenced by archive().

◆ unarchive_ex() [1/3]

ex GiNaC::archive::unarchive_ex ( const lst sym_lst,
const char *  name 
) const

Retrieve expression from archive by name.

Parameters
sym_lstlist of pre-defined symbols
namename of expression

Definition at line 78 of file archive.cpp.

References atomize(), exprs, and nodes.

◆ unarchive_ex() [2/3]

ex GiNaC::archive::unarchive_ex ( const lst sym_lst,
unsigned  index = 0 
) const

Retrieve expression from archive by index.

Parameters
sym_lstlist of pre-defined symbols
indexindex of expression
See also
count_expressions

Definition at line 97 of file archive.cpp.

References exprs, and nodes.

◆ unarchive_ex() [3/3]

ex GiNaC::archive::unarchive_ex ( const lst sym_lst,
std::string &  name,
unsigned  index = 0 
) const

Retrieve expression and its name from archive by index.

Parameters
sym_lstlist of pre-defined symbols
namereceives the name of the expression
indexindex of expression
See also
count_expressions

Definition at line 107 of file archive.cpp.

References exprs, nodes, and unatomize().

◆ num_expressions()

unsigned GiNaC::archive::num_expressions ( ) const

Return number of archived expressions.

Definition at line 120 of file archive.cpp.

References exprs.

◆ get_top_node()

const archive_node & GiNaC::archive::get_top_node ( unsigned  index = 0) const

Return reference to top node of an expression specified by index.

Definition at line 125 of file archive.cpp.

References exprs, and nodes.

◆ clear()

void GiNaC::archive::clear ( )

Clear all archived expressions.

Definition at line 599 of file archive.cpp.

References atoms, exprs, exprtable, inverse_atoms, and nodes.

◆ add_node()

archive_node_id GiNaC::archive::add_node ( const archive_node n)

Add archive_node to archive if the corresponding expression is not already archived.

Returns
ID of archived node

Definition at line 50 of file archive.cpp.

References exprtable, n, and nodes.

Referenced by GiNaC::archive_node::add_ex(), and archive_ex().

◆ get_node()

archive_node & GiNaC::archive::get_node ( archive_node_id  id)

◆ forget()

void GiNaC::archive::forget ( )

Delete cached unarchived expressions in all archive_nodes (mainly for debugging).

Definition at line 610 of file archive.cpp.

References GiNaC::archive_node::forget(), and nodes.

◆ printraw()

void GiNaC::archive::printraw ( std::ostream &  os) const

Print archive to stream in ugly raw format (for debugging).

Definition at line 624 of file archive.cpp.

References atoms, exprs, nodes, and unatomize().

◆ atomize()

archive_atom GiNaC::archive::atomize ( const std::string &  s) const

◆ unatomize()

const std::string & GiNaC::archive::unatomize ( archive_atom  id) const

Unatomize a string (i.e.

convert the ID number back to the string).

Definition at line 316 of file archive.cpp.

References atoms.

Referenced by GiNaC::archive_node::find_string(), GiNaC::archive_node::get_properties(), GiNaC::archive_node::printraw(), printraw(), and unarchive_ex().

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const archive ar 
)
friend

Write archive to binary data stream.

Definition at line 213 of file archive.cpp.

◆ operator>>

std::istream & operator>> ( std::istream &  is,
archive ar 
)
friend

Read archive from binary data stream.

Definition at line 260 of file archive.cpp.

Member Data Documentation

◆ nodes

std::vector<archive_node> GiNaC::archive::nodes
private

Vector of archived nodes.

Definition at line 309 of file archive.h.

Referenced by add_node(), clear(), forget(), get_node(), get_top_node(), printraw(), and unarchive_ex().

◆ exprs

std::vector<archived_ex> GiNaC::archive::exprs
private

Vector of archived expression descriptors.

Definition at line 321 of file archive.h.

Referenced by archive_ex(), clear(), get_top_node(), num_expressions(), printraw(), and unarchive_ex().

◆ atoms

std::vector<std::string> GiNaC::archive::atoms
mutableprivate

Vector of atomized strings (using a vector allows faster unarchiving).

Definition at line 329 of file archive.h.

Referenced by atomize(), clear(), printraw(), and unatomize().

◆ inverse_atoms

std::map<std::string, archive_atom> GiNaC::archive::inverse_atoms
mutableprivate

Definition at line 334 of file archive.h.

Referenced by atomize(), and clear().

◆ exprtable

std::map<ex, archive_node_id, ex_is_less> GiNaC::archive::exprtable
mutableprivate

Map of stored expressions to nodes for faster archiving.

Definition at line 337 of file archive.h.

Referenced by add_node(), and clear().


The documentation for this class was generated from the following files:

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