Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/agnotify.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * agnotify.h | |
7 */ | |
8 | |
9 #ifndef AGNOTIFY_H | |
10 #define AGNOTIFY_H | |
11 | |
12 #include "agstack.h" | |
13 | |
14 | |
15 class AgNotifierBase; | |
16 | |
17 class AgNotificationActionBase { | |
18 protected: | |
19 AgStack<AgNotifierBase *> notifierStack; | |
20 public: | |
21 AgNotificationActionBase() {} | |
22 virtual ~AgNotificationActionBase(); | |
23 virtual void perform() {} | |
24 AgNotificationActionBase &attach(AgNotifierBase *notifier); | |
25 void remove(AgNotifierBase *notifier); | |
26 }; | |
27 | |
28 template <class T> | |
29 class AgNotificationAction : public AgNotificationActionBase { | |
30 protected: | |
31 T *object; | |
32 void (T::*memberFunction)(); | |
33 public: | |
34 AgNotificationAction(T *x, void (T::*f)()): object(x), memberFunction(f) {} | |
35 void perform() { (object->*memberFunction)(); } | |
36 }; | |
37 | |
38 class AgNotifierBase { | |
39 protected: | |
40 AgStack<AgNotificationActionBase *> notifyStack; | |
41 void notify(); | |
42 | |
43 public: | |
44 AgNotifierBase() {} | |
45 virtual ~AgNotifierBase(); | |
46 void attach(AgNotificationActionBase *action) { | |
47 notifyStack.push(action); | |
48 } | |
49 void remove(AgNotificationActionBase *action); | |
50 }; | |
51 | |
52 template <class T> | |
53 class AgNotifier : public AgNotifierBase { | |
54 protected: | |
55 T contents; | |
56 | |
57 public: | |
58 AgNotifier(const T &d) : contents(d) {} | |
59 AgNotifier(const AgNotifier<T> &d) : contents(d.contents) {} | |
60 operator T &() { return contents; } | |
61 //T &data() { return contents; } | |
62 T *pointer() { return &contents; } | |
63 virtual void initialize(const T &d) { | |
64 contents = d; | |
65 } | |
66 virtual T &operator = (const T &d) { | |
67 contents = d; | |
68 notify(); | |
69 return contents; | |
70 } | |
71 }; | |
72 | |
73 | |
74 #endif /* AGNOTIFY_H */ |