X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fstructure.h;h=867cd42dd2cb786ead3d346ba72dfad0872ab5c3;hp=41b243ac343ecd005db8b0d143c07dfd8d93944a;hb=e45f9fca76b81e01ffa5edc417c29538fa05147b;hpb=5ef801553eb39aed7bd2df9dd1aff9d752c3ea9d diff --git a/ginac/structure.h b/ginac/structure.h index 41b243ac..867cd42d 100644 --- a/ginac/structure.h +++ b/ginac/structure.h @@ -3,7 +3,7 @@ * Wrapper template for making GiNaC classes out of C++ structures. */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2011 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 @@ -17,21 +17,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __GINAC_STRUCTURE_H__ -#define __GINAC_STRUCTURE_H__ - -#include +#ifndef GINAC_STRUCTURE_H +#define GINAC_STRUCTURE_H #include "ex.h" +#include "ncmul.h" +#include "numeric.h" +#include "operators.h" #include "print.h" -namespace GiNaC { - -extern unsigned next_structure_tinfo_key; +#include +namespace GiNaC { /** Comparison policy: all structures of one type are equal */ template @@ -116,13 +116,11 @@ class structure : public basic, public ComparisonPolicy { GINAC_DECLARE_REGISTERED_CLASS(structure, basic) // helpers - static unsigned get_tinfo() { return reg_info.tinfo_key; } static const char *get_class_name() { return "structure"; } - // constructors public: /** Construct structure as a copy of a given C++ structure. */ - structure(const T & t) : inherited(get_tinfo()), obj(t) { } + structure(const T & t) : obj(t) { } // functions overriding virtual functions from base classes // All these are just defaults that can be specialized by the user @@ -153,8 +151,8 @@ public: ex & operator[](size_t i) { return inherited::operator[](i); } // pattern matching - bool has(const ex & other) const { return inherited::has(other); } - bool match(const ex & pattern, lst & repl_lst) const { return inherited::match(pattern, repl_lst); } + bool has(const ex & other, unsigned options = 0) const { return inherited::has(other, options); } + bool match(const ex & pattern, exmap& repl_lst) const { return inherited::match(pattern, repl_lst); } protected: bool match_same_type(const basic & other) const { return true; } public: @@ -181,9 +179,9 @@ public: ex series(const relational & r, int order, unsigned options = 0) const { return inherited::series(r, order, options); } // rational functions - ex normal(exmap & repl, int level = 0) const { return inherited::normal(repl, level); } - ex to_rational(lst & repl_lst) const { return inherited::to_rational(repl_lst); } - ex to_polynomial(lst & repl_lst) const { return inherited::to_polynomial(repl_lst); } + ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const { return inherited::normal(repl, rev_lookup, level); } + ex to_rational(exmap & repl) const { return inherited::to_rational(repl); } + ex to_polynomial(exmap & repl) const { return inherited::to_polynomial(repl); } // polynomial algorithms numeric integer_content() const { return 1; } @@ -193,12 +191,18 @@ public: // indexed objects exvector get_free_indices() const { return exvector(); } ex add_indexed(const ex & self, const ex & other) const { return self + other; } - ex scalar_mul_indexed(const ex & self, const numeric & other) const { return self * other; } + ex scalar_mul_indexed(const ex & self, const numeric & other) const { return self * ex(other); } bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { return false; } // noncommutativity unsigned return_type() const { return return_types::commutative; } - unsigned return_type_tinfo() const { return tinfo(); } + return_type_t return_type_tinfo() const + { + return_type_t r; + r.rl = 0; + r.tinfo = &typeid(*this); + return r; + } protected: bool is_equal_same_type(const basic & other) const @@ -206,7 +210,7 @@ protected: GINAC_ASSERT(is_a(other)); const structure & o = static_cast(other); - return struct_is_equal(&obj, &o.obj); + return this->struct_is_equal(&obj, &o.obj); } unsigned calchash() const { return inherited::calchash(); } @@ -217,7 +221,6 @@ public: const T *operator->() const { return &obj; } T &get_struct() { return obj; } const T &get_struct() const { return obj; } - private: T obj; }; @@ -225,25 +228,7 @@ private: /** Default constructor */ template class CP> -structure::structure() : inherited(get_tinfo()) { } - -/** Construct object from archive_node. */ -template class CP> -structure::structure(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst) {} - -/** Unarchive the object. */ -template class CP> -ex structure::unarchive(const archive_node &n, lst &sym_lst) -{ - return (new structure(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -template class CP> -void structure::archive(archive_node &n) const -{ - inherited::archive(n); -} +structure::structure() { } /** Compare two structures of the same type. */ template class CP> @@ -252,16 +237,12 @@ int structure::compare_same_type(const basic & other) const GINAC_ASSERT(is_a(other)); const structure & o = static_cast(other); - return struct_compare(&obj, &o.obj); + return this->struct_compare(&obj, &o.obj); } template class CP> -registered_class_info structure::reg_info(structure::get_class_name(), "basic", next_structure_tinfo_key++, &structure::unarchive); - -template class CP> -const char *structure::class_name() const { return reg_info.name; } - +registered_class_info structure::reg_info = registered_class_info(registered_class_options(structure::get_class_name(), "basic", typeid(structure))); } // namespace GiNaC -#endif // ndef __GINAC_STRUCTURE_H__ +#endif // ndef GINAC_STRUCTURE_H