]> www.ginac.de Git - ginac.git/blobdiff - ginac/constant.cpp
- implemented global class registry (for class basic and derived classes)
[ginac.git] / ginac / constant.cpp
index fa7adf24a79f3cba630cbb10bd69c56b3bd6cd25..1e9a4c15a4b9a10f904aa0a4c2a4c53ad60e67b5 100644 (file)
 #include "constant.h"
 #include "numeric.h"
 #include "ex.h"
+#include "archive.h"
 #include "debugmsg.h"
 
 #ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(constant, basic)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -101,6 +104,42 @@ constant::constant(string const & initname, numeric const & initnumber) :
     debugmsg("constant constructor from string, numeric",LOGLEVEL_CONSTRUCT);
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+constant::constant(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("constant constructor from archive_node", LOGLEVEL_CONSTRUCT);
+}
+
+/** Unarchive the object. */
+ex constant::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    // Find constant by name (!! this is bad: 'twould be better if there
+    // was a list of all global constants that we could search)
+    string s;
+    if (n.find_string("name", s)) {
+        if (s == Pi.name)
+            return Pi;
+        else if (s == Catalan.name)
+            return Catalan;
+        else if (s == EulerGamma.name)
+            return EulerGamma;
+        else
+            throw (std::runtime_error("unknown constant '" + s + "' in archive"));
+    } else
+        throw (std::runtime_error("unnamed constant in archive"));
+}
+
+/** Archive the object. */
+void constant::archive(archive_node &n) const
+{
+    inherited::archive(n);
+    n.add_string("name", name);
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////