00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __DYNAMIC_HPP
00014 #define __DYNAMIC_HPP
00015 #include <basix/routine.hpp>
00016
00018
00019 namespace mmx {
00020 class observer_rep;
00021 class observer;
00022 class dynamic_rep;
00023 class dynamic;
00024
00025 #define OUTPUT_OBSERVER 1
00026 #define ARGUMENT_OBSERVER 2
00027 #define RESULT_OBSERVER 3
00028
00029
00030
00031
00032
00033 class observer_rep: public rep_struct {
00034 public:
00035 dynamic_rep* ref;
00036
00037 inline observer_rep (dynamic_rep* ref2): ref (ref2) {}
00038 inline virtual ~observer_rep () {}
00039
00040 virtual nat observer_type () const = 0;
00041 virtual void destroy () const = 0;
00042 virtual void modify () const = 0;
00043 virtual inline void message (const generic& msg) const { (void) msg; }
00044
00045 friend class observer;
00046 friend class dynamic;
00047 };
00048
00049 class observer {
00050 INDIRECT_PROTO (observer, observer_rep)
00051 public:
00052 inline observer (): rep (NULL) {}
00053 inline friend syntactic flatten (const observer& g) { return "observer"; }
00054 friend class observer_rep;
00055 };
00056 INDIRECT_NULL_IMPL (observer, observer_rep)
00057
00058 HARD_TO_EXACT_IDENTITY_SUGAR(,observer);
00059 HARD_TO_TRUE_IDENTITY_SUGAR(,observer);
00060
00061
00062
00063
00064
00065 class dynamic_rep: public rep_struct {
00066 public:
00067 generic val;
00068 vector<observer> obs;
00069
00070 dynamic_rep (const generic& val2);
00071 ~dynamic_rep ();
00072
00073 friend class observer;
00074 friend class dynamic;
00075 };
00076
00077 class dynamic {
00078 INDIRECT_PROTO (dynamic, dynamic_rep)
00079 public:
00080 inline dynamic (): rep (NULL) {}
00081 inline dynamic (const generic& val): rep (new dynamic_rep (val)) {}
00082 dynamic (const routine& fun, const vector<dynamic>& args);
00083 friend class dynamic_rep;
00084 };
00085 INDIRECT_NULL_IMPL (dynamic, dynamic_rep)
00086
00087 extern void (*dynamic_event) (const string& id, const generic& val);
00088 syntactic flatten (const dynamic& g);
00089
00090 inline generic contents (const dynamic& d) { return inside (d) -> val; }
00091 void assign (const dynamic& d, const generic& val);
00092 void message (const dynamic& d, const generic& msg);
00093 void attach (const dynamic& d, const observer& o);
00094
00095 HARD_TO_EXACT_IDENTITY_SUGAR(,dynamic);
00096 HARD_TO_TRUE_IDENTITY_SUGAR(,dynamic);
00097
00098 }
00099 #endif // __DYNAMIC_HPP