GiNaC  1.6.2
relational.h
Go to the documentation of this file.
00001 
00005 /*
00006  *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  */
00022 
00023 #ifndef GINAC_RELATIONAL_H
00024 #define GINAC_RELATIONAL_H
00025 
00026 #include "basic.h"
00027 #include "ex.h"
00028 #include "archive.h"
00029 
00030 namespace GiNaC {
00031 
00034 class relational : public basic
00035 {
00036     GINAC_DECLARE_REGISTERED_CLASS(relational, basic)
00037 
00038 // types
00039 public:
00040     enum operators {
00041         equal,
00042         not_equal,
00043         less,
00044         less_or_equal,
00045         greater,
00046         greater_or_equal
00047     };
00048     
00049     // other constructors
00050 public:
00051     relational(const ex & lhs, const ex & rhs, operators oper=equal);
00052     
00053     // functions overriding virtual functions from base classes
00054 public:
00055     unsigned precedence() const {return 20;}
00056     bool info(unsigned inf) const;
00057     size_t nops() const;
00058     ex op(size_t i) const;
00059     ex map(map_function & f) const;
00060     ex subs(const exmap & m, unsigned options = 0) const;
00061     ex eval(int level=0) const;
00062 
00064     void archive(archive_node& n) const;
00066     void read_archive(const archive_node& n, lst& syms);
00067 protected:
00068     ex eval_ncmul(const exvector & v) const;
00069     bool match_same_type(const basic & other) const;
00070     unsigned return_type() const;
00071     return_type_t return_type_tinfo() const;
00072     unsigned calchash() const;
00073 
00074     // new virtual functions which can be overridden by derived classes
00075 protected:
00076     void do_print(const print_context & c, unsigned level) const;
00077     void do_print_python_repr(const print_python_repr & c, unsigned level) const;
00078 
00079 public:
00080     virtual ex lhs() const;
00081     virtual ex rhs() const;
00082 
00083     // non-virtual functions in this class
00084 private:
00085     // For conversions to boolean, as would be used in an if conditional,
00086     // implicit conversions from bool to int have a large number of
00087     // undesirable side effects.  The following safe_bool type enables
00088     // use of relational objects in conditionals without those side effects
00089     struct safe_bool_helper {
00090         void nonnull() {};
00091     };
00092 
00093     typedef void (safe_bool_helper::*safe_bool)();
00094     
00095     safe_bool make_safe_bool(bool) const;
00096 
00097 public:
00098     operator safe_bool() const;
00099     safe_bool operator!() const;
00100 
00101 // member variables
00102     
00103 protected:
00104     ex lh;
00105     ex rh;
00106     operators o;
00107 };
00108 GINAC_DECLARE_UNARCHIVER(relational); 
00109 
00110 // utility functions
00111 
00112 // inlined functions for efficiency
00113 inline relational::safe_bool relational::operator!() const
00114 {
00115     return make_safe_bool(!static_cast<bool>(*this));
00116 }
00117 
00118 } // namespace GiNaC
00119 
00120 #endif // ndef GINAC_RELATIONAL_H

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.