]> www.ginac.de Git - ginac.git/blobdiff - ginac/lorentzidx.cpp
- Fixed a thinko in atan(const numeric &).
[ginac.git] / ginac / lorentzidx.cpp
index 56b4358c4c86f4b10208d9234e471ba6d6b7f73a..9a0aa7bd34a854e6886a2323f840fd7568cbfa26 100644 (file)
 #include <stdexcept>
 
 #include "lorentzidx.h"
+#include "lst.h"
+#include "archive.h"
 #include "utils.h"
 #include "debugmsg.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -50,13 +54,13 @@ lorentzidx::~lorentzidx()
     destroy(0);
 }
 
-lorentzidx::lorentzidx(lorentzidx const & other)
+lorentzidx::lorentzidx(const lorentzidx & other)
 {
     debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
     copy(other);
 }
 
-lorentzidx const & lorentzidx::operator=(lorentzidx const & other)
+const lorentzidx & lorentzidx::operator=(const lorentzidx & other)
 {
     debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
     if (this != &other) {
@@ -68,16 +72,16 @@ lorentzidx const & lorentzidx::operator=(lorentzidx const & other)
 
 // protected
 
-void lorentzidx::copy(lorentzidx const & other)
+void lorentzidx::copy(const lorentzidx & other)
 {
-    idx::copy(other);
+    inherited::copy(other);
     orthogonal_only=other.orthogonal_only;
     dim_parallel_space=other.dim_parallel_space;
 }
 
 void lorentzidx::destroy(bool call_parent)
 {
-    if (call_parent) idx::destroy(call_parent);
+    if (call_parent) inherited::destroy(call_parent);
 }
 
 //////////
@@ -99,7 +103,7 @@ lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) :
     tinfo_key=TINFO_lorentzidx;
 }
 
-lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp)
+lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
     debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
@@ -107,7 +111,7 @@ lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp)
     tinfo_key=TINFO_lorentzidx;
 }
 
-lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp)
+lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
     debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
@@ -115,13 +119,50 @@ lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp)
     tinfo_key=TINFO_lorentzidx;
 }
 
-lorentzidx::lorentzidx(unsigned const v, bool cov) : idx(v,cov),
+lorentzidx::lorentzidx(unsigned v, bool cov) : idx(v,cov),
     orthogonal_only(false), dim_parallel_space(0)
 {
     debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_lorentzidx;
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
+    n.find_bool("orthogonal_only", orthogonal_only);
+       if (orthogonal_only)
+               n.find_unsigned("pdim", dim_parallel_space);
+}
+
+/** Unarchive the object. */
+ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
+
+    if (ex_to_lorentzidx(s).symbolic) {
+        // If lorentzidx is in sym_lst, return the existing lorentzidx
+        for (unsigned i=0; i<sym_lst.nops(); i++) {
+            if (is_ex_of_type(sym_lst.op(i), lorentzidx) && (ex_to_lorentzidx(sym_lst.op(i)).name == ex_to_lorentzidx(s).name))
+                return sym_lst.op(i);
+        }
+    }
+    return s;
+}
+
+/** Archive the object. */
+void lorentzidx::archive(archive_node &n) const
+{
+    inherited::archive(n);
+       n.add_bool("orthogonal_only", orthogonal_only);
+       if (orthogonal_only)
+               n.add_unsigned("pdim", dim_parallel_space);
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////
@@ -134,7 +175,7 @@ basic * lorentzidx::duplicate() const
     return new lorentzidx(*this);
 }
 
-void lorentzidx::printraw(ostream & os) const
+void lorentzidx::printraw(std::ostream & os) const
 {
     debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
 
@@ -164,11 +205,11 @@ void lorentzidx::printraw(ostream & os) const
     os << ")";
 }
 
-void lorentzidx::printtree(ostream & os, unsigned indent) const
+void lorentzidx::printtree(std::ostream & os, unsigned indent) const
 {
     debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
 
-    os << string(indent,' ') << "lorentzidx: ";
+    os << std::string(indent,' ') << "lorentzidx: ";
 
     if (symbolic) {
         os << "symbolic,name=" << name;
@@ -190,11 +231,12 @@ void lorentzidx::printtree(ostream & os, unsigned indent) const
     }
 
     os << ", serial=" << serial
-       << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
-       << ", flags=" << flags << endl;
+       << ", hash=" << hashvalue
+       << " (0x" << std::hex << hashvalue << std::dec << ")"
+       << ", flags=" << flags << std::endl;
 }
 
-void lorentzidx::print(ostream & os, unsigned upper_precedence) const
+void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
 {
     debugmsg("lorentzidx print",LOGLEVEL_PRINT);
 
@@ -213,7 +255,7 @@ void lorentzidx::print(ostream & os, unsigned upper_precedence) const
 bool lorentzidx::info(unsigned inf) const
 {
     if (inf==info_flags::lorentzidx) return true;
-    return idx::info(inf);
+    return inherited::info(inf);
 }
 
 //////////
@@ -251,8 +293,8 @@ lorentzidx lorentzidx::create_anonymous_representative(void) const
 //////////
 
 const lorentzidx some_lorentzidx;
-type_info const & typeid_lorentzidx=typeid(some_lorentzidx);
+const type_info & typeid_lorentzidx=typeid(some_lorentzidx);
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC