/* Determinate class implementation: inline functions. Copyright (C) 2001-2004 Roberto Bagnara 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 2 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., 59 Temple Place - Suite 330, 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 namespace Parma_Polyhedra_Library { template Determinate::Rep::Rep(dimension_type num_dimensions, Polyhedron::Degenerate_Kind kind) : references(0), ph(num_dimensions, kind) { } template Determinate::Rep::Rep(const PH& p) : references(0), ph(p) { } template Determinate::Rep::Rep(const ConSys& cs) : references(0), ph(cs) { } template Determinate::Rep::~Rep() { assert(references == 0); } template void Determinate::Rep::new_reference() const { ++references; } template bool Determinate::Rep::del_reference() const { return --references == 0; } template bool Determinate::Rep::is_shared() const { return references > 1; } template Determinate::Determinate(dimension_type num_dimensions, bool universe) : prep(new Rep(num_dimensions, universe ? Polyhedron::UNIVERSE : Polyhedron::EMPTY)) { prep->new_reference(); } template Determinate::Determinate(const PH& ph) : prep(new Rep(ph)) { prep->new_reference(); } template Determinate::Determinate(const ConSys& cs) : prep(new Rep(cs)) { prep->new_reference(); } template Determinate::Determinate(const Determinate& y) : prep(y.prep) { prep->new_reference(); } template Determinate::~Determinate() { if (prep->del_reference()) delete prep; } template 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 void Determinate::mutate() { if (prep->is_shared()) { Rep* new_prep = new Rep(prep->ph); (void) prep->del_reference(); new_prep->new_reference(); prep = new_prep; } } template const PH& Determinate::element() const { return prep->ph; } template PH& Determinate::element() { mutate(); return prep->ph; } template void Determinate::upper_bound_assign(const Determinate& y) { mutate(); prep->ph.poly_hull_assign(y.prep->ph); } template void Determinate::meet_assign(const Determinate& y) { mutate(); prep->ph.intersection_assign(y.prep->ph); } template void Determinate::concatenate_assign(const Determinate& y) { mutate(); prep->ph.concatenate_assign(y.prep->ph); } template bool Determinate::definitely_entails(const Determinate& y) const { return prep == y.prep || y.prep->ph.contains(prep->ph); } template bool Determinate::is_definitely_equivalent_to(const Determinate& y) const { return prep == y.prep || prep->ph == y.prep->ph; } template inline bool Determinate::is_top() const { return prep->ph.is_universe(); } template inline bool Determinate::is_bottom() const { return prep->ph.is_empty(); } template bool Determinate::OK() const { return prep->ph.OK(); } namespace IO_Operators { /*! \relates Parma_Polyhedra_Library::Determinate */ template std::ostream& operator<<(std::ostream& s, const Determinate& x) { if (x.is_top()) s << "true"; else if (x.is_bottom()) s << "false"; else { const ConSys& cs = x.constraints(); ConSys::const_iterator i = cs.begin(); ConSys::const_iterator cs_end = cs.end(); s << "{ "; while (i != cs_end) { s << *i++; if (i != cs_end) s << ", "; } s << " }"; } return s; } } // namespace IO_Operators /*! \relates Determinate */ template bool operator==(const Determinate& x, const Determinate& y) { return x.prep == y.prep || x.prep->ph == y.prep->ph; } /*! \relates Determinate */ template bool operator!=(const Determinate& x, const Determinate& y) { return x.prep != y.prep && x.prep->ph != y.prep->ph; } template dimension_type Determinate::space_dimension() const { return prep->ph.space_dimension(); } template const ConSys& Determinate::constraints() const { return prep->ph.constraints(); } template const ConSys& Determinate::minimized_constraints() const { return prep->ph.minimized_constraints(); } template void Determinate::add_constraint(const Constraint& c) { mutate(); prep->ph.add_constraint(c); } template void Determinate::add_constraints(ConSys& cs) { mutate(); prep->ph.add_constraints(cs); } template void Determinate::add_dimensions_and_embed(dimension_type m) { mutate(); prep->ph.add_dimensions_and_embed(m); } template void Determinate::add_dimensions_and_project(dimension_type m) { mutate(); prep->ph.add_dimensions_and_project(m); } template void Determinate::remove_dimensions(const Variables_Set& to_be_removed) { mutate(); prep->ph.remove_dimensions(to_be_removed); } template void Determinate::remove_higher_dimensions(dimension_type new_dimension) { mutate(); prep->ph.remove_higher_dimensions(new_dimension); } template template void Determinate::map_dimensions(const PartialFunction& pfunc) { mutate(); prep->ph.map_dimensions(pfunc); } } // 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)