/* Determinate class implementation: inline functions. Copyright (C) 2001-2010 Roberto Bagnara Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com) This file is part of the Parma Polyhedra Library (PPL). The PPL is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The PPL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. For the most up-to-date information see the Parma Polyhedra Library site: http://www.cs.unipr.it/ppl/ . */ #ifndef PPL_Determinate_inlines_hh #define PPL_Determinate_inlines_hh 1 #include "assert.hh" namespace Parma_Polyhedra_Library { template inline Determinate::Rep::Rep(dimension_type num_dimensions, Degenerate_Element kind) : references(0), pset(num_dimensions, kind) { } template inline Determinate::Rep::Rep(const PSET& p) : references(0), pset(p) { } template inline Determinate::Rep::Rep(const Constraint_System& cs) : references(0), pset(cs) { } template inline Determinate::Rep::Rep(const Congruence_System& cgs) : references(0), pset(cgs) { } template inline Determinate::Rep::~Rep() { PPL_ASSERT(references == 0); } template inline void Determinate::Rep::new_reference() const { ++references; } template inline bool Determinate::Rep::del_reference() const { return --references == 0; } template inline bool Determinate::Rep::is_shared() const { return references > 1; } template inline memory_size_type Determinate::Rep::external_memory_in_bytes() const { return pset.external_memory_in_bytes(); } template inline memory_size_type Determinate::Rep::total_memory_in_bytes() const { return sizeof(*this) + external_memory_in_bytes(); } template inline Determinate::Determinate(const PSET& pset) : prep(new Rep(pset)) { prep->new_reference(); } template inline Determinate::Determinate(const Constraint_System& cs) : prep(new Rep(cs)) { prep->new_reference(); } template inline Determinate::Determinate(const Congruence_System& cgs) : prep(new Rep(cgs)) { prep->new_reference(); } template inline Determinate::Determinate(const Determinate& y) : prep(y.prep) { prep->new_reference(); } template inline Determinate::~Determinate() { if (prep->del_reference()) delete prep; } template inline Determinate& Determinate::operator=(const Determinate& y) { y.prep->new_reference(); if (prep->del_reference()) delete prep; prep = y.prep; return *this; } template inline void Determinate::swap(Determinate& y) { std::swap(prep, y.prep); } template inline void Determinate::mutate() { if (prep->is_shared()) { Rep* new_prep = new Rep(prep->pset); (void) prep->del_reference(); new_prep->new_reference(); prep = new_prep; } } template inline const PSET& Determinate::pointset() const { return prep->pset; } template inline PSET& Determinate::pointset() { mutate(); return prep->pset; } template inline void Determinate::upper_bound_assign(const Determinate& y) { pointset().upper_bound_assign(y.pointset()); } template inline void Determinate::meet_assign(const Determinate& y) { pointset().intersection_assign(y.pointset()); } template inline bool Determinate::has_nontrivial_weakening() { // FIXME: the following should be turned into a query to PSET. This // can be postponed until the time the ask-and-tell construction is // revived. return false; } template inline void Determinate::weakening_assign(const Determinate& y) { // FIXME: the following should be turned into a proper // implementation. This can be postponed until the time the // ask-and-tell construction is revived. pointset().difference_assign(y.pointset()); } template inline void Determinate::concatenate_assign(const Determinate& y) { pointset().concatenate_assign(y.pointset()); } template inline bool Determinate::definitely_entails(const Determinate& y) const { return prep == y.prep || y.prep->pset.contains(prep->pset); } template inline bool Determinate::is_definitely_equivalent_to(const Determinate& y) const { return prep == y.prep || prep->pset == y.prep->pset; } template inline bool Determinate::is_top() const { return prep->pset.is_universe(); } template inline bool Determinate::is_bottom() const { return prep->pset.is_empty(); } template inline memory_size_type Determinate::external_memory_in_bytes() const { return prep->total_memory_in_bytes(); } template inline memory_size_type Determinate::total_memory_in_bytes() const { return sizeof(*this) + external_memory_in_bytes(); } template inline bool Determinate::OK() const { return prep->pset.OK(); } namespace IO_Operators { /*! \relates Parma_Polyhedra_Library::Determinate */ template inline std::ostream& operator<<(std::ostream& s, const Determinate& x) { s << x.pointset(); return s; } } // namespace IO_Operators /*! \relates Determinate */ template inline bool operator==(const Determinate& x, const Determinate& y) { return x.prep == y.prep || x.prep->pset == y.prep->pset; } /*! \relates Determinate */ template inline bool operator!=(const Determinate& x, const Determinate& y) { return x.prep != y.prep && x.prep->pset != y.prep->pset; } template template inline Determinate::Binary_Operator_Assign_Lifter:: Binary_Operator_Assign_Lifter(Binary_Operator_Assign op_assign) : op_assign_(op_assign) { } template template inline void Determinate::Binary_Operator_Assign_Lifter:: operator()(Determinate& x, const Determinate& y) const { op_assign_(x.pointset(), y.pointset()); } template template inline Determinate::Binary_Operator_Assign_Lifter Determinate::lift_op_assign(Binary_Operator_Assign op_assign) { return Binary_Operator_Assign_Lifter(op_assign); } } // namespace Parma_Polyhedra_Library namespace std { /*! \relates Parma_Polyhedra_Library::Determinate */ template inline void swap(Parma_Polyhedra_Library::Determinate& x, Parma_Polyhedra_Library::Determinate& y) { x.swap(y); } } // namespace std #endif // !defined(PPL_Determinate_inlines_hh)