43 exprs.emplace_back(ae);
59 return nodes.size() - 1;
64 return nodes.size()-1;
71 if (
id >=
nodes.size())
72 throw (std::range_error(
"archive::get_node(): archive node ID out of range"));
81 std::string name_string = name;
89 throw (std::runtime_error(
"expression with name '" + name_string +
"' not found in archive"));
93 lst sym_lst_copy = sym_lst;
94 return nodes[i->root].unarchive(sym_lst_copy);
99 if (index >=
exprs.size())
100 throw (std::range_error(
"index of archived expression out of range"));
103 lst sym_lst_copy = sym_lst;
104 return nodes[
exprs[index].root].unarchive(sym_lst_copy);
109 if (index >=
exprs.size())
110 throw (std::range_error(
"index of archived expression out of range"));
116 lst sym_lst_copy = sym_lst;
117 return nodes[
exprs[index].root].unarchive(sym_lst_copy);
127 if (index >=
exprs.size())
128 throw (std::range_error(
"index of archived expression out of range"));
176 while (val >= 0x80) {
177 os.put((val & 0x7f) | 0x80);
193 ret |= (b & 0x7f) << shift;
203 unsigned num_props =
n.props.size();
205 for (
unsigned i=0; i<num_props; i++) {
223 unsigned num_atoms = ar.
atoms.size();
225 for (
unsigned i=0; i<num_atoms; i++)
226 os << ar.
atoms[i] << std::ends;
229 unsigned num_exprs = ar.
exprs.size();
231 for (
unsigned i=0; i<num_exprs; i++) {
237 unsigned num_nodes = ar.
nodes.size();
239 for (
unsigned i=0; i<num_nodes; i++)
249 n.props.resize(num_props);
250 for (
unsigned i=0; i<num_props; i++) {
253 n.props[i].name = name_type >> 3;
264 is.get(c1); is.get(c2); is.get(c3); is.get(c4);
265 if (c1 !=
'G' || c2 !=
'A' || c3 !=
'R' || c4 !=
'C')
266 throw (std::runtime_error(
"not a GiNaC archive (signature not found)"));
270 if ((version > max_version) || (version < min_version))
271 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)));
275 ar.
atoms.resize(num_atoms);
276 for (
unsigned i=0; i<num_atoms; i++) {
277 getline(is, ar.
atoms[i],
'\0');
283 ar.
exprs.resize(num_exprs);
284 for (
unsigned i=0; i<num_exprs; i++) {
292 ar.
nodes.resize(num_nodes, ar);
293 for (
unsigned i=0; i<num_nodes; i++)
318 if (
id >=
atoms.size())
319 throw (std::range_error(
"archive::unatomize(): atom ID out of range"));
328 if (
this != &other) {
340 : a(ar), has_expression(true), e(expr)
342 expr.
bp->archive(*
this);
353 return e.
bp == other.
e.
bp;
360 for (
auto i=
props.begin(); i!=
props.end(); ++i)
361 if (i->name == name_atom)
372 if (i->name == name_atom)
384 for (
auto i=
props.begin(); i!=
props.end(); ++i) {
385 if (i->name == name1_atom && range.
begin ==
props.end()) {
388 if (i->name == name2_atom && range.
begin !=
props.end()) {
422 unsigned found_index = 0;
424 if (i->type ==
PTYPE_BOOL && i->name == name_atom) {
425 if (found_index == index) {
440 unsigned found_index = 0;
443 if (found_index == index) {
458 unsigned found_index = 0;
461 if (found_index == index) {
481 unsigned found_index = 0;
483 if (i->type ==
PTYPE_NODE && i->name == name_atom) {
484 if (found_index == index) {
499 unsigned found_index = 0;
501 if (i->type ==
PTYPE_NODE && i->name == name_atom) {
502 if (found_index == index)
508 throw (std::runtime_error(
"property with name '" + name +
"' not found in archive node"));
520 auto a = v.begin(), aend = v.end();
523 if (
a->type == type &&
a->name == name) {
551 std::string class_name;
553 throw (std::runtime_error(
"archive node contains no class name"));
559 obj->read_archive(*
this, sym_lst);
577 unarchive_map_t::const_iterator i =
unarch_map->find(classname);
580 throw std::runtime_error(std::string(
"no unarchiving function for \"")
581 + classname +
"\" class");
587 throw std::runtime_error(std::string(
"Class \"" + classname
588 +
"\" is already registered"));
629 std::vector<std::string>::const_iterator i =
atoms.begin(), iend =
atoms.end();
632 os <<
" " <<
id <<
" " << *i << std::endl;
639 os <<
"Expressions:\n";
644 os <<
" " << index <<
" \"" <<
unatomize(i->name) <<
"\" root node " << i->root << std::endl;
656 os <<
" " <<
id <<
" ";
668 os <<
"(basic * " <<
e.
bp <<
" = " <<
e <<
")\n";
681 default: os <<
"<unknown>";
break;
683 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.
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