]> www.ginac.de Git - ginac.git/commitdiff
A better return_type_tinfo() mechanism.
authorAlexei Sheplyakov <varg@theor.jinr.ru>
Fri, 17 Oct 2008 09:15:03 +0000 (13:15 +0400)
committerAlexei Sheplyakov <varg@theor.jinr.ru>
Sun, 19 Oct 2008 17:29:11 +0000 (21:29 +0400)
return_type_tinfo() is used in order to distingish between non-commutative
objects of different type. However, often it's necessary to distingish
between non-commutative objects of the same type, for example, between
gamma matrices with different representation label. return_type_tinfo()
does not provide any clean way to do that. Hence, introduce return_type_t
type which holds representation label along with type information, and
use it for return_type_tinfo().

25 files changed:
ginac/add.cpp
ginac/add.h
ginac/basic.cpp
ginac/basic.h
ginac/clifford.cpp
ginac/clifford.h
ginac/color.cpp
ginac/color.h
ginac/ex.h
ginac/function.pl
ginac/indexed.h
ginac/integral.cpp
ginac/integral.h
ginac/mul.cpp
ginac/mul.h
ginac/ncmul.cpp
ginac/ncmul.h
ginac/power.cpp
ginac/power.h
ginac/registrar.h
ginac/relational.cpp
ginac/relational.h
ginac/structure.h
ginac/symbol.cpp
ginac/symbol.h

index 2fa73dc27d168068294b07bc19979f98454dcbda..547bee32d72b166c2ae95b292cd34b1c1c8455c5 100644 (file)
@@ -498,10 +498,10 @@ unsigned add::return_type() const
                return seq.begin()->rest.return_type();
 }
 
                return seq.begin()->rest.return_type();
 }
 
-tinfo_t add::return_type_tinfo() const
+return_type_t add::return_type_tinfo() const
 {
        if (seq.empty())
 {
        if (seq.empty())
-               return this;
+               return make_return_type_t<add>();
        else
                return seq.begin()->rest.return_type_tinfo();
 }
        else
                return seq.begin()->rest.return_type_tinfo();
 }
index 18f43517ccba195b7aee82e5cd07f0d4c5ccd204..d96e12637e477e0e5f4f2ab20cb795cefb1ad8fe 100644 (file)
@@ -65,7 +65,7 @@ public:
 protected:
        ex derivative(const symbol & s) const;
        unsigned return_type() const;
 protected:
        ex derivative(const symbol & s) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
        ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
        expair split_ex_to_pair(const ex & e) const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
        ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
        expair split_ex_to_pair(const ex & e) const;
index fa6e1d9679be426b90bd75acfee56c8babb4835b..567760c906f6c936fe832c6edddef772291aa832 100644 (file)
@@ -774,9 +774,12 @@ unsigned basic::return_type() const
        return return_types::commutative;
 }
 
        return return_types::commutative;
 }
 
-tinfo_t basic::return_type_tinfo() const
+return_type_t basic::return_type_tinfo() const
 {
 {
-       return tinfo_key;
+       return_type_t rt;
+       rt.tinfo = &typeid(*this);
+       rt.rl = 0;
+       return rt;
 }
 
 /** Compute the hash value of an object and if it makes sense to store it in
 }
 
 /** Compute the hash value of an object and if it makes sense to store it in
index 304adcfab2ee7c9d757d02feccbbe4415504535e..3685fb53ca920f6f5e8ebc4c1f5cb8d9c31982c6 100644 (file)
@@ -216,7 +216,7 @@ public:
 
        // noncommutativity
        virtual unsigned return_type() const;
 
        // noncommutativity
        virtual unsigned return_type() const;
-       virtual tinfo_t return_type_tinfo() const;
+       virtual return_type_t return_type_tinfo() const;
 
        // functions for complex expressions
        virtual ex conjugate() const;
 
        // functions for complex expressions
        virtual ex conjugate() const;
index c76fff234cf57bbbc24b9797c2bc96e1637a0f75..e66003728b50f856e8a71f748608e1ff6882c595 100644 (file)
@@ -46,8 +46,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed,
   print_func<print_dflt>(&clifford::do_print_dflt).
   print_func<print_latex>(&clifford::do_print_latex))
 
   print_func<print_dflt>(&clifford::do_print_dflt).
   print_func<print_latex>(&clifford::do_print_latex))
 
-const tinfo_static_t clifford::return_type_tinfo_static[256] = {{}};
-
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
   print_func<print_dflt>(&diracone::do_print).
   print_func<print_latex>(&diracone::do_print_latex))
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
   print_func<print_dflt>(&diracone::do_print).
   print_func<print_latex>(&diracone::do_print_latex))
@@ -120,6 +118,11 @@ clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_p
        tinfo_key = &clifford::tinfo_static;
 }
 
        tinfo_key = &clifford::tinfo_static;
 }
 
+return_type_t clifford::return_type_tinfo() const
+{
+       return make_return_type_t<clifford>(representation_label);
+}
+
 //////////
 // archiving
 //////////
 //////////
 // archiving
 //////////
@@ -811,19 +814,11 @@ ex dirac_slash(const ex & e, const ex & dim, unsigned char rl)
    return clifford(e, varidx(0, dim), indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl);
 }
 
    return clifford(e, varidx(0, dim), indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl);
 }
 
-/** Check whether a given tinfo key (as returned by return_type_tinfo()
- *  is that of a clifford object (with an arbitrary representation label). */
-bool is_clifford_tinfo(tinfo_t ti)
-{
-       p_int start_loc=(p_int)&clifford::return_type_tinfo_static;
-       return (p_int)ti>=start_loc && (p_int)ti<start_loc+256;
-}
-
 /** Extract representation label from tinfo key (as returned by
  *  return_type_tinfo()). */
 /** Extract representation label from tinfo key (as returned by
  *  return_type_tinfo()). */
-static unsigned char get_representation_label(tinfo_t ti)
+static unsigned char get_representation_label(const return_type_t& ti)
 {
 {
-       return (unsigned char)((p_int)ti-(p_int)&clifford::return_type_tinfo_static);
+       return (unsigned char)ti.rl;
 }
 
 /** Take trace of a string of an even number of Dirac gammas given a vector
 }
 
 /** Take trace of a string of an even number of Dirac gammas given a vector
index 62aabce91b1e6333fc268778cbeb1e7fa70ae3ef..59b49d0fa5a49985e26a4acca7d48ce82593dbbf 100644 (file)
@@ -41,9 +41,6 @@ namespace GiNaC {
 class clifford : public indexed
 {
        GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
 class clifford : public indexed
 {
        GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
-public:
-       static const tinfo_static_t return_type_tinfo_static[256];
-
        // other constructors
 public:
        clifford(const ex & b, unsigned char rl = 0);
        // other constructors
 public:
        clifford(const ex & b, unsigned char rl = 0);
@@ -62,8 +59,7 @@ protected:
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
-       tinfo_t return_type_tinfo() const { return clifford::return_type_tinfo_static+representation_label; }
-
+       return_type_t return_type_tinfo() const;
        // non-virtual functions in this class
 public:
        unsigned char get_representation_label() const { return representation_label; }
        // non-virtual functions in this class
 public:
        unsigned char get_representation_label() const { return representation_label; }
@@ -186,11 +182,14 @@ protected:
 
 // global functions
 
 
 // global functions
 
-/** Check whether a given tinfo key (as returned by return_type_tinfo()
+/** Check whether a given return_type_t object (as returned by return_type_tinfo()
   * is that of a clifford object (with an arbitrary representation label).
   *
   * @param ti tinfo key */
   * is that of a clifford object (with an arbitrary representation label).
   *
   * @param ti tinfo key */
-bool is_clifford_tinfo(tinfo_t ti);
+inline bool is_clifford_tinfo(const return_type_t& ti)
+{
+       return *(ti.tinfo) == typeid(clifford);
+}
 
 /** Create a Clifford unity object.
  *
 
 /** Create a Clifford unity object.
  *
index b70298b6214c55b0c94982dc3c76c72721180b4b..437686333b9263998942652a79bcaa56e76cf13b 100644 (file)
@@ -39,8 +39,6 @@ namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
 
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
 
-const tinfo_static_t color::return_type_tinfo_static[256] = {{}};
-
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3one, tensor,
   print_func<print_dflt>(&su3one::do_print).
   print_func<print_latex>(&su3one::do_print_latex))
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3one, tensor,
   print_func<print_dflt>(&su3one::do_print).
   print_func<print_latex>(&su3one::do_print_latex))
@@ -101,6 +99,11 @@ color::color(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(not_symme
        tinfo_key = &color::tinfo_static;
 }
 
        tinfo_key = &color::tinfo_static;
 }
 
+return_type_t color::return_type_tinfo() const
+{
+       return make_return_type_t<color>(representation_label);
+}
+
 //////////
 // archiving
 //////////
 //////////
 // archiving
 //////////
@@ -524,17 +527,16 @@ ex color_h(const ex & a, const ex & b, const ex & c)
 
 /** Check whether a given tinfo key (as returned by return_type_tinfo()
  *  is that of a color object (with an arbitrary representation label). */
 
 /** Check whether a given tinfo key (as returned by return_type_tinfo()
  *  is that of a color object (with an arbitrary representation label). */
-static bool is_color_tinfo(tinfo_t ti)
+static bool is_color_tinfo(const return_type_t& ti)
 {
 {
-       p_int start_loc=(p_int)&color::return_type_tinfo_static;
-       return (p_int)ti>=start_loc && (p_int)ti<start_loc+256;
+       return *(ti.tinfo) == typeid(color);
 }
 
 /** Extract representation label from tinfo key (as returned by
  *  return_type_tinfo()). */
 }
 
 /** Extract representation label from tinfo key (as returned by
  *  return_type_tinfo()). */
-static unsigned char get_representation_label(tinfo_t ti)
+static unsigned char get_representation_label(const return_type_t& ti)
 {
 {
-       return (unsigned char)((p_int)ti-(p_int)&color::return_type_tinfo_static);
+       return (unsigned char)ti.rl;
 }
 
 ex color_trace(const ex & e, const std::set<unsigned char> & rls)
 }
 
 ex color_trace(const ex & e, const std::set<unsigned char> & rls)
index ebe21226953e61284c29566857338e7d950a2d9b..360223e20b56686fca9d60336ff069cf85807137 100644 (file)
@@ -41,9 +41,6 @@ namespace GiNaC {
 class color : public indexed
 {
        GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
 class color : public indexed
 {
        GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
-public:
-       static const tinfo_static_t return_type_tinfo_static[256];
-
        // other constructors
 public:
        color(const ex & b, unsigned char rl = 0);
        // other constructors
 public:
        color(const ex & b, unsigned char rl = 0);
@@ -60,7 +57,7 @@ protected:
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const { return return_types::noncommutative; }
-       tinfo_t return_type_tinfo() const { return color::return_type_tinfo_static+representation_label; }
+       return_type_t return_type_tinfo() const;
 
        // non-virtual functions in this class
 public:
 
        // non-virtual functions in this class
 public:
index 4a603ce03778d441a9bfb1209cfdb0b3995bce2a..60d4080c7d7cdeaccad22f9baa7cacc2f6464dfd 100644 (file)
@@ -217,7 +217,7 @@ public:
 
        // noncommutativity
        unsigned return_type() const { return bp->return_type(); }
 
        // noncommutativity
        unsigned return_type() const { return bp->return_type(); }
-       tinfo_t return_type_tinfo() const { return bp->return_type_tinfo(); }
+       return_type_t return_type_tinfo() const { return bp->return_type_tinfo(); }
 
        unsigned gethash() const { return bp->gethash(); }
 
 
        unsigned gethash() const { return bp->gethash(); }
 
index b478023f50dc2d56852e3ebceac374af178aeaea..88be68d89e129308ce6a5ac18d53eb766f9f2ef6 100644 (file)
@@ -410,7 +410,7 @@ $print_func_interface
                return *this;
        }
 
                return *this;
        }
 
-       function_options & set_return_type(unsigned rt, tinfo_t rtt=NULL);
+       function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0);
        function_options & do_not_evalf_params();
        function_options & remember(unsigned size, unsigned assoc_size=0,
                                    unsigned strategy=remember_strategies::delete_never);
        function_options & do_not_evalf_params();
        function_options & remember(unsigned size, unsigned assoc_size=0,
                                    unsigned strategy=remember_strategies::delete_never);
@@ -445,7 +445,7 @@ protected:
 
        bool use_return_type;
        unsigned return_type;
 
        bool use_return_type;
        unsigned return_type;
-       tinfo_t return_type_tinfo;
+       return_type_t return_type_tinfo;
 
        bool use_remember;
        unsigned remember_size;
 
        bool use_remember;
        unsigned remember_size;
@@ -520,7 +520,7 @@ protected:
        bool is_equal_same_type(const basic & other) const;
        bool match_same_type(const basic & other) const;
        unsigned return_type() const;
        bool is_equal_same_type(const basic & other) const;
        bool match_same_type(const basic & other) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        
        // new virtual functions which can be overridden by derived classes
        // none
        
        // new virtual functions which can be overridden by derived classes
        // none
@@ -739,11 +739,14 @@ function_options& function_options::series_func(series_funcp_exvector s)
        return *this;
 }
 
        return *this;
 }
 
-function_options & function_options::set_return_type(unsigned rt, tinfo_t rtt)
+function_options & function_options::set_return_type(unsigned rt, const return_type_t* rtt)
 {
        use_return_type = true;
        return_type = rt;
 {
        use_return_type = true;
        return_type = rt;
-       return_type_tinfo = rtt;
+       if (rtt != 0)
+               return_type_tinfo = *rtt;
+       else
+               return_type_tinfo = make_return_type_t<function>();
        return *this;
 }
 
        return *this;
 }
 
@@ -1258,7 +1261,7 @@ unsigned function::return_type() const
        }
 }
 
        }
 }
 
-tinfo_t function::return_type_tinfo() const
+return_type_t function::return_type_tinfo() const
 {
        GINAC_ASSERT(serial<registered_functions().size());
        const function_options &opt = registered_functions()[serial];
 {
        GINAC_ASSERT(serial<registered_functions().size());
        const function_options &opt = registered_functions()[serial];
@@ -1270,7 +1273,7 @@ tinfo_t function::return_type_tinfo() const
                // Default behavior is to use the return type of the first
                // argument. Thus, exp() of a matrix behaves like a matrix, etc.
                if (seq.empty())
                // Default behavior is to use the return type of the first
                // argument. Thus, exp() of a matrix behaves like a matrix, etc.
                if (seq.empty())
-                       return this;
+                       return make_return_type_t<function>();
                else
                        return seq.begin()->return_type_tinfo();
        }
                else
                        return seq.begin()->return_type_tinfo();
        }
index 3c8951a1ee4b4af48a7108d01998fb59083cff27..82a45c3441b4e8390b5624e72e2ca49446bad780 100644 (file)
@@ -156,7 +156,7 @@ protected:
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const;
        ex thiscontainer(const exvector & v) const;
        ex thiscontainer(std::auto_ptr<exvector> vp) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const { return op(0).return_type_tinfo(); }
+       return_type_t return_type_tinfo() const { return op(0).return_type_tinfo(); }
        ex expand(unsigned options = 0) const;
 
        // new virtual functions which can be overridden by derived classes
        ex expand(unsigned options = 0) const;
 
        // new virtual functions which can be overridden by derived classes
index 2a332083eeb7e97e26bc25451289bcf045dc901b..220047568f160f36a9b522bb34dd6bb1f94f1040 100644 (file)
@@ -436,7 +436,7 @@ unsigned integral::return_type() const
        return f.return_type();
 }
 
        return f.return_type();
 }
 
-tinfo_t integral::return_type_tinfo() const
+return_type_t integral::return_type_tinfo() const
 {
        return f.return_type_tinfo();
 }
 {
        return f.return_type_tinfo();
 }
index c85a68278383969e62aa8414b6c20add518d9cac..e2843c82055e9326b6ef73d4bd726e564f8498a6 100644 (file)
@@ -51,7 +51,7 @@ public:
        ex expand(unsigned options = 0) const;
        exvector get_free_indices() const;
        unsigned return_type() const;
        ex expand(unsigned options = 0) const;
        exvector get_free_indices() const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        ex conjugate() const;
        ex eval_integ() const;
 protected:
        ex conjugate() const;
        ex eval_integ() const;
 protected:
index 63f92e1492d4fae3af2d8467f66793b0cc40bb68..96b965d1c5d4fd996f54b2ea7d33ed583c163349 100644 (file)
@@ -855,10 +855,10 @@ unsigned mul::return_type() const
        return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
        return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
-tinfo_t mul::return_type_tinfo() const
+return_type_t mul::return_type_tinfo() const
 {
        if (seq.empty())
 {
        if (seq.empty())
-               return this;  // mul without factors: should not happen
+               return make_return_type_t<mul>(); // mul without factors: should not happen
        
        // return type_info of first noncommutative element
        epvector::const_iterator i = seq.begin(), end = seq.end();
        
        // return type_info of first noncommutative element
        epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -868,7 +868,7 @@ tinfo_t mul::return_type_tinfo() const
                ++i;
        }
        // no noncommutative element found, should not happen
                ++i;
        }
        // no noncommutative element found, should not happen
-       return this;
+       return make_return_type_t<mul>();
 }
 
 ex mul::thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming) const
 }
 
 ex mul::thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming) const
index 20faf6af47f4e51a73a11e0c1788768d0cef0c18..a11b29b5fd0f3e39ce8966bc400ef880c8a9ee10 100644 (file)
@@ -68,7 +68,7 @@ protected:
        ex derivative(const symbol & s) const;
        ex eval_ncmul(const exvector & v) const;
        unsigned return_type() const;
        ex derivative(const symbol & s) const;
        ex eval_ncmul(const exvector & v) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
        ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
        expair split_ex_to_pair(const ex & e) const;
        ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
        ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming = false) const;
        expair split_ex_to_pair(const ex & e) const;
index a5969f317d035bb48db1ce491c12491d491d3f60..e0bc7dee4d12fe95c605b7aeedb4b1c7bd227774 100644 (file)
@@ -401,13 +401,13 @@ ex ncmul::eval(int level) const
 
                size_t assoc_num = assocseq.size();
                exvectorvector evv;
 
                size_t assoc_num = assocseq.size();
                exvectorvector evv;
-               std::vector<tinfo_t> rttinfos;
+               std::vector<return_type_t> rttinfos;
                evv.reserve(assoc_num);
                rttinfos.reserve(assoc_num);
 
                cit = assocseq.begin(), citend = assocseq.end();
                while (cit != citend) {
                evv.reserve(assoc_num);
                rttinfos.reserve(assoc_num);
 
                cit = assocseq.begin(), citend = assocseq.end();
                while (cit != citend) {
-                       tinfo_t ti = cit->return_type_tinfo();
+                       return_type_t ti = cit->return_type_tinfo();
                        size_t rtt_num = rttinfos.size();
                        // search type in vector of known types
                        for (i=0; i<rtt_num; ++i) {
                        size_t rtt_num = rttinfos.size();
                        // search type in vector of known types
                        for (i=0; i<rtt_num; ++i) {
@@ -578,10 +578,10 @@ unsigned ncmul::return_type() const
        return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
        return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
-tinfo_t ncmul::return_type_tinfo() const
+return_type_t ncmul::return_type_tinfo() const
 {
        if (seq.empty())
 {
        if (seq.empty())
-               return this;
+               return make_return_type_t<ncmul>();
 
        // return type_info of first noncommutative element
        exvector::const_iterator i = seq.begin(), end = seq.end();
 
        // return type_info of first noncommutative element
        exvector::const_iterator i = seq.begin(), end = seq.end();
@@ -592,7 +592,7 @@ tinfo_t ncmul::return_type_tinfo() const
        }
 
        // no noncommutative element found, should not happen
        }
 
        // no noncommutative element found, should not happen
-       return this;
+       return make_return_type_t<ncmul>();
 }
 
 //////////
 }
 
 //////////
index 7b21cf8bcf2c3975384fe2423b2b9c779164138a..910142745ca215a59253ba58724edad47cf48209 100644 (file)
@@ -71,7 +71,7 @@ public:
 protected:
        ex derivative(const symbol & s) const;
        unsigned return_type() const;
 protected:
        ex derivative(const symbol & s) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        
        // new virtual functions which can be overridden by derived classes
        // none
        
        // new virtual functions which can be overridden by derived classes
        // none
index a4a33c576ca415e0a3baa7e6b089fd8dae22b81f..ca7fea549f43a9c316b67dd503a761be3eeb4024 100644 (file)
@@ -769,7 +769,7 @@ unsigned power::return_type() const
        return basis.return_type();
 }
 
        return basis.return_type();
 }
 
-tinfo_t power::return_type_tinfo() const
+return_type_t power::return_type_tinfo() const
 {
        return basis.return_type_tinfo();
 }
 {
        return basis.return_type_tinfo();
 }
index 5c59ee7fef6679507e63aa996717aa8805c04a07..a13f7fcfd211ba3344639b9e280e2d1084bb1b64 100644 (file)
@@ -74,7 +74,7 @@ protected:
        ex derivative(const symbol & s) const;
        ex eval_ncmul(const exvector & v) const;
        unsigned return_type() const;
        ex derivative(const symbol & s) const;
        ex eval_ncmul(const exvector & v) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        ex expand(unsigned options = 0) const;
        
        // new virtual functions which can be overridden by derived classes
        ex expand(unsigned options = 0) const;
        
        // new virtual functions which can be overridden by derived classes
index d1f4a5c9d1b3e70a03cb771332fad7982c78eb48..d8a64db241dff5d99b720ec501eb7782602ee1fe 100644 (file)
@@ -38,6 +38,43 @@ class archive_node;
 template <template <class T, class = std::allocator<T> > class> class container;
 typedef container<std::list> lst;
 
 template <template <class T, class = std::allocator<T> > class> class container;
 typedef container<std::list> lst;
 
+/** To distinguish between different kinds of non-commutative objects */
+struct return_type_t
+{
+       /// to distinguish between non-commutative objects of different type.
+       std::type_info const* tinfo; 
+       /// to distinguish between non-commutative objects of the same type.
+       /// Think of gamma matrices with different represenation labels.
+       unsigned rl;
+
+       /// Strict weak ordering (so one can put return_type_t's into
+       /// a STL container).
+       inline bool operator<(const return_type_t& other) const
+       {
+               if (tinfo->before(*other.tinfo))
+                       return true;
+               return rl < other.rl;
+       }
+       inline bool operator==(const return_type_t& other) const
+       {
+               if (*tinfo != *(other.tinfo))
+                       return false;
+               return rl == other.rl;
+       }
+       inline bool operator!=(const return_type_t& other) const
+       {
+               return ! (operator==(other));
+       }
+};
+
+template<typename T> inline return_type_t make_return_type_t(const unsigned rl = 0)
+{
+       return_type_t ret;
+       ret.rl = rl;
+       ret.tinfo = &typeid(T);
+       return ret;
+}
+
 /** Definitions for the tinfo mechanism. */
 typedef const void * tinfo_t;
 struct tinfo_static_t {};
 /** Definitions for the tinfo mechanism. */
 typedef const void * tinfo_t;
 struct tinfo_static_t {};
index 2f19d21337622159ecd65ad9fcbd91715b61d632..f3329f98824edc92dd6c3fd6739abb0b83353d0d 100644 (file)
@@ -250,7 +250,7 @@ unsigned relational::return_type() const
        return lh.return_type();
 }
    
        return lh.return_type();
 }
    
-tinfo_t relational::return_type_tinfo() const
+return_type_t relational::return_type_tinfo() const
 {
        GINAC_ASSERT(lh.return_type_tinfo()==rh.return_type_tinfo());
        return lh.return_type_tinfo();
 {
        GINAC_ASSERT(lh.return_type_tinfo()==rh.return_type_tinfo());
        return lh.return_type_tinfo();
index 20e720dc0f4524e10d78b2c1b426b880d545efce..91cf51990e092346d5eed5cac51074152bc7ed37 100644 (file)
@@ -63,7 +63,7 @@ protected:
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        unsigned return_type() const;
        ex eval_ncmul(const exvector & v) const;
        bool match_same_type(const basic & other) const;
        unsigned return_type() const;
-       tinfo_t return_type_tinfo() const;
+       return_type_t return_type_tinfo() const;
        unsigned calchash() const;
 
        // new virtual functions which can be overridden by derived classes
        unsigned calchash() const;
 
        // new virtual functions which can be overridden by derived classes
index d00100b13ab60e156a10f1ca9c80b8c40fbcad10..cfd17c90cc41feed0973015a8fe4a07157f23c17 100644 (file)
@@ -200,7 +200,13 @@ public:
 
        // noncommutativity
        unsigned return_type() const { return return_types::commutative; }
 
        // noncommutativity
        unsigned return_type() const { return return_types::commutative; }
-       tinfo_t return_type_tinfo() const { return this; }
+       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
 
 protected:
        bool is_equal_same_type(const basic & other) const
index f233d84e791322f7d618348c45f211b4d6ce1c11..0bdebc0e88a514416b6032b822b4f6392dd89eed 100644 (file)
@@ -45,7 +45,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic,
 // symbol
 
 symbol::symbol()
 // symbol
 
 symbol::symbol()
- : inherited(&symbol::tinfo_static), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), domain(domain::complex), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), domain(domain::complex), ret_type(return_types::commutative), ret_type_tinfo(make_return_type_t<symbol>())
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -73,24 +73,24 @@ possymbol::possymbol()
 // symbol
 
 symbol::symbol(const std::string & initname, unsigned domain)
 // symbol
 
 symbol::symbol(const std::string & initname, unsigned domain)
- : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(make_return_type_t<symbol>())
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
-symbol::symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain)
+symbol::symbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 symbol::symbol(const std::string & initname, const std::string & texname, unsigned domain)
  : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 symbol::symbol(const std::string & initname, const std::string & texname, unsigned domain)
- : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(make_return_type_t<symbol>())
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
-symbol::symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
+symbol::symbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : inherited(&symbol::tinfo_static),  serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
  : inherited(&symbol::tinfo_static),  serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
@@ -104,10 +104,10 @@ realsymbol::realsymbol(const std::string & initname, unsigned domain)
 realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned domain)
  : symbol(initname, texname, domain) { }
 
 realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned domain)
  : symbol(initname, texname, domain) { }
 
-realsymbol::realsymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain)
+realsymbol::realsymbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : symbol(initname, rt, rtt, domain) { }
 
  : symbol(initname, rt, rtt, domain) { }
 
-realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
+realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : symbol(initname, texname, rt, rtt, domain) { }
 
 // possymbol
  : symbol(initname, texname, rt, rtt, domain) { }
 
 // possymbol
@@ -118,10 +118,10 @@ possymbol::possymbol(const std::string & initname, unsigned domain)
 possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned domain)
  : symbol(initname, texname, domain) { }
 
 possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned domain)
  : symbol(initname, texname, domain) { }
 
-possymbol::possymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain)
+possymbol::possymbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : symbol(initname, rt, rtt, domain) { }
 
  : symbol(initname, rt, rtt, domain) { }
 
-possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
+possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain)
  : symbol(initname, texname, rt, rtt, domain) { }
 
 //////////
  : symbol(initname, texname, rt, rtt, domain) { }
 
 //////////
index 3caa24e45c500c2943a6d8b6be7a57586483ac3f..00d4b9034f665fb1d986beb9270ec88640ada0a1 100644 (file)
@@ -47,8 +47,8 @@ public:
        explicit symbol(const std::string & initname, unsigned domain = domain::complex);
        symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex);
        symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned domain);
        explicit symbol(const std::string & initname, unsigned domain = domain::complex);
        symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex);
        symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned domain);
-       symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
-       symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
+       symbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::complex);
+       symbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::complex);
        
        // functions overriding virtual functions from base classes
 public:
        
        // functions overriding virtual functions from base classes
 public:
@@ -61,7 +61,7 @@ public:
        ex to_rational(exmap & repl) const;
        ex to_polynomial(exmap & repl) const;
        unsigned return_type() const { return ret_type; }
        ex to_rational(exmap & repl) const;
        ex to_polynomial(exmap & repl) const;
        unsigned return_type() const { return ret_type; }
-       tinfo_t return_type_tinfo() const { return ret_type_tinfo; }
+       return_type_t return_type_tinfo() const { return ret_type_tinfo; }
        ex conjugate() const;
        ex real_part() const;
        ex imag_part() const;
        ex conjugate() const;
        ex real_part() const;
        ex imag_part() const;
@@ -93,7 +93,7 @@ protected:
        std::string TeX_name;            ///< LaTeX name of this symbol
        unsigned domain;                 ///< domain of symbol, complex (default) or real
        unsigned ret_type;               ///< value returned by return_type()
        std::string TeX_name;            ///< LaTeX name of this symbol
        unsigned domain;                 ///< domain of symbol, complex (default) or real
        unsigned ret_type;               ///< value returned by return_type()
-       tinfo_t ret_type_tinfo;         ///< value returned by return_type_tinfo()
+       return_type_t ret_type_tinfo;         ///< value returned by return_type_tinfo()
 private:
        static unsigned next_serial;
 };
 private:
        static unsigned next_serial;
 };
@@ -107,8 +107,8 @@ public:
        realsymbol();
        explicit realsymbol(const std::string & initname, unsigned domain = domain::real);
        realsymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::real);
        realsymbol();
        explicit realsymbol(const std::string & initname, unsigned domain = domain::real);
        realsymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::real);
-       realsymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
-       realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
+       realsymbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::real);
+       realsymbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::real);
 };
 
 
 };
 
 
@@ -120,8 +120,8 @@ public:
        possymbol();
        explicit possymbol(const std::string & initname, unsigned domain = domain::positive);
        possymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::positive);
        possymbol();
        explicit possymbol(const std::string & initname, unsigned domain = domain::positive);
        possymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::positive);
-       possymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
-       possymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
+       possymbol(const std::string & initname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::positive);
+       possymbol(const std::string & initname, const std::string & texname, unsigned rt, const return_type_t& rtt, unsigned domain = domain::positive);
 };
 
 
 };