41 exprs.emplace_back(ae);
57 return nodes.size() - 1;
62 return nodes.size()-1;
69 if (
id >=
nodes.size())
70 throw (std::range_error(
"archive::get_node(): archive node ID out of range"));
79 std::string name_string = name;
87 throw (std::runtime_error(
"expression with name '" + name_string +
"' not found in archive"));
91 lst sym_lst_copy = sym_lst;
92 return nodes[i->root].unarchive(sym_lst_copy);
97 if (index >=
exprs.size())
98 throw (std::range_error(
"index of archived expression out of range"));
101 lst sym_lst_copy = sym_lst;
102 return nodes[
exprs[index].root].unarchive(sym_lst_copy);
107 if (index >=
exprs.size())
108 throw (std::range_error(
"index of archived expression out of range"));
114 lst sym_lst_copy = sym_lst;
115 return nodes[
exprs[index].root].unarchive(sym_lst_copy);
125 if (index >=
exprs.size())
126 throw (std::range_error(
"index of archived expression out of range"));
174 while (val >= 0x80) {
175 os.put((val & 0x7f) | 0x80);
191 ret |= (b & 0x7f) << shift;
201 unsigned num_props =
n.
props.size();
203 for (
unsigned i=0; i<num_props; i++) {
221 unsigned num_atoms = ar.
atoms.size();
223 for (
unsigned i=0; i<num_atoms; i++)
224 os << ar.
atoms[i] << std::ends;
227 unsigned num_exprs = ar.
exprs.size();
229 for (
unsigned i=0; i<num_exprs; i++) {
235 unsigned num_nodes = ar.
nodes.size();
237 for (
unsigned i=0; i<num_nodes; i++)
247 n.props.resize(num_props);
248 for (
unsigned i=0; i<num_props; i++) {
251 n.props[i].name = name_type >> 3;
262 is.get(c1); is.get(c2); is.get(c3); is.get(c4);
263 if (c1 !=
'G' || c2 !=
'A' || c3 !=
'R' || c4 !=
'C')
264 throw (std::runtime_error(
"not a GiNaC archive (signature not found)"));
268 if ((version > max_version) || (version < min_version))
269 throw (std::runtime_error(
"archive version " + std::to_string(version) +
" cannot be read by this GiNaC library (which supports versions " + std::to_string(min_version) +
" thru " + std::to_string(max_version)));
273 ar.
atoms.resize(num_atoms);
274 for (
unsigned i=0; i<num_atoms; i++) {
275 getline(is, ar.
atoms[i],
'\0');
281 ar.
exprs.resize(num_exprs);
282 for (
unsigned i=0; i<num_exprs; i++) {
290 ar.
nodes.resize(num_nodes, ar);
291 for (
unsigned i=0; i<num_nodes; i++)
316 if (
id >=
atoms.size())
317 throw (std::range_error(
"archive::unatomize(): atom ID out of range"));
326 if (
this != &other) {
338 : a(ar), has_expression(true), e(expr)
340 expr.
bp->archive(*
this);
351 return e.
bp == other.
e.
bp;
358 for (
auto i=
props.begin(); i!=
props.end(); ++i)
359 if (i->name == name_atom)
370 if (i->name == name_atom)
382 for (
auto i=
props.begin(); i!=
props.end(); ++i) {
383 if (i->name == name1_atom && range.
begin ==
props.end()) {
386 if (i->name == name2_atom && range.
begin !=
props.end()) {
420 unsigned found_index = 0;
422 if (i->type ==
PTYPE_BOOL && i->name == name_atom) {
423 if (found_index == index) {
438 unsigned found_index = 0;
441 if (found_index == index) {
456 unsigned found_index = 0;
459 if (found_index == index) {
479 unsigned found_index = 0;
481 if (i->type ==
PTYPE_NODE && i->name == name_atom) {
482 if (found_index == index) {
497 unsigned found_index = 0;
499 if (i->type ==
PTYPE_NODE && i->name == name_atom) {
500 if (found_index == index)
506 throw (std::runtime_error(
"property with name '" + name +
"' not found in archive node"));
518 auto a = v.begin(), aend = v.end();
521 if (
a->type == type &&
a->name == name) {
549 std::string class_name;
551 throw (std::runtime_error(
"archive node contains no class name"));
557 obj->read_archive(*
this, sym_lst);
575 unarchive_map_t::const_iterator i =
unarch_map->find(classname);
578 throw std::runtime_error(std::string(
"no unarchiving function for \"")
579 + classname +
"\" class");
585 throw std::runtime_error(std::string(
"Class \"" + classname
586 +
"\" is already registered"));
627 std::vector<std::string>::const_iterator i =
atoms.
begin(), iend =
atoms.end();
630 os <<
" " <<
id <<
" " << *i << std::endl;
637 os <<
"Expressions:\n";
642 os <<
" " << index <<
" \"" <<
unatomize(i->name) <<
"\" root node " << i->root << std::endl;
654 os <<
" " <<
id <<
" ";
666 os <<
"(basic * " <<
e.
bp <<
" = " <<
e <<
")\n";
679 default: os <<
"<unknown>";
break;
681 os <<
" \"" <<
a.
unatomize(i->name) <<
"\" " << i->value << std::endl;
Archiving of GiNaC expressions.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
void printraw(std::ostream &os) const
Output archive_node to stream in ugly raw format (for debugging).
std::vector< property > props
Vector of stored properties.
property_type
Property data types.
void get_properties(propinfovector &v) const
Return vector of properties stored in node.
bool has_expression
Flag indicating whether a cached unarchived representation of this node exists.
bool find_unsigned(const std::string &name, unsigned &ret, unsigned index=0) const
Retrieve property of type "unsigned" from node.
void add_unsigned(const std::string &name, unsigned value)
Add property of type "unsigned int" to node.
bool find_ex(const std::string &name, ex &ret, lst &sym_lst, unsigned index=0) const
Retrieve property of type "ex" from node.
bool has_same_ex_as(const archive_node &other) const
Check if the archive_node stores the same expression as another archive_node.
void find_ex_by_loc(archive_node_cit loc, ex &ret, lst &sym_lst) const
Retrieve property of type "ex" from the node if it is known that this node in fact contains such a pr...
bool find_bool(const std::string &name, bool &ret, unsigned index=0) const
Retrieve property of type "bool" from node.
void forget()
Delete cached unarchived expressions from node (for debugging).
std::vector< property >::const_iterator archive_node_cit
archive_node(archive &ar)
const archive_node & find_ex_node(const std::string &name, unsigned index=0) const
Retrieve property of type "ex" from node, returning the node of the sub-expression.
std::vector< property_info > propinfovector
bool find_string(const std::string &name, std::string &ret, unsigned index=0) const
Retrieve property of type "string" from node.
void add_ex(const std::string &name, const ex &value)
Add property of type "ex" to node.
void add_bool(const std::string &name, bool value)
Add property of type "bool" to node.
archive_node_cit_range find_property_range(const std::string &name1, const std::string &name2) const
Find a range of locations in the vector of properties.
ex e
The cached unarchived representation of this node (if any).
archive_node_cit find_last(const std::string &name) const
const archive_node & operator=(const archive_node &other)
Assignment operator of archive_node.
archive_node_cit find_first(const std::string &name) const
Find the location in the vector of properties of the first/last property with a given name.
archive & a
Reference to the archive to which this node belongs.
ex unarchive(lst &sym_lst) const
Convert archive node to GiNaC expression.
void add_string(const std::string &name, const std::string &value)
Add property of type "string" to node.
This class holds archived versions of GiNaC expressions (class ex).
archive_node_id add_node(const archive_node &n)
Add archive_node to archive if the corresponding expression is not already archived.
archive_atom atomize(const std::string &s) const
Atomize a string (i.e.
void forget()
Delete cached unarchived expressions in all archive_nodes (mainly for debugging).
ex unarchive_ex(const lst &sym_lst, const char *name) const
Retrieve expression from archive by name.
void clear()
Clear all archived expressions.
void archive_ex(const ex &e, const char *name)
Archive an expression.
unsigned num_expressions() const
Return number of archived expressions.
const std::string & unatomize(archive_atom id) const
Unatomize a string (i.e.
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.
std::map< ex, archive_node_id, ex_is_less > exprtable
Map of stored expressions to nodes for faster archiving.
const archive_node & get_top_node(unsigned index=0) const
Return reference to top node of an expression specified by index.
std::vector< archive_node > nodes
Vector of archived nodes.
archive_node & get_node(archive_node_id id)
Retrieve archive_node by ID.
void printraw(std::ostream &os) const
Print archive to stream in ugly raw format (for debugging).
std::vector< archived_ex > exprs
Vector of archived expression descriptors.
std::vector< std::string > atoms
Vector of atomized strings (using a vector allows faster unarchiving).
std::map< std::string, archive_atom > inverse_atoms
Wrapper template for making GiNaC classes out of STL containers.
Lightweight wrapper for GiNaC's symbolic objects.
const_iterator begin() const noexcept
ptr< basic > bp
pointer to basic object managed by this
Class of (intrusively) reference-counted pointers that support copy-on-write semantics.
@ dynallocated
heap-allocated (i.e. created by new if we want to be clever and bypass the stack,
void insert(const std::string &classname, synthesize_func f)
synthesize_func find(const std::string &classname) const
static unarchive_map_t * unarch_map
Interface to GiNaC's light-weight expression handles.
Definition of GiNaC's lst.
unsigned archive_atom
Numerical ID value to refer to a string.
std::ostream & operator<<(std::ostream &os, const archive_node &n)
Write archive_node to binary data stream.
std::map< std::string, synthesize_func > unarchive_map_t
basic *(* synthesize_func)()
unsigned archive_node_id
Numerical ID value to refer to an archive_node.
static void write_unsigned(std::ostream &os, unsigned val)
Write unsigned integer quantity to stream.
static unsigned read_unsigned(std::istream &is)
Read unsigned integer quantity from stream.
std::istream & operator>>(std::istream &is, archive_node &n)
Read archive_node from binary data stream.
static synthesize_func find_factory_fcn(const std::string &name)
GiNaC's class registrar (for class basic and all classes derived from it).
Archived expression descriptor.
Information about a stored property.
Archived property (data type, name and associated data)
GiNaC library version information.
#define GINACLIB_ARCHIVE_AGE
#define GINACLIB_ARCHIVE_VERSION