1 /* Partial_Function class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Partial_Function_defs_hh
25 #define PPL_Partial_Function_defs_hh 1
26 
27 #include "Partial_Function_types.hh"
28 #include "globals_defs.hh"
29 #include <vector>
30 #ifndef NDEBUG
31 #include <set>
32 #endif
33 #include <iosfwd>
34 
35 namespace Parma_Polyhedra_Library {
36 
37 class Partial_Function {
38 public:
39   /*! \brief
40     Default constructor: builds a function with empty codomain
41     (i.e., always undefined).
42   */
43   Partial_Function();
44 
45   /*! \brief
46     Returns \c true if and only if the represented partial function
47     has an empty codomain (i.e., it is always undefined).
48   */
49   bool has_empty_codomain() const;
50 
51   /*! \brief
52     If the codomain is \e not empty, returns the maximum value in it.
53 
54     \exception std::runtime_error
55     Thrown if called when \p *this has an empty codomain.
56   */
57   dimension_type max_in_codomain() const;
58 
59   /*! \brief
60     If \p *this maps \p i to a value \c k, assigns \c k to \p j and
61     returns \c true; otherwise, \p j is unchanged and \c false is returned.
62   */
63   bool maps(dimension_type i, dimension_type& j) const;
64 
65   void print(std::ostream& s) const;
66 
67   /*! \brief
68     Modifies \p *this so that \p i is mapped to \p j.
69 
70     \exception std::runtime_error
71     Thrown if \p *this is already mapping \p j.
72   */
73   void insert(dimension_type i, dimension_type j);
74 
75 private:
76   std::vector<dimension_type> vec;
77   dimension_type max;
78 #ifndef NDEBUG
79   std::set<dimension_type> codomain;
80 #endif
81 }; // class Partial_Function
82 
83 } // namespace Parma_Polyhedra_Library
84 
85 #include "Partial_Function_inlines.hh"
86 
87 #endif // !defined(PPL_Partial_Function_defs_hh)
88