1 /* Handler and derived classes' 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_Handler_defs_hh
25 #define PPL_Handler_defs_hh 1
26 
27 #include "Handler_types.hh"
28 
29 //! Abstract base class for handlers of the watchdog events.
30 class Parma_Polyhedra_Library::Implementation::Watchdog::Handler {
31 public:
32   //! Does the job.
33   virtual void act() const = 0;
34 
35   //! Virtual destructor.
36   virtual ~Handler();
37 };
38 
39 //! A kind of Handler that installs a flag onto a flag-holder.
40 /*!
41   The template class <CODE>Handler_Flag\<Flag_Base, Flag\></CODE>
42   is an handler whose job is to install a flag onto an <EM>holder</EM>
43   for the flag.
44   The flag is of type \p Flag and the holder is a (volatile) pointer
45   to \p Flag_Base.  Installing the flag onto the holder means making
46   the holder point to the flag, so that it must be possible to assign
47   a value of type <CODE>Flag*</CODE> to an entity of type
48   <CODE>Flag_Base*</CODE>.
49   The class \p Flag must provide the method
50 
51   \code
52     int priority() const
53   \endcode
54   returning an integer priority associated to the flag.
55 
56   The handler will install its flag onto the holder only if the holder
57   is empty, namely, it is the null pointer, or if the holder holds a
58   flag of strictly lower priority.
59  */
60 template <typename Flag_Base, typename Flag>
61 class Parma_Polyhedra_Library::Implementation::Watchdog::Handler_Flag
62   : public Handler {
63 public:
64   //! Constructor with a given function.
65   Handler_Flag(const Flag_Base* volatile& holder, Flag& flag);
66 
67   /*! \brief
68     Does its job: installs the flag onto the holder, if a flag with
69     an higher priority has not already been installed.
70   */
71   virtual void act() const;
72 
73 private:
74   // Declare holder as reference to volatile pointer to const Flag_Base.
75   const Flag_Base* volatile& h;
76   Flag& f;
77 };
78 
79 //! A kind of Handler calling a given function.
80 class Parma_Polyhedra_Library::Implementation::Watchdog::Handler_Function
81   : public Handler {
82 public:
83   //! Constructor with a given function.
84   Handler_Function(void (* const function)());
85 
86   //! Does its job: calls the embedded function.
87   virtual void act() const;
88 
89 private:
90   //! Pointer to the embedded function.
91   void (* const f)();
92 };
93 
94 #include "Handler_inlines.hh"
95 
96 #endif // !defined(PPL_Handler_defs_hh)
97