1 /********************* */
4 ** Original author: Tim King
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2016 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Utility classes for listeners and collections of listeners.
14 ** Utilities for the development of a Listener interface class. This class
15 ** provides a single notification that must be overwritten. This file also
16 ** provides a utility class for a collection of listeners and an RAII style
17 ** RegisterListener class for managing the relationship between Listeners
21 #include "cvc4_public.h"
23 #ifndef __CVC4__LISTENER_H
24 #define __CVC4__LISTENER_H
31 * Listener interface class.
33 * The interface provides a notify() function.
35 class CVC4_PUBLIC Listener
{
40 /** Note that notify may throw arbitrary exceptions. */
41 virtual void notify() = 0;
45 * ListenerCollection is a list of Listener instances.
46 * One can add and remove Listeners.
48 * ListenerCollection does not own the memory of the Listeners.
49 * As a sanity check, it asserted that all of its listeners
52 class CVC4_PUBLIC ListenerCollection
{
54 typedef std::list
<Listener
*> ListenerList
;
55 typedef ListenerList::iterator iterator
;
59 ~ListenerCollection();
61 iterator
addListener(Listener
* listener
);
63 void removeListener(iterator position
);
70 ListenerList d_listeners
;
74 * RegisterListener is an RAII utility function for using Listener
75 * with ListenerCollection.
77 * On construction, the RegisterListener takes a ListenerCollection, collection,
78 * and a Listener*, listener. It takes over the memory for listener. It then
79 * add listener to collection. On destruction it removes listener and calls
82 * Because of this usage, a RegisterListener must be destroyed before
85 class CVC4_PUBLIC RegisterListener
{
87 RegisterListener(ListenerCollection
* collection
, Listener
* listener
);
92 ListenerCollection::iterator d_position
;
93 ListenerCollection
* d_collection
;
99 #endif /* __CVC4__LISTENER_H */