]> www.ginac.de Git - ginac.git/blobdiff - ginac/indexed.cpp
- Bernard Parisse's patch for Order_eval().
[ginac.git] / ginac / indexed.cpp
index 7fcd8939ef6d877bc0e9884532a24102b23ccddc..fb35d8c1819967e3b89228eb48b8763d175d258b 100644 (file)
@@ -1,8 +1,9 @@
 /** @file indexed.cpp
  *
- *  Implementation of GiNaC's index carrying objects.
- *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  Implementation of GiNaC's index carrying objects. */
+
+/*
+ *  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
 #include "indexed.h"
 #include "ex.h"
 #include "idx.h"
+#include "debugmsg.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(indexed, exprseq)
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -43,13 +51,13 @@ indexed::~indexed()
     destroy(0);
 }
 
-indexed::indexed(indexed const & other)
+indexed::indexed(const indexed & other)
 {
     debugmsg("indexed copy constructor",LOGLEVEL_CONSTRUCT);
     copy (other);
 }
 
-indexed const & indexed::operator=(indexed const & other)
+const indexed & indexed::operator=(const indexed & other)
 {
     debugmsg("indexed operator=",LOGLEVEL_ASSIGNMENT);
     if (this != &other) {
@@ -61,15 +69,15 @@ indexed const & indexed::operator=(indexed const & other)
 
 // protected
 
-void indexed::copy(indexed const & other)
+void indexed::copy(const indexed & other)
 {
-    exprseq::copy(other);
+    inherited::copy(other);
 }
 
 void indexed::destroy(bool call_parent)
 {
     if (call_parent) {
-        exprseq::destroy(call_parent);
+        inherited::destroy(call_parent);
     }
 }
 
@@ -79,40 +87,71 @@ void indexed::destroy(bool call_parent)
 
 // public
 
-indexed::indexed(ex const & i1) : exprseq(i1)
+indexed::indexed(const ex & i1) : inherited(i1)
 {
     debugmsg("indexed constructor from ex",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_indexed;
-    ASSERT(all_of_type_idx());
+    GINAC_ASSERT(all_of_type_idx());
 }
 
-indexed::indexed(ex const & i1, ex const & i2) : exprseq(i1,i2)
+indexed::indexed(const ex & i1, const ex & i2) : inherited(i1,i2)
 {
     debugmsg("indexed constructor from ex,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_indexed;
-    ASSERT(all_of_type_idx());
+    GINAC_ASSERT(all_of_type_idx());
 }
 
-indexed::indexed(ex const & i1, ex const & i2, ex const & i3)
-    : exprseq(i1,i2,i3)
+indexed::indexed(const ex & i1, const ex & i2, const ex & i3)
+    : inherited(i1,i2,i3)
 {
     debugmsg("indexed constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_indexed;
-    ASSERT(all_of_type_idx());
+    GINAC_ASSERT(all_of_type_idx());
+}
+
+indexed::indexed(const ex & i1, const ex & i2, const ex & i3, const ex & i4)
+    : inherited(i1,i2,i3,i4)
+{
+    debugmsg("indexed constructor from ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
+    tinfo_key=TINFO_indexed;
+    GINAC_ASSERT(all_of_type_idx());
 }
 
-indexed::indexed(exvector const & iv) : exprseq(iv)
+indexed::indexed(const exvector & iv) : inherited(iv)
 {
     debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_indexed;
-    ASSERT(all_of_type_idx());
+    GINAC_ASSERT(all_of_type_idx());
 }
 
-indexed::indexed(exvector * ivp) : exprseq(ivp)
+indexed::indexed(exvector * ivp) : inherited(ivp)
 {
     debugmsg("indexed constructor from exvector *",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_indexed;
-    ASSERT(all_of_type_idx());
+    GINAC_ASSERT(all_of_type_idx());
+}
+
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("indexed constructor from archive_node", LOGLEVEL_CONSTRUCT);
+    tinfo_key = TINFO_indexed;
+}
+
+/** Unarchive the object. */
+ex indexed::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated);
+}
+
+/** Archive the object. */
+void indexed::archive(archive_node &n) const
+{
+    inherited::archive(n);
 }
 
 //////////
@@ -127,7 +166,7 @@ basic * indexed::duplicate() const
     return new indexed(*this);
 }
 
-void indexed::printraw(ostream & os) const
+void indexed::printraw(std::ostream & os) const
 {
     debugmsg("indexed printraw",LOGLEVEL_PRINT);
     os << "indexed(indices=";
@@ -135,22 +174,22 @@ void indexed::printraw(ostream & os) const
     os << ",hash=" << hashvalue << ",flags=" << flags << ")";
 }
 
-void indexed::printtree(ostream & os, unsigned indent) const
+void indexed::printtree(std::ostream & os, unsigned indent) const
 {
     debugmsg("indexed printtree",LOGLEVEL_PRINT);
-    os << string(indent,' ') << "indexed: " << seq.size() << " indices";
-    os << ",hash=" << hashvalue << ",flags=" << flags << endl;
+    os << std::string(indent,' ') << "indexed: " << seq.size() << " indices";
+    os << ",hash=" << hashvalue << ",flags=" << flags << std::endl;
     printtreeindices(os,indent);
 }
 
-void indexed::print(ostream & os, unsigned upper_precedence) const
+void indexed::print(std::ostream & os, unsigned upper_precedence) const
 {
     debugmsg("indexed print",LOGLEVEL_PRINT);
     os << "UNNAMEDINDEX";
     printindices(os);
 }
 
-void indexed::printcsrc(ostream & os, unsigned type,
+void indexed::printcsrc(std::ostream & os, unsigned type,
                         unsigned upper_precedence) const
 {
     debugmsg("indexed print csrc",LOGLEVEL_PRINT);
@@ -161,7 +200,7 @@ bool indexed::info(unsigned inf) const
 {
     if (inf==info_flags::indexed) return true;
     if (inf==info_flags::has_indices) return seq.size()!=0;
-    return exprseq::info(inf);
+    return inherited::info(inf);
 }
 
 exvector indexed::get_indices(void) const
@@ -182,16 +221,23 @@ exvector indexed::get_indices(void) const
 
 // protected
 
-int indexed::compare_same_type(basic const & other) const
+/** Implementation of ex::diff() for an indexed object. It always returns 0.
+ *  @see ex::diff */
+ex indexed::derivative(const symbol & s) const
+{
+        return _ex0();
+}
+
+int indexed::compare_same_type(const basic & other) const
 {
-    ASSERT(is_of_type(other,indexed));
-    return exprseq::compare_same_type(other);
+    GINAC_ASSERT(is_of_type(other,indexed));
+    return inherited::compare_same_type(other);
 }
 
-bool indexed::is_equal_same_type(basic const & other) const
+bool indexed::is_equal_same_type(const basic & other) const
 {
-    ASSERT(is_of_type(other,indexed));
-    return exprseq::is_equal_same_type(other);
+    GINAC_ASSERT(is_of_type(other,indexed));
+    return inherited::is_equal_same_type(other);
 }
 
 unsigned indexed::return_type(void) const
@@ -204,7 +250,7 @@ unsigned indexed::return_type_tinfo(void) const
     return tinfo_key;
 }
 
-ex indexed::thisexprseq(exvector const & v) const
+ex indexed::thisexprseq(const exvector & v) const
 {
     return indexed(v);
 }
@@ -226,7 +272,7 @@ ex indexed::thisexprseq(exvector * vp) const
 
 // protected
 
-void indexed::printrawindices(ostream & os) const
+void indexed::printrawindices(std::ostream & os) const
 {
     if (seq.size()!=0) {
         for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -236,18 +282,18 @@ void indexed::printrawindices(ostream & os) const
     }
 }
 
-void indexed::printtreeindices(ostream & os, unsigned indent) const
+void indexed::printtreeindices(std::ostream & os, unsigned indent) const
 {
     if (seq.size()!=0) {
         for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-            os << string(indent+delta_indent,' ');
+            os << std::string(indent+delta_indent,' ');
             (*cit).printraw(os);
-            os << endl;
+            os << std::endl;
         }
     }
 }
 
-void indexed::printindices(ostream & os) const
+void indexed::printindices(std::ostream & os) const
 {
     if (seq.size()!=0) {
         if (seq.size()>1) {
@@ -286,5 +332,8 @@ bool indexed::all_of_type_idx(void) const
 //////////
 
 const indexed some_indexed;
-type_info const & typeid_indexed=typeid(some_indexed);
+const type_info & typeid_indexed=typeid(some_indexed);
 
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC