]> www.ginac.de Git - ginac.git/blobdiff - ginac/archive.cpp
- archive file format is a little more compact (stores property name and type
[ginac.git] / ginac / archive.cpp
index dfc00cee9f6cc7d923ff3ad343cb3089dd51a350..058264d9150a82ac4b78b050748b632b26005bf5 100644 (file)
@@ -3,7 +3,7 @@
  *  Archiving of GiNaC expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -29,9 +29,9 @@
 #include "config.h"
 #include "utils.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 
 /** Archive an expression.
@@ -144,8 +144,8 @@ unsigned int archive::num_expressions(void) const
  *      - unsigned root node ID
  *   - unsigned number of nodes
  *      - unsigned number of properties
- *        - unsigned type (PTYPE_*)
- *        - unsigned name atom
+ *        - unsigned containing type (PTYPE_*) in its lower 3 bits and
+ *          name atom in the upper bits
  *        - unsigned property value
  *
  *  Unsigned quantities are stored in a compressed format:
@@ -202,10 +202,10 @@ ostream &operator<<(ostream &os, const archive_node &n)
        unsigned int num_props = n.props.size();
        write_unsigned(os, num_props);
        for (unsigned int i=0; i<num_props; i++) {
-               write_unsigned(os, n.props[i].type);
-               write_unsigned(os, n.props[i].name);
+               write_unsigned(os, n.props[i].type | (n.props[i].name << 3));
                write_unsigned(os, n.props[i].value);
        }
+    return os;
 }
 
 /** Write archive to binary data stream. */
@@ -237,6 +237,7 @@ ostream &operator<<(ostream &os, const archive &ar)
        write_unsigned(os, num_nodes);
        for (unsigned int i=0; i<num_nodes; i++)
                os << ar.nodes[i];
+    return os;
 }
 
 /** Read archive_node from binary data stream. */
@@ -246,10 +247,12 @@ istream &operator>>(istream &is, archive_node &n)
        unsigned int num_props = read_unsigned(is);
        n.props.resize(num_props);
        for (unsigned int i=0; i<num_props; i++) {
-               n.props[i].type = (archive_node::property_type)read_unsigned(is);
-               n.props[i].name = read_unsigned(is);
+               unsigned int name_type = read_unsigned(is);
+               n.props[i].type = (archive_node::property_type)(name_type & 7);
+               n.props[i].name = name_type >> 3;
                n.props[i].value = read_unsigned(is);
        }
+    return is;
 }
 
 /** Read archive from binary data stream. */
@@ -284,6 +287,7 @@ istream &operator>>(istream &is, archive &ar)
        ar.nodes.resize(num_nodes, ar);
        for (unsigned int i=0; i<num_nodes; i++)
                is >> ar.nodes[i];
+    return is;
 }
 
 
@@ -511,8 +515,8 @@ void archive_node::forget(void)
 }
 
 
-/** Dump archive to stream (for debugging). */
-void archive::dump(ostream &os) const
+/** Print archive to stream in ugly raw format (for debugging). */
+void archive::printraw(ostream &os) const
 {
        // Dump atoms
        os << "Atoms:\n";
@@ -545,20 +549,20 @@ void archive::dump(ostream &os) const
                archive_node_id id = 0;
                while (i != iend) {
                        os << " " << id << " ";
-                       i->dump(os);
+                       i->printraw(os);
                        i++; id++;
                }
        }
 }
 
-/** Dump archive_node to stream (for debugging). */
-void archive_node::dump(ostream &os) const
+/** Output archive_node to stream in ugly raw format (for debugging). */
+void archive_node::printraw(ostream &os) const
 {
        // Dump cached unarchived expression
        if (has_expression)
                os << "(basic * " << e.bp << " = " << e << ")\n";
        else
-               os << "(no expression)\n";
+               os << "\n";
 
        // Dump properties
        vector<property>::const_iterator i = props.begin(), iend = props.end();
@@ -576,7 +580,15 @@ void archive_node::dump(ostream &os) const
        }
 }
 
+/** Create a dummy archive.  The intention is to fill archive_node's default ctor,
+ *  which is currently a Cint-requirement. */
+archive* archive_node::dummy_ar_creator(void)
+{
+    static archive* some_ar = new archive;
+    return some_ar;
+}
+
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC