#ifndef __libeast_object_h__ #define __libeast_object_h__ #include #include #include #include "event.h" #include "heap.h" #include "smart_ptr.h" class Event; class Environment; // Abstract base object class class Object { public: // TODO: perhaps this belongs in operator new... Object(const string& name = ""): my_environment(NULL) { heap.add(this, name); } // and maybe this goes in operator delete (or maybe not) // TODO: resolve the confusion here between the heap deleting the object // and the object telling the heap to delete virtual ~Object() { heap.forget(this); } virtual Object& operator<< (SmartPtr rhs); const string& name() const {return heap.name(this);} void rename(const string& name); Environment& environ() const {return *my_environment;} // TODO: make this protected and accessible only to Environment::Pack void set_env(Environment* env) {my_environment = env;} protected: Environment* my_environment; }; // Abstract base environment class class Environment: public Object { public: Environment(const string& name); Environment& add(Object* obj); Environment& del(Object* obj); virtual Environment& operator<< (SmartPtr rhs); protected: struct Pack: public binary_function { void operator() (Object* obj, Environment* env) const; }; struct Kill: public binary_function { void operator() (Object* obj, Environment* env) const; }; struct Send: public binary_function, void> { void operator() (Object* obj, SmartPtr ev) const; }; deque my_objects; // Contained objects queue > my_events; // Queued events bool my_event_lock; // Processing events? // Necessary friends (necessary evils?) friend void Pack::operator() (Object*, Environment*) const; friend void Kill::operator() (Object*, Environment*) const; }; #endif