basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/include/basix/dynamic.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : dynamic.hpp
00004 * DESCRIPTION: Dynamic objects, capable of updating themselves automatically
00005 * COPYRIGHT  : (C) 2008  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 * Observers of dynamic objects
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 * The dynamic class
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 } // namespace mmx
00099 #endif // __DYNAMIC_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines