PPL  1.2
Parma_Polyhedra_Library::Threshold_Watcher< Traits > Class Template Reference

A class of watchdogs controlling the exceeding of a threshold. More...

#include <Threshold_Watcher_defs.hh>

Collaboration diagram for Parma_Polyhedra_Library::Threshold_Watcher< Traits >:

Classes

struct  Initialize
 

Public Member Functions

template<typename Flag_Base , typename Flag >
 Threshold_Watcher (const typename Traits::Delta &delta, const Flag_Base *volatile &holder, Flag &flag)
 
 Threshold_Watcher (const typename Traits::Delta &delta, void(*function)())
 
 ~Threshold_Watcher ()
 

Private Types

typedef Implementation::Watchdog::Pending_List< Traits > TW_Pending_List
 
typedef Implementation::Watchdog::Handler TW_Handler
 

Private Member Functions

 Threshold_Watcher (const Threshold_Watcher &)
 
Threshold_Watcheroperator= (const Threshold_Watcher &)
 

Static Private Member Functions

static TW_Pending_List::iterator add_threshold (typename Traits::Threshold threshold, const TW_Handler &handler, bool &expired_flag)
 
static TW_Pending_List::iterator remove_threshold (typename TW_Pending_List::iterator position)
 
static void check ()
 Check threshold reaching. More...
 

Private Attributes

bool expired
 
const TW_Handlerhandler
 
TW_Pending_List::iterator pending_position
 

Static Private Attributes

static Initialize init
 

Detailed Description

template<typename Traits>
class Parma_Polyhedra_Library::Threshold_Watcher< Traits >

A class of watchdogs controlling the exceeding of a threshold.

Template Parameters
TraitsA class to set data types and functions for the threshold handling. See Parma_Polyhedra_Library::Weightwatch_Traits for an example.

Definition at line 40 of file Threshold_Watcher_defs.hh.

Member Typedef Documentation

template<typename Traits >
typedef Implementation::Watchdog::Handler Parma_Polyhedra_Library::Threshold_Watcher< Traits >::TW_Handler
private

Definition at line 54 of file Threshold_Watcher_defs.hh.

template<typename Traits >
typedef Implementation::Watchdog::Pending_List<Traits> Parma_Polyhedra_Library::Threshold_Watcher< Traits >::TW_Pending_List
private

Definition at line 53 of file Threshold_Watcher_defs.hh.

Constructor & Destructor Documentation

template<typename Traits >
template<typename Flag_Base , typename Flag >
Parma_Polyhedra_Library::Threshold_Watcher< Traits >::Threshold_Watcher ( const typename Traits::Delta &  delta,
const Flag_Base *volatile &  holder,
Flag &  flag 
)

Definition at line 35 of file Threshold_Watcher_inlines.hh.

38  : expired(false),
39  handler(*new
40  Implementation::Watchdog::Handler_Flag<Flag_Base, Flag>(holder,
41  flag)) {
42  typename Traits::Threshold threshold;
43  Traits::from_delta(threshold, delta);
44  if (!Traits::less_than(Traits::get(), threshold)) {
45  throw std::invalid_argument("Threshold_Watcher constructor called with a"
46  " threshold already reached");
47  }
49 }
static TW_Pending_List::iterator add_threshold(typename Traits::Threshold threshold, const TW_Handler &handler, bool &expired_flag)
template<typename Traits >
Parma_Polyhedra_Library::Threshold_Watcher< Traits >::Threshold_Watcher ( const typename Traits::Delta &  delta,
void(*)()  function 
)
inline

Definition at line 54 of file Threshold_Watcher_inlines.hh.

55  : expired(false),
56  handler(*new Implementation::Watchdog::Handler_Function(function)) {
57  typename Traits::Threshold threshold;
58  Traits::from_delta(threshold, delta);
59  if (!Traits::less_than(Traits::get(), threshold)) {
60  throw std::invalid_argument("Threshold_Watcher constructor called with a"
61  " threshold already reached");
62  }
64 }
static TW_Pending_List::iterator add_threshold(typename Traits::Threshold threshold, const TW_Handler &handler, bool &expired_flag)
template<typename Traits >
Parma_Polyhedra_Library::Threshold_Watcher< Traits >::~Threshold_Watcher ( )

Definition at line 50 of file Threshold_Watcher_templates.hh.

50  {
51  if (!expired) {
53  }
54  delete &handler;
55 }
static TW_Pending_List::iterator remove_threshold(typename TW_Pending_List::iterator position)
template<typename Traits >
Parma_Polyhedra_Library::Threshold_Watcher< Traits >::Threshold_Watcher ( const Threshold_Watcher< Traits > &  )
private

Member Function Documentation

template<typename Traits >
Threshold_Watcher< Traits >::TW_Pending_List::iterator Parma_Polyhedra_Library::Threshold_Watcher< Traits >::add_threshold ( typename Traits::Threshold  threshold,
const TW_Handler handler,
bool &  expired_flag 
)
staticprivate

Definition at line 31 of file Threshold_Watcher_templates.hh.

References Parma_Polyhedra_Library::Threshold_Watcher< Traits >::check().

33  {
34  Traits::check_function = Threshold_Watcher::check;
35  return init.pending.insert(threshold, handler, expired_flag);
36 }
static void check()
Check threshold reaching.
TW_Pending_List pending
The ordered queue of pending thresholds.
iterator insert(const typename Traits::Threshold &deadline, const Handler &handler, bool &expired_flag)
Inserts a new Pending_Element object with the given attributes.
template<typename Traits >
void Parma_Polyhedra_Library::Threshold_Watcher< Traits >::check ( )
staticprivate

Check threshold reaching.

Definition at line 59 of file Threshold_Watcher_templates.hh.

Referenced by Parma_Polyhedra_Library::Threshold_Watcher< Traits >::add_threshold().

59  {
61  assert(i != init.pending.end());
62  const typename Traits::Threshold& current = Traits::get();
63  while (!Traits::less_than(current, i->deadline())) {
64  i->handler().act();
65  i->expired_flag() = true;
66  i = remove_threshold(i);
67  if (i == init.pending.end()) {
68  break;
69  }
70  }
71 }
TW_Pending_List pending
The ordered queue of pending thresholds.
static TW_Pending_List::iterator remove_threshold(typename TW_Pending_List::iterator position)
iterator end()
Returns an iterator pointing one past the last element in the list.
EList< Pending_Element< typename Traits::Threshold > >::iterator iterator
A non-const iterator to traverse the list.
iterator begin()
Returns an iterator pointing to the beginning of the list.
template<typename Traits >
Threshold_Watcher& Parma_Polyhedra_Library::Threshold_Watcher< Traits >::operator= ( const Threshold_Watcher< Traits > &  )
private
template<typename Traits >
Threshold_Watcher< Traits >::TW_Pending_List::iterator Parma_Polyhedra_Library::Threshold_Watcher< Traits >::remove_threshold ( typename TW_Pending_List::iterator  position)
staticprivate

Definition at line 41 of file Threshold_Watcher_templates.hh.

41  {
42  typename TW_Pending_List::iterator i = init.pending.erase(position);
43  if (init.pending.empty()) {
44  Traits::check_function = 0;
45  }
46  return i;
47 }
bool empty() const
Returns true if and only if the list is empty.
TW_Pending_List pending
The ordered queue of pending thresholds.
iterator erase(iterator position)
Removes the element pointed to by position, returning an iterator pointing to the next element...
EList< Pending_Element< typename Traits::Threshold > >::iterator iterator
A non-const iterator to traverse the list.

Member Data Documentation

template<typename Traits >
bool Parma_Polyhedra_Library::Threshold_Watcher< Traits >::expired
private

Definition at line 56 of file Threshold_Watcher_defs.hh.

template<typename Traits >
const TW_Handler& Parma_Polyhedra_Library::Threshold_Watcher< Traits >::handler
private

Definition at line 57 of file Threshold_Watcher_defs.hh.

template<typename Traits >
Parma_Polyhedra_Library::Threshold_Watcher< Traits >::Initialize Parma_Polyhedra_Library::Threshold_Watcher< Traits >::init
staticprivate

Definition at line 68 of file Threshold_Watcher_defs.hh.

template<typename Traits >
TW_Pending_List::iterator Parma_Polyhedra_Library::Threshold_Watcher< Traits >::pending_position
private

Definition at line 58 of file Threshold_Watcher_defs.hh.


The documentation for this class was generated from the following files: