]> www.ginac.de Git - ginac.git/blobdiff - ginac/structure.cpp
fixed a bug where quo() would call vector::reserve() with a negative argument
[ginac.git] / ginac / structure.cpp
index e7cb8303bb59fa8c67ce184e9d4f4d7097ab7eed..1122c212e730b0430ab06e82e476e3ef192f2b4e 100644 (file)
@@ -1,8 +1,9 @@
 /** @file structure.cpp
  *
- *  Implementation of 'abstract' class structure.
- *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  Implementation of 'abstract' class structure. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2001 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
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <iostream>
 #include <string>
 
 #include "structure.h"
+#include "archive.h"
+#include "utils.h"
+#include "print.h"
 
-//////////
-// default constructor, destructor, copy constructor assignment operator and helpers
-//////////
-
-// public
-
-structure::structure()
-{
-    debugmsg("structure default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_structure;
-}
-
-structure::~structure()
-{
-    debugmsg("structure destructor",LOGLEVEL_DESTRUCT);
-    destroy(0);
-}
-
-structure::structure(structure const & other)
-{
-    debugmsg("structure copy constructor",LOGLEVEL_CONSTRUCT);
-    copy(other);
-}
-
-structure const & structure::operator=(structure const & other)
-{
-    debugmsg("structure operator=",LOGLEVEL_ASSIGNMENT);
-    if (this != &other) {
-        destroy(1);
-        copy(other);
-    }
-    return *this;
-}
-
-// protected
-
-void structure::copy(structure const & other)
-{
-    basic::copy(other);
-}
+namespace GiNaC {
 
-void structure::destroy(bool call_parent)
-{
-    if (call_parent) basic::destroy(call_parent);
-}
+GINAC_IMPLEMENT_REGISTERED_CLASS(structure, basic)
 
 //////////
-// other constructors
+// default ctor, dtor, copy ctor, assignment operator and helpers
 //////////
 
-// none
+DEFAULT_CTORS(structure)
 
 //////////
-// structures overriding virtual structures from bases classes
+// archiving
 //////////
 
-// public
+DEFAULT_ARCHIVING(structure)
 
-basic * structure::duplicate() const
-{
-    debugmsg("structure duplicate",LOGLEVEL_DUPLICATE);
-    return new structure(*this);
-}
-
-void structure::printraw(ostream & os) const
-{
-    debugmsg("structure printraw",LOGLEVEL_PRINT);
-
-    os << "structure(hash=" << hashvalue << ",flags=" << flags << ")";
-}
-
-void structure::print(ostream & os, unsigned upper_precedence) const
-{
-    debugmsg("structure print",LOGLEVEL_PRINT);
-
-    os << "structure()";
-}
+//////////
+// functions overriding virtual functions from base classes
+//////////
 
-void structure::printtree(ostream & os, unsigned indent) const
+void structure::print(const print_context & c, unsigned level) const
 {
-    debugmsg("structure printtree",LOGLEVEL_PRINT);
+       if (is_a<print_tree>(c)) {
 
-    os << string(indent,' ') << "structure "
-       << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
-       << ", flags=" << flags << endl;
-}
+               c.s << std::string(level, ' ') << class_name()
+                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+                   << std::endl;
 
-void structure::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
-{
-    debugmsg("structure print csrc",LOGLEVEL_PRINT);
-
-    os << "structure()";
+       } else
+               c.s << class_name() << "()";
 }
 
 // protected
 
-int structure::compare_same_type(basic const & other) const
-{
-    ASSERT(is_of_type(other, structure));
-    return 0; // all structures are the same
-}
+DEFAULT_COMPARE(structure)
 
-bool structure::is_equal_same_type(basic const & other) const
+bool structure::is_equal_same_type(const basic & other) const
 {
-    ASSERT(is_of_type(other, structure));
-    return true; // all structures are the same
+       GINAC_ASSERT(is_a<structure>(other));
+       return true; // all structures are the same
 }
 
 //////////
-// new virtual structures which can be overridden by derived classes
-//////////
-
-// none
-
-//////////
-// non-virtual structures in this class
+// non-virtual functions in this class
 //////////
 
 // protected
 
-vector<registered_structure_info> & structure::registered_structures(void)
+std::vector<registered_structure_info> & structure::registered_structures(void)
 {
-    static vector<registered_structure_info> * rs=new vector<registered_structure_info>;
-    return *rs;
+       static std::vector<registered_structure_info> * rs = new std::vector<registered_structure_info>;
+       return *rs;
 }
 
 // public
 
-unsigned structure::register_new(char const * nm)
+unsigned structure::register_new(const char * nm)
 {
-    registered_structure_info rsi={nm};
-    registered_structures().push_back(rsi);
-    return registered_structures().size()-1;
+       registered_structure_info rsi={nm};
+       registered_structures().push_back(rsi);
+       return registered_structures().size()-1;
 }
 
-//////////
-// static member variables
-//////////
-
-// none
-
-//////////
-// global constants
-//////////
-
-const structure some_structure;
-type_info const & typeid_structure=typeid(some_structure);
-
+} // namespace GiNaC