PPL  0.12.1
Linear_Expression.defs.hh
Go to the documentation of this file.
00001 /* Linear_Expression class declaration.
00002    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
00003    Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
00004 
00005 This file is part of the Parma Polyhedra Library (PPL).
00006 
00007 The PPL is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 The PPL is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software Foundation,
00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
00020 
00021 For the most up-to-date information see the Parma Polyhedra Library
00022 site: http://bugseng.com/products/ppl/ . */
00023 
00024 #ifndef PPL_Linear_Expression_defs_hh
00025 #define PPL_Linear_Expression_defs_hh 1
00026 
00027 #include "Linear_Expression.types.hh"
00028 #include "Scalar_Products.types.hh"
00029 #include "Constraint.types.hh"
00030 #include "Generator.types.hh"
00031 #include "Congruence.types.hh"
00032 #include "Grid_Generator.types.hh"
00033 #include "Linear_Row.defs.hh"
00034 #include "Coefficient.types.hh"
00035 #include "Variable.defs.hh"
00036 #include "Constraint_System.types.hh"
00037 #include "Generator_System.types.hh"
00038 #include "Congruence_System.types.hh"
00039 #include "Grid_Generator_System.types.hh"
00040 #include "Polyhedron.types.hh"
00041 #include "Grid.types.hh"
00042 #include <cstddef>
00043 
00044 namespace Parma_Polyhedra_Library {
00045 
00047 
00048 void swap(Linear_Expression& x, Linear_Expression& y);
00049 
00050 // Put them in the namespace here to declare them friend later.
00051 
00053 
00054 Linear_Expression
00055 operator+(const Linear_Expression& e1, const Linear_Expression& e2);
00056 
00058 
00059 Linear_Expression
00060 operator+(Variable v, Variable w);
00061 
00063 
00064 Linear_Expression
00065 operator+(Variable v, const Linear_Expression& e);
00066 
00068 
00069 Linear_Expression
00070 operator+(const Linear_Expression& e, Variable v);
00071 
00073 
00074 Linear_Expression
00075 operator+(Coefficient_traits::const_reference n, const Linear_Expression& e);
00076 
00078 
00079 Linear_Expression
00080 operator+(const Linear_Expression& e, Coefficient_traits::const_reference n);
00081 
00083 
00084 Linear_Expression
00085 operator+(const Linear_Expression& e);
00086 
00088 
00089 Linear_Expression
00090 operator-(const Linear_Expression& e);
00091 
00093 
00094 Linear_Expression
00095 operator-(const Linear_Expression& e1, const Linear_Expression& e2);
00096 
00098 
00099 Linear_Expression
00100 operator-(Variable v, Variable w);
00101 
00103 
00104 Linear_Expression
00105 operator-(Variable v, const Linear_Expression& e);
00106 
00108 
00109 Linear_Expression
00110 operator-(const Linear_Expression& e, Variable v);
00111 
00113 
00114 Linear_Expression
00115 operator-(Coefficient_traits::const_reference n, const Linear_Expression& e);
00116 
00118 
00119 Linear_Expression
00120 operator-(const Linear_Expression& e, Coefficient_traits::const_reference n);
00121 
00123 
00124 Linear_Expression
00125 operator*(Coefficient_traits::const_reference n, const Linear_Expression& e);
00126 
00128 
00129 Linear_Expression
00130 operator*(const Linear_Expression& e, Coefficient_traits::const_reference n);
00131 
00133 
00134 Linear_Expression&
00135 operator+=(Linear_Expression& e1, const Linear_Expression& e2);
00136 
00138 
00143 Linear_Expression&
00144 operator+=(Linear_Expression& e, Variable v);
00145 
00147 
00148 Linear_Expression&
00149 operator+=(Linear_Expression& e, Coefficient_traits::const_reference n);
00150 
00152 
00153 Linear_Expression&
00154 operator-=(Linear_Expression& e1, const Linear_Expression& e2);
00155 
00157 
00162 Linear_Expression&
00163 operator-=(Linear_Expression& e, Variable v);
00164 
00166 
00167 Linear_Expression&
00168 operator-=(Linear_Expression& e, Coefficient_traits::const_reference n);
00169 
00171 
00172 Linear_Expression&
00173 operator*=(Linear_Expression& e, Coefficient_traits::const_reference n);
00174 
00176 
00177 Linear_Expression&
00178 add_mul_assign(Linear_Expression& e,
00179                Coefficient_traits::const_reference n, Variable v);
00180 
00182 
00183 Linear_Expression&
00184 sub_mul_assign(Linear_Expression& e,
00185                Coefficient_traits::const_reference n, Variable v);
00186 
00187 namespace IO_Operators {
00188 
00190 
00191 std::ostream& operator<<(std::ostream& s, const Linear_Expression& e);
00192 
00193 } // namespace IO_Operators
00194 
00195 } // namespace Parma_Polyhedra_Library
00196 
00198 
00244 class Parma_Polyhedra_Library::Linear_Expression : private Linear_Row {
00245 public:
00247   Linear_Expression();
00248 
00250   Linear_Expression(const Linear_Expression& e);
00251 
00253   ~Linear_Expression();
00254 
00259   explicit Linear_Expression(Coefficient_traits::const_reference n);
00260 
00262 
00267   Linear_Expression(Variable v);
00268 
00270 
00279   explicit Linear_Expression(const Constraint& c);
00280 
00294   explicit Linear_Expression(const Generator& g);
00295 
00305   explicit Linear_Expression(const Grid_Generator& g);
00306 
00308 
00313   explicit Linear_Expression(const Congruence& cg);
00314 
00316   static dimension_type max_space_dimension();
00317 
00319   dimension_type space_dimension() const;
00320 
00322   Coefficient_traits::const_reference coefficient(Variable v) const;
00323 
00325   Coefficient_traits::const_reference inhomogeneous_term() const;
00326 
00328   bool is_zero() const;
00329 
00334   bool all_homogeneous_terms_are_zero() const;
00335 
00337   static void initialize();
00338 
00340   static void finalize();
00341 
00343   static const Linear_Expression& zero();
00344 
00349   memory_size_type total_memory_in_bytes() const;
00350 
00352   memory_size_type external_memory_in_bytes() const;
00353 
00354   PPL_OUTPUT_DECLARATIONS
00355 
00361   bool ascii_load(std::istream& s);
00362 
00364   bool OK() const;
00365 
00367   void m_swap(Linear_Expression& y);
00368 
00369 private:
00374   static const Linear_Expression* zero_p;
00375 
00376   friend class Parma_Polyhedra_Library::Scalar_Products;
00377   friend class Parma_Polyhedra_Library::Constraint;
00378   friend class Parma_Polyhedra_Library::Generator;
00379   // The following declaration grants access to Grid_Generator::parameter.
00380   friend class Parma_Polyhedra_Library::Grid_Generator;
00381   friend class Parma_Polyhedra_Library::Congruence;
00382   // FIXME: the following friend declaration should be avoided.
00383   friend class Parma_Polyhedra_Library::Polyhedron;
00384   friend class Parma_Polyhedra_Library::Grid;
00385 
00386   // FIXME: the following friend declaration is only to grant access to
00387   // Constraint_System::affine_preimage().
00388   friend class Parma_Polyhedra_Library::Constraint_System;
00389 
00390   // FIXME: the following friend declaration is only to grant access to
00391   // Generator_System::affine_image().
00392   friend class Parma_Polyhedra_Library::Generator_System;
00393 
00394   // FIXME: the following friend declaration is only to grant access to
00395   // Congruence_System::affine_preimage().
00396   friend class Parma_Polyhedra_Library::Congruence_System;
00397 
00398   // FIXME: the following friend declaration is only to grant access to
00399   // Grid_Generator_System::affine_image().
00400   friend class Parma_Polyhedra_Library::Grid_Generator_System;
00401 
00403   Linear_Expression(const Linear_Expression& e, dimension_type sz);
00404 
00406 
00410   Linear_Expression(dimension_type sz, bool);
00411 
00420   Linear_Expression(Variable v, Variable w);
00421 
00422   friend Linear_Expression
00423   operator+(const Linear_Expression& e1, const Linear_Expression& e2);
00424   friend Linear_Expression
00425   operator+(Coefficient_traits::const_reference n, const Linear_Expression& e);
00426   friend Linear_Expression
00427   operator+(const Linear_Expression& e, Coefficient_traits::const_reference n);
00428   friend Linear_Expression
00429   operator+(Variable v, const Linear_Expression& e);
00430   friend Linear_Expression
00431   operator+(Variable v, Variable w);
00432 
00433   friend Linear_Expression
00434   operator-(const Linear_Expression& e);
00435 
00436   friend Linear_Expression
00437   operator-(const Linear_Expression& e1, const Linear_Expression& e2);
00438   friend Linear_Expression
00439   operator-(Variable v, Variable w);
00440   friend Linear_Expression
00441   operator-(Coefficient_traits::const_reference n, const Linear_Expression& e);
00442   friend Linear_Expression
00443   operator-(const Linear_Expression& e, Coefficient_traits::const_reference n);
00444   friend Linear_Expression
00445   operator-(Variable v, const Linear_Expression& e);
00446   friend Linear_Expression
00447   operator-(const Linear_Expression& e, Variable v);
00448 
00449   friend Linear_Expression
00450   operator*(Coefficient_traits::const_reference n, const Linear_Expression& e);
00451   friend Linear_Expression
00452   operator*(const Linear_Expression& e, Coefficient_traits::const_reference n);
00453 
00454   friend Linear_Expression&
00455   operator+=(Linear_Expression& e1, const Linear_Expression& e2);
00456   friend Linear_Expression&
00457   operator+=(Linear_Expression& e, Variable v);
00458   friend Linear_Expression&
00459   operator+=(Linear_Expression& e, Coefficient_traits::const_reference n);
00460 
00461   friend Linear_Expression&
00462   operator-=(Linear_Expression& e1, const Linear_Expression& e2);
00463   friend Linear_Expression&
00464   operator-=(Linear_Expression& e, Variable v);
00465   friend Linear_Expression&
00466   operator-=(Linear_Expression& e, Coefficient_traits::const_reference n);
00467 
00468   friend Linear_Expression&
00469   operator*=(Linear_Expression& e, Coefficient_traits::const_reference n);
00470 
00471   friend Linear_Expression&
00472   add_mul_assign(Linear_Expression& e,
00473                  Coefficient_traits::const_reference n, Variable v);
00474   friend Linear_Expression&
00475   sub_mul_assign(Linear_Expression& e,
00476                  Coefficient_traits::const_reference n, Variable v);
00477 
00478   friend std::ostream&
00479   Parma_Polyhedra_Library::IO_Operators
00480   ::operator<<(std::ostream& s, const Linear_Expression& e);
00481 };
00482 
00483 #include "Linear_Expression.inlines.hh"
00484 
00485 #endif // !defined(PPL_Linear_Expression_defs_hh)