1 /* Variable_Floating_Point_Expression class implementation: inline functions.
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_Variable_Floating_Point_Expression_inlines_hh
25 #define PPL_Variable_Floating_Point_Expression_inlines_hh 1
26 
27 #include "globals_defs.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 template <typename FP_Interval_Type, typename FP_Format>
32 inline
33 Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>::
Variable_Floating_Point_Expression(const dimension_type v_index)34 Variable_Floating_Point_Expression(const dimension_type v_index)
35   : variable_index(v_index) {}
36 
37 template <typename FP_Interval_Type, typename FP_Format>
38 inline
39 Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>::
~Variable_Floating_Point_Expression()40 ~Variable_Floating_Point_Expression() {}
41 
42 template <typename FP_Interval_Type, typename FP_Format>
43 inline void
44 Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>
m_swap(Variable_Floating_Point_Expression & y)45 ::m_swap(Variable_Floating_Point_Expression& y) {
46   using std::swap;
47   swap(variable_index, y.variable_index);
48 }
49 
50 template <typename FP_Interval_Type, typename FP_Format>
51 inline bool
52 Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>
linearize(const FP_Interval_Abstract_Store &,const FP_Linear_Form_Abstract_Store & lf_store,FP_Linear_Form & result) const53 ::linearize(const FP_Interval_Abstract_Store&,
54             const FP_Linear_Form_Abstract_Store& lf_store,
55             FP_Linear_Form& result) const {
56   typename FP_Linear_Form_Abstract_Store::const_iterator
57            variable_value = lf_store.find(variable_index);
58 
59   if (variable_value == lf_store.end()) {
60     result = FP_Linear_Form(Variable(variable_index));
61     return true;
62   }
63 
64   result = FP_Linear_Form(variable_value->second);
65   return !this->overflows(result);
66 }
67 
68 template <typename FP_Interval_Type, typename FP_Format>
69 inline void
70 Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>
linear_form_assign(const FP_Linear_Form & lf,FP_Linear_Form_Abstract_Store & lf_store) const71 ::linear_form_assign(const FP_Linear_Form& lf,
72                            FP_Linear_Form_Abstract_Store& lf_store) const {
73   for (typename FP_Linear_Form_Abstract_Store::iterator
74          i = lf_store.begin(); i != lf_store.end(); ) {
75     if ((i->second).coefficient(Variable(variable_index)) != 0) {
76       i = lf_store.erase(i);
77     }
78     else {
79       ++i;
80     }
81   }
82   lf_store[variable_index] = lf;
83   return;
84 }
85 
86 /*! \relates Variable_Floating_Point_Expression */
87 template <typename FP_Interval_Type, typename FP_Format>
88 inline void
swap(Variable_Floating_Point_Expression<FP_Interval_Type,FP_Format> & x,Variable_Floating_Point_Expression<FP_Interval_Type,FP_Format> & y)89 swap(Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>& x,
90      Variable_Floating_Point_Expression<FP_Interval_Type, FP_Format>& y) {
91   x.m_swap(y);
92 }
93 
94 } // namespace Parma_Polyhedra_Library
95 
96 #endif // !defined(PPL_Variable_Floating_Point_Expression_inlines_hh)
97