Update of /cvsroot/simspark/simspark/spark/zeitgeist In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10095 Added Files: Makefile.am class.cpp class.h class_c.cpp core.cpp core.h corecontext.cpp corecontext.h leaf.cpp leaf.h leaf_c.cpp node.cpp node.h node_c.cpp object.cpp object.h object_c.cpp object_c.h parameterlist.cpp parameterlist.h zeitgeist.cpp zeitgeist.h Log Message: --- NEW FILE: zeitgeist.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: zeitgeist.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef ZEITGEIST_ZEITGEIST_H #define ZEITGEIST_ZEITGEIST_H #include "core.h" #include "corecontext.h" #include "scriptserver/scriptserver.h" #include "logserver/logserver.h" #include <boost/shared_ptr.hpp> namespace zeitgeist { /** \class Zeitgeist is the main class, which initializes the Zeitgeist framework, manages the core and the main core context. It is the basic interface to the client code. */ class Zeitgeist { // // functions // public: /** constructs the main core and starts the zeitgeist framework. dotName gives the name of the directory in the user's home directory, where the default init scripts are searched. */ Zeitgeist(std::string dotName); /** constructs the main core as above but changes the relative path prefix used by the ScriptServer prior to running the zeitgeist init script. */ Zeitgeist(std::string dotName, std::string relPathPrefix); ~Zeitgeist(); /** creates a new corecontext */ boost::shared_ptr<CoreContext> CreateContext(); /** returns a pointer to the main core */ boost::shared_ptr<Core>& GetCore(); private: /** allocates and sets up the main core */ void ConstructCore(); /** runs the zeitgeist init script. dotName is the name of the users local directory, where the init scripts are searched */ void RunInitScript(std::string dotName); // // members // private: /** the main core */ boost::shared_ptr<Core> mCore; }; } //namespace zeitgeist #endif //ZEITGEIST_ZEITGEIST_H --- NEW FILE: leaf.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: leaf.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Leaf HISTORY: 04.06.2002 MK - initial version 13.06.2002 MK - reworked Base to use a quad-linked tree 15.06.2002 MK - split Base up into Base and Node classes 02.09.2002 MK - removed quad-link 22.02.2003 MK - renamed to Leaf */ #ifndef ZEITGEIST_LEAF_H #define ZEITGEIST_LEAF_H #include <list> #include <string> #include "object.h" namespace zeitgeist { /** Leaf defines the beginning of the hierarchy. A Leaf object can reside within the hierarchy, but cannot have children! */ class Leaf : public Object { friend class Node; // // types // public: typedef std::list< boost::shared_ptr<Leaf> > TLeafList; // // functions // public: /** constructs a leaf with the given name */ Leaf(const std::string &name = "<unnamed>"); virtual ~Leaf(); /** returns a reference to the name of the leaf */ std::string& GetName() { return mName; } /** returns a constant reference to the name of the leaf */ const std::string& GetName() const { return mName; } // hierarchy /** returns a pointer to the parent of the leaf */ boost::weak_ptr<Node>& GetParent(); /** returns a constant pointer to the parent of the leaf */ const boost::weak_ptr<Node>& GetParent() const; /** defines an interface to get a pointer to a child (i.e. node or leaf) with the given name, which can be searched recursively. The class Leaf will always return an empty reference */ virtual boost::shared_ptr<Leaf> GetChild(const std::string &name, bool recursive = false); /** defines an interface to get a pointer to child of the given class type, which can be searched recursively. The class Leaf will always return an empty reference */ virtual boost::shared_ptr<Leaf> GetChildOfClass(const std::string &name, bool recursive = false); /** defines an interface to get the fist child supporting the class 'name' (i.e. nodes of a type equal to or derived from the class 'name'), which can be searched recursively. The class Leaf will always return an empty reference */ virtual boost::shared_ptr<Leaf> GetChildSupportingClass(const std::string &name, bool recursive = false); /** defines an interface to get the fist child supporting the class 'name' (i.e. nodes of a type equal to or derived from the class 'name'), which can be searched recursively. The class Leaf will always return an empty reference. This implementation of FindChildSupportingClass does not rely on the associated zeitgeist class name but uses the c++ typeid system. */ template<class CLASS> boost::shared_ptr<CLASS> FindChildSupportingClass(bool recursive = false) { TLeafList::iterator lstEnd = end(); // avoid repeated virtual calls for (TLeafList::iterator i = begin(); i != lstEnd; ++i) { // check if we have found a match and return it boost::shared_ptr<CLASS> child = boost::shared_dynamic_cast<CLASS>(*i); if (child.get() != 0) { return child; } if (recursive) { return (*i)->FindChildSupportingClass<CLASS>(recursive); } } return boost::shared_ptr<CLASS>(); } /** defines an interface to get a list of children. The Leaf class will always return an empty list */ virtual void GetChildren(const std::string &name, TLeafList &baseList, bool recursive = false); /** defines an interface to get a list to all children of type 'name'. The Leaf class will always return an empty list */ virtual void GetChildrenOfClass(const std::string &name, TLeafList &baseList, bool recursive = false); /** defines an interface to get a list to all children supporting a class 'name' i.e. they are an instance of that class or are derived from it. The Leaf class will always return an empty list */ virtual void GetChildrenSupportingClass(const std::string &name, TLeafList &baseList, bool recursive = false); /** constructs a list of all children supporting a class 'name' i.e. they are an instance of that class or are derived from it. This implementation of GetChildrenSupportingClass does not rely on the associated zeitgeist class name but uses the c++ typeid system. */ template<class CLASS> void ListChildrenSupportingClass(TLeafList& list, bool recursive = false) { TLeafList::iterator lstEnd = end(); // avoid repeated virtual calls for (TLeafList::iterator i = begin(); i != lstEnd; ++i) { // check if we have found a match and add it boost::shared_ptr<CLASS> child = boost::shared_dynamic_cast<CLASS>(*i); if (child.get() != 0) { list.push_back(child); } if (recursive) { (*i)->ListChildrenSupportingClass<CLASS>(list,recursive); } } } /** defines an interface to get the first parent node on the way up the hierarchy that supports a class 'name', i.e. is an instance of that class or is derived from it. */ virtual boost::weak_ptr<Node> GetParentSupportingClass(const std::string &name) const; /** defines an interface to get the first parent node on the way up the hierarchy that supports a class 'name', i.e. is an instance of that class or is derived from it. This implementation of GetParentSupportingClass does not rely on the associated zeitgeist class name but uses the c++ typeid system. */ template<class CLASS> boost::weak_ptr<CLASS> FindParentSupportingClass() const; // { // boost::shared_ptr<Node> node // = boost::shared_static_cast<Node>(make_shared(GetParent())); // while (node.get() != 0) // { // boost::shared_ptr<CLASS> test = // boost::shared_dynamic_cast<CLASS>(node); // if (test.get() != 0) // { // return test; // } // node = boost::shared_static_cast<Node>(make_shared(node->GetParent())); // } // return boost::shared_ptr<CLASS>(); // } /** defines an interface to test if this node is a leaf. Only the TLeaf class will return true */ virtual bool IsLeaf() const; /** removes base from the set of children. */ virtual void RemoveChildReference(const boost::shared_ptr<Leaf> &base); /** adds base to the set of children and sets the parent of base to be this node */ virtual bool AddChildReference(const boost::shared_ptr<Leaf> &base); /** detaches this node and its hierarchy from its parent. */ void Unlink(); /** unlinks all child nodes */ virtual void UnlinkChildren(); /** writes debug data to stdout */ virtual void Dump() const; /** update variables from a script */ virtual void UpdateCached() {} /** constructs the full path of this node by walking up the tree. Cosecutive calls return a cached copy of the full path to avoid the expensive tree walk. */ const std::string& GetFullPath() const; /** clears any cached data (e.g. the cached full path and forces the node to recalculate all values */ void ClearCachedData() const; /** sets the name of this node */ void SetName(const std::string &name) { mName = name; ClearCachedData(); } // iterator helpers virtual TLeafList::iterator begin(); virtual TLeafList::const_iterator begin() const; virtual TLeafList::iterator end(); virtual TLeafList::const_iterator end() const; protected: /** called from within UpdatCached; override to perform node specific updates */ virtual void UpdateCachedInternal() {} /** Sets the parent of this node. It has to be implemented 'very carefully'. The parent object always holds a shared pointer reference to mSelf. What we have to do is 'get' the shared reference, remove it from the old parent. Insert it into the new parent and change the parent pointer. */ void SetParent(const boost::shared_ptr<Node> &parent); /** This method is called, when the hierarchy object has been linked to a parent. At that point, traversal can commence. It can be overridden to support custom 'link' behavior. */ virtual void OnLink(); /** This rountine is called, before the hierarchy object is removed from the parent. It can be overridden to support custom 'unlink' behavior. */ virtual void OnUnlink(); private: Leaf(const Leaf &obj); Leaf& operator=(const Leaf &obj); // // members // protected: /** This pointer holds a link to the parent of this node. It has to be at least a Node, as that is the first class, which can hold children. We use a weak pointer to break the cyclic dependency. */ boost::weak_ptr<Node> mParent; private: /** the name of the node */ std::string mName; /** temporary cached full path of this node in the hierarchy */ mutable std::string *mCachedFullPath; }; /** the class object declaration for Leaf has been moved to class.h to break * circular inclusion between class.h and leaf.h */ } //namespace zeitgeist; #endif //ZEITGEIST_LEAF_H --- NEW FILE: parameterlist.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: parameterlist.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef ZEITGEIST_PARAMETERLIST_H #define ZEITGEIST_PARAMETERLIST_H #include <boost/any.hpp> #include <vector> #include <string> #include <salt/vector.h> namespace zeitgeist { class ParameterList; /** \class ParameterList manages a list of values. Boost::Any is used as a typesafe container to realize a sequence of values of arbitrary types. */ class ParameterList { public: typedef std::vector<boost::any> TVector; protected: TVector mList; public: ParameterList(); virtual ~ParameterList(); /** inserts a value at the end of the managed sequence */ void AddValue(const boost::any& value); /** inserts an empty ParameterList as a new value at the end of the managed sequence and returns a reference to the new list. Using AddList instead of AddValue avoids copying a list on insertion. */ ParameterList& AddList(); /** returns the number of values contained in the managed sequence */ int GetSize() const; /** returns true if the managed sequence is empty */ bool IsEmpty() const; /** removes all elements from the managed sequence */ void Clear(); /** removes the first element from the managed sequence */ void Pop_Front(); /** removes the last element from the managed sequence */ void Pop_Back(); /** returns an iterator pointing at the begin of the managed sequence */ TVector::const_iterator begin() const; /** returns an iterator pointing at the end of the managed sequence */ TVector::const_iterator end() const; /** returns an iterator pointing at the nth element of the managed sequence */ TVector::const_iterator operator[] (int n) const; /** returns an iterator pointing at the nth element of the managed sequence */ TVector::iterator operator[] (int n); /** returns an iterator pointing at the begin of the managed sequence */ TVector::iterator begin(); /** returns an iterator pointing at the end of the managed sequence */ TVector::iterator end(); /** AdvanceAnyValue is a generic templated helper function for consumers of ParameterLists. It tries to cast the parameter at iter to a value of type T. If successful it returns true, assigns the casted parameter to value and increments the iterator iter. Otherwise false is returned and value and iter are unchanged. Note that AdvanceValue increments iter to transparently allow specialized functions for types that are represented by more than one entry in the ParameterList. An example is a three dimensional vector represented by a sequence of three floats. Note: the AdvanceAnyValue and AdvanceValue have distinct names, as C++ does not support partly specialized template function (currently only partly specialized classes) and would always call the generic template function instead of a partly specialized variant. \param iter position of the parameter \param value extracted value of the parameter \return true if extraction successful, false otherwise */ template<typename T> bool AdvanceAnyValue(TVector::const_iterator& iter, T& value) const { return GetValueInternal<T,T>(iter,value); } /** GetValue is a generic templated helper function for consumers of ParameterLists. It has the same semantics as it's corresponding AdvanceValue except that it takes a const reference to iter that it does not increment. */ template<typename T> f_inline bool GetValue(const TVector::const_iterator& iter, T& value) const { TVector::const_iterator tmp = iter; return AdvanceValue(tmp,value); } template<typename T> f_inline bool GetAnyValue(const TVector::const_iterator& iter, T& value) const { TVector::const_iterator tmp = iter; return AdvanceAnyValue(tmp,value); } /** Below are AdvanceValue helper functions spezialiced for a type */ bool AdvanceValue(TVector::const_iterator& iter, std::string& value) const; bool AdvanceValue(TVector::const_iterator& iter, float& value) const; bool AdvanceValue(TVector::const_iterator& iter, double& value) const; bool AdvanceValue(TVector::const_iterator& iter, int& value) const; bool AdvanceValue(TVector::const_iterator& iter, bool& value) const; bool AdvanceValue(TVector::const_iterator& iter, unsigned int& value) const; bool AdvanceValue(TVector::const_iterator& iter, salt::Vector3f& value) const; bool AdvanceValue(TVector::const_iterator& iter, salt::Vector2f& value) const; protected: /** This is a specialized GetValue helper to read any salt::TVector from a TParameterList. It first tries to interprete a single element of the TParameterList as a TVector. If this fails it tries to build a vector from a sequence of values in the ParameterList. Depending on the way the Vector is built iter is incremented either by one element or the number of scalar elements that make up a vector of the given type. Note: If GetVectorValue builds a vector from a sequence of scalars it uses the AdvanceValue function specialized for the scalar value type of that TVector. For example in the common case of a float vector this enables GetVectorValue to handle any mixture of float, int and string representation within the TParameterList. \param iter \param value a vector extracted from a parameter list \return true if extraction successful */ template <typename DATATYPE, int ELEMENTS, typename TYPE> f_inline bool GetVectorValue(TVector::const_iterator& iter, salt::TVector<DATATYPE,ELEMENTS,TYPE>& value) const { typedef salt::TVector<DATATYPE,ELEMENTS,TYPE> Vector; // try to cast to Vector from a single value if (GetValueInternal<Vector,Vector>(iter,value)) { return true; } // a direct cast faild. try to construct a vector from // three consecutive values TVector::const_iterator test = iter; Vector vec; int i=0; while ( (i<ELEMENTS) && (test != mList.end()) ) { if (! AdvanceValue(test,vec[i])) { break; } ++i; // iterator test is incremented within the // call to GetValue() } if (i != ELEMENTS) { // there were not enough components to build // the vector return false; } value = vec; iter = test; return true; } /** This is a specialized GetValue helper to read a scalar value from a TParameterList. It tries to generate the value from a string representation */ template<typename TYPE> f_inline bool ConvertStringValue(TVector::const_iterator& iter, TYPE& value) const { const boost::any& param = (*iter); try { std::string str; if (param.type() == typeid(std::string)) { str = boost::any_cast<std::string>(param); } else if (param.type() == typeid(char*)) { str = boost::any_cast<char*>(param); } else { return false; } value = static_cast<TYPE>(atof(str.c_str())); ++iter; } catch(const std::bad_cast&) { return false; } return true; } /** helper that tries to any_cast the TFrom value at iter to a TTo Value, on success it returns true and advances the iterator */ template<typename TFrom, typename TTo> f_inline bool GetValueInternal(TVector::const_iterator& iter, TTo& value) const { const boost::any& param = (*iter); if (param.type() != typeid(TFrom)) { return false; } try { value = static_cast<TTo>(boost::any_cast<TFrom>(*iter)); ++iter; return true; } catch(const std::bad_cast&) { return false; } } }; } #endif // ZEITGEIST_PARAMETERLIST_H --- NEW FILE: corecontext.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: corecontext.cpp,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "corecontext.h" #include <salt/path.h> #include "leaf.h" #include "node.h" #include "core.h" #include <iostream> using namespace boost; using namespace salt; using namespace std; using namespace zeitgeist; CoreContext::CoreContext(const boost::shared_ptr<Core> &core, const boost::shared_ptr<Leaf> &root) : mCore(core), mObject(root) { } CoreContext::~CoreContext() { //cout << "~CoreContext()" << endl; } boost::shared_ptr<Leaf> CoreContext::New(const std::string& className, const std::string& pathStr) { // first, we try to create the class with the core shared_ptr<Object> instance = mCore->New(className); if (instance.get()) { // now, we check the type by dynamic casting to leaf shared_ptr<Leaf> leaf = shared_static_cast<Leaf>(instance); if (leaf.get() != NULL) { // we have created the instance, now we install it at the location // stored in pathName if (Install(leaf, pathStr) == true) { mObject = leaf; return leaf; } } } // return default constructed 'NULL' object return shared_ptr<Leaf>(); } bool CoreContext::Delete (const std::string &name) { shared_ptr<Leaf> leaf = Get(name); if (leaf.get()) { leaf->Unlink(); return true; } return false; } boost::shared_ptr<Leaf> CoreContext::Select(const std::string &pathStr) { shared_ptr<Leaf> leaf = Get(pathStr); if (leaf.get()) { mObject = leaf; } return leaf; } bool CoreContext::Install(const boost::shared_ptr<Leaf> &leaf, const std::string &pathStr, bool isNamed) { //cout << "CoreContext(" << (void*) this << ") Install '" << pathStr << "'" << endl; Path path(pathStr); if(! isNamed) { // we need at least one token to 'name' the leaf class if (path.IsEmpty()) { return false; } leaf->SetName(path.Back()); path.PopBack(); // now, we have named the leaf object, so we can install it } shared_ptr<Leaf> current; // check if we have a relative or absolute path if (path.IsAbsolute()) { current = mCore->GetRoot(); } else { current = mObject; } if (! current.get()) { return false; } while (! path.IsEmpty()) { current = mCore->GetChild(current, path.Front()); if (! current.get()) { return false; } path.PopFront(); } return current->AddChildReference(leaf); } boost::shared_ptr<Leaf> CoreContext::Get(const std::string& pathStr) { return mCore->Get(pathStr, mObject); } bool CoreContext::Test(const std::string& pathStr) { return mCore->Test(pathStr, mObject); } void CoreContext::ListObjects() const { Leaf::TLeafList::iterator i; for (i = mObject->begin(); i != mObject->end(); ++i) { cout << (*i)->GetName(); if (!(*i)->IsLeaf()) { cout << "/"; } cout << endl; } } void CoreContext::Push() { if (mObject.get() != NULL) mObjectStack.push_front(mObject); } void CoreContext::Pop() { if (!mObjectStack.empty()) { mObject = mObjectStack.front(); mObjectStack.pop_front(); } } void CoreContext::Dir() const { for ( TObjectStack::const_iterator i = mObjectStack.begin(); i != mObjectStack.end(); ++i ) { cout << (*i)->GetName(); if (!(*i)->IsLeaf()) { cout << "/"; } cout << endl; } } --- NEW FILE: class.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: class.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Class HISTORY: 04.06.2002 MK - initial version */ #ifndef ZEITGEIST_CLASS_H #define ZEITGEIST_CLASS_H #include <zeitgeist/scriptserver/gcvalue.h> #ifdef HAVE_CONFIG_H #include <config.h> #endif #ifdef HAVE_HASH_MAP #include <hash_map> #else #include <map> #endif #include <string> #include <vector> #include <list> #include <salt/defines.h> #include <salt/sharedlibrary.h> #include "leaf.h" #include "parameterlist.h" namespace zeitgeist { #define CLASS(className) Class_##className #define DECLARE_CLASS(className)\ class CLASS(className) : public zeitgeist::Class\ {\ public:\ CLASS(className)() : zeitgeist::Class(#className) { DefineClass(); }\ zeitgeist::Object* CreateInstance() const\ {\ zeitgeist::Object *instance = new className();\ return instance;\ }\ private:\ void DefineClass();\ }; #define DECLARE_ABSTRACTCLASS(className)\ class CLASS(className) : public zeitgeist::Class\ {\ public:\ CLASS(className)() : zeitgeist::Class(#className) { DefineClass(); }\ private:\ void DefineClass();\ }; // note the 'unused' attribute suppresses compiler warnings if the // 'in' parameter is not accessed in the function implementation #define FUNCTION(className,functionName)\ static zeitgeist::GCValue functionName(className *obj, \ __attribute__((unused)) const zeitgeist::ParameterList &in) #define DEFINE_FUNCTION(functionName)\ mFunctions[#functionName] = (TCmdProc) &functionName; #define DEFINE_BASECLASS(baseClass)\ mBaseClasses.push_back(#baseClass); // // Export stuff // #define ZEITGEIST_EXPORT_BEGIN()\ using namespace boost;\ using namespace salt;\ using namespace zeitgeist;\ extern "C"{\ SHARED_LIB_EXPORT void Zeitgeist_RegisterBundle(std::list <shared_ptr<Class> > &classes){ #define ZEITGEIST_EXPORT_EX(className, path)\ classes.push_back(shared_ptr<Class>(new CLASS(className))); #define ZEITGEIST_EXPORT(className) ZEITGEIST_EXPORT_EX(className, "") #define ZEITGEIST_EXPORT_END()\ }} // forward declarations class Core; /** This class is quite essential for the Zeitgeist Core. Every class * which wants to be managed by Zeitgeist will have to derive a class * object from this class and override the factory method. Only * decendants from Object are able to use Class properly and the * factory method returns a Object pointer. * * A Class object is characterized by several parameters: * * - the name of the class * - the version of the class * * A version is stored as an unsigned 32-bit integer, with each byte * representing a version number. So ABCD would be A.B.C.D. That way a * simple integer comparison can be used for newer version queries. * * Class objects also are the key to providing Zeitgeist with a plugin * interface. The Core is responsible for managing all Class objects it * knows. It is possible to export Class objects from a shared library * through a unified interface, therefore enabling Class objects to be * added at runtime to the Core. */ class Class : public Leaf { // friends friend class Object; friend class Core; // // types // public: /** defines a signature for a function used as the c++ implementation of a member function exported to a script language. It receives a pointer to an instance of the class from which it is a member function along with a list of paramters. */ typedef GCValue (*TCmdProc)(Object* , const zeitgeist::ParameterList &in); typedef std::list<std::string> TStringList; private: /** defines a list of pointers to object instances */ typedef std::list< boost::weak_ptr<Object> > TObjectList; /** defines a mapping from member names to command procedures */ #ifdef HAVE_HASH_MAP typedef std::hash_map<std::string, TCmdProc> TCommandMap; #else typedef std::map<std::string, TCmdProc> TCommandMap; #endif // // functions // public: /** constructs a class object for the class 'name' */ Class(const std::string &name); virtual ~Class(); /** creates a new instance of the represented class */ boost::shared_ptr<Object> Create(); /** returns a pointer to the core this class is attached to */ boost::shared_ptr<Core> GetCore() const; /** sets the bundle, this class was loaded from */ void SetBundle(const boost::shared_ptr<salt::SharedLibrary> &bundle); /** the command procedure for a function */ TCmdProc GetCmdProc(const std::string &functionName) const; /** returns a list of base class names */ const TStringList& GetBaseClasses() const; /** returns true iff the class supports a given 'interface', * i.e. the base class hierarchy contains the class 'name' */ bool SupportsClass(const std::string &name) const; /** returns true iff the class supports a given command, i.e. to * this class or to one of its base classes the given command * procedure is registered */ bool SupportsCommand(const std::string &name) const; protected: /** adds an instance to the local list of instances */ void AttachInstance(const boost::weak_ptr<Object> &instance); /** removes an instance from the local list of instances */ void DetachInstance(const boost::weak_ptr<Object> &instance); private: Class(const Class &obj); Class& operator=(const Class &obj); /** pure virtual function which creates instances */ virtual Object* CreateInstance() const; /** pure virtual function which initializes the script callbacks and links to parent classes */ virtual void DefineClass() = 0; /** set the core, which this class belongs to */ void AttachTo(const boost::weak_ptr<Core>& core); // // members // protected: TCommandMap mFunctions; TStringList mBaseClasses; private: boost::weak_ptr<Core> mCore; /** a shared pointer to the bundle, this class object came * from. So, if all references to the class object are * deleted, the shared library will be freed. */ boost::shared_ptr<salt::SharedLibrary> mBundle; /** a list of instances, which were created by this class object */ TObjectList mInstances; }; /** this is the class object beloging to the class 'zeitgeist::Class'. */ class CLASS(Class) : public Class { public: CLASS(Class)() : Class("ClassClass") { DefineClass(); } private: void DefineClass(); }; /** declare the clss object for leaf. Put here to avoid a circular dependency between class inheriting from leaf and leaf needing class to inherit its corresponding class object */ DECLARE_CLASS(Leaf); } // namespace zeitgeist #endif //ZEITGEIST_CLASS_H --- NEW FILE: zeitgeist.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: zeitgeist.cpp,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "zeitgeist.h" #include <iostream> #include <sstream> using namespace std; using namespace zeitgeist; Zeitgeist::Zeitgeist(string dotName) { ConstructCore(); RunInitScript(dotName); } Zeitgeist::Zeitgeist(string dotName, string relPathPrefix) { ConstructCore(); if (mCore->GetScriptServer() == 0) { return; } mCore->GetScriptServer()->SetInitRelPathPrefix(relPathPrefix); RunInitScript(dotName); } Zeitgeist::~Zeitgeist() { // this Zeitgeist object owns the only shared_ptr to the // core. Class objects only own weak_ptrs to the core. Destructing // the core implicitly after this destructor finishes, invalidates // our shared_ptr prior to the call to Core::~Core() and all // instances are left without a valid core reference on shutdown // (calls to OnUnlink). Therefore we destruct the core and the hierarchy explicitly // with the mCore reference intact. mCore->Desctruct(); } void Zeitgeist::ConstructCore() { mCore = boost::shared_ptr<Core>(new Core()); mCore->Construct(mCore); } void Zeitgeist::RunInitScript(string dotName) { if (mCore->GetScriptServer() == 0) { return; } // setup the dot directory in the script server mCore->GetScriptServer()->SetDotName(dotName); // run the zeitgeist init script mCore->GetScriptServer()->RunInitScript ( "zeitgeist.rb", "lib/zeitgeist", ScriptServer::IS_COMMON ); } boost::shared_ptr<CoreContext> Zeitgeist::CreateContext() { return mCore->CreateContext(); } boost::shared_ptr<Core>& Zeitgeist::GetCore() { return mCore; } --- NEW FILE: corecontext.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: corecontext.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. CoreContext HISTORY: 05.07.2002 MK - initial version */ #ifndef ZEITGEIST_CORECONTEXT_H #define ZEITGEIST_CORECONTEXT_H #include <string> #include <list> #include <boost/weak_ptr.hpp> #include <boost/shared_ptr.hpp> namespace zeitgeist { class Core; class Leaf; /** This class is responsible for representing a browsing context * within the object hierarchy. It is usually created by the Core * object. * * Why was the browsing context separated from the Core? * * Well, the usage scenario of the framework envisions multiple clients * browsing the same object hierarchy. Therefore it was necessary to * place the current browsing context into a distinct object. */ class CoreContext { // // types // private: typedef std::list< boost::shared_ptr<Leaf> > TObjectStack; // // functions // public: /** constructs a core context * \param 'core' is the core this context belongs to * \param 'root' is the root of the core */ CoreContext(const boost::shared_ptr<Core> &core, const boost::shared_ptr<Leaf> &root); virtual ~CoreContext(); /** constructs a new class of type 'className' below the node * described by 'pathStr'. The function assumes that only * compatible classes are created this way. Compatible means * 'starting at Leaf' in the hierarchy. It returns a reference to * the constructed object. */ boost::shared_ptr<Leaf> New(const std::string& className, const std::string& pathStr); bool Delete(const std::string& name); /** selects the currenlty active object to be the one described the by path expression pathStr. It returns a reference to the selected object*/ boost::shared_ptr<Leaf> Select(const std::string& pathStr); /** inserts the object 'leaf' below the object described by the path expression 'pathStr' into the hierarchy and returns true on success */ bool Install(const boost::shared_ptr<Leaf>& leaf, const std::string& pathStr, bool isNamed = false); /** returns a reference to the object described by the path expression pathStr */ boost::shared_ptr<Leaf> Get(const std::string& pathStr); /** returns true if the object referenced by the path expression pathStr exists */ bool Test(const std::string& pathStr); /** returns the currently selected object */ boost::shared_ptr<Leaf> GetObject() const { return mObject; } /** returns the core this context belongs to */ boost::shared_ptr<Core> GetCore() const { return mCore; } /** prints the children of the currently selected object to stdout */ void ListObjects() const; /** pushs the current active object on the object stack */ void Push(); /** makes the top of the object stack the current object, no change if stack is empty */ void Pop(); /** prints the objects on the stack to stdout */ void Dir() const; private: CoreContext(const CoreContext& obj); CoreContext& operator=(const CoreContext& obj); // // members // private: /** pointer to the core object this context belongs to */ boost::shared_ptr<Core> mCore; /** the current active object */ boost::shared_ptr<Leaf> mObject; /** the current working path */ std::string mPath; /** the object stack */ TObjectStack mObjectStack; }; } // namespace zeitgeist #endif //ZEITGEIST_CORECONTEXT_H --- NEW FILE: class.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: class.cpp,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "class.h" #include "leaf.h" #include "core.h" #include <iostream> using namespace boost; using namespace std; using namespace zeitgeist; Class::Class(const std::string &name) : Leaf(name) { } Class::~Class() { if (mInstances.size() > 0) { cout << "(Class) Leaked " << mInstances.size() << " instances..." << endl; for ( TObjectList::iterator i = mInstances.begin(); i != mInstances.end(); ++i ) { if (shared_ptr<Object> j = i->lock()) { cout << " " << j.get() << endl; } else { cout << " " << "(expired)" << endl; } } } } boost::shared_ptr<Object> Class::Create() { shared_ptr<Object> obj(CreateInstance()); if (obj.get()) { if (obj->Construct(obj, shared_static_cast<Class> (make_shared(GetSelf()))) == true) { // successfully constructed AttachInstance(obj); } else { obj.reset(); } } return obj; } boost::shared_ptr<Core> Class::GetCore() const { if (mCore.expired()) { std::cerr << "(Class) ERROR: failed to get zeitgeist Core for class '" << GetName() << "'" << std::endl; } return make_shared(mCore); } void Class::AttachInstance(const boost::weak_ptr<Object> &instance) { mInstances.push_back(instance); } void Class::DetachInstance(const boost::weak_ptr<Object> &instance) { // mInstances.remove() doesn't work in this case because // operator== is not implemented for weak_ptr TObjectList::iterator first = mInstances.begin(); TObjectList::iterator last = mInstances.end(); while (first != last) { TObjectList::iterator next = first; ++next; boost::shared_ptr<Object> i = first->lock(); boost::shared_ptr<Object> j = instance.lock(); if (i.get() == j.get()) { mInstances.erase(first); } first = next; } } Object* Class::CreateInstance() const { return NULL; } void Class::AttachTo(const boost::weak_ptr<Core>& core) { mCore = core; } void Class::SetBundle(const boost::shared_ptr<salt::SharedLibrary> &bundle) { mBundle = bundle; } Class::TCmdProc Class::GetCmdProc(const std::string &functionName) const { TCommandMap::const_iterator cmd = mFunctions.find(functionName); if (cmd != mFunctions.end()) { return (*cmd).second; } // ok, we don't have the requested function, so we'll try the base // class objects shared_ptr<Leaf> classDir = GetCore()->Get("/classes"); for ( TStringList::const_iterator baseClass = mBaseClasses.begin(); baseClass != mBaseClasses.end(); ++baseClass ) { // this should get the base class object (it has to live on // the same level of the hierarchy as this class object) shared_ptr<Class> theClass = shared_static_cast<Class> (GetCore()->Get(*baseClass, classDir)); if (theClass) { // now, we ask the class object, if it knows the command // in question TCmdProc theCmd = theClass->GetCmdProc(functionName); //printf("theCmd: %s - %d\n", functionName.c_str(), theCmd); if (theCmd != NULL) { // here we have found the command and return it return theCmd; } } } return NULL; } const Class::TStringList& Class::GetBaseClasses() const { return mBaseClasses; } bool Class::SupportsCommand(const std::string & name) const { return (GetCmdProc(name) != 0); } bool Class::SupportsClass(const std::string &name) const { if (GetName().compare(name) == 0) { return true; } // check base-classes shared_ptr<Leaf> classDir = GetCore()->Get("/classes"); for ( TStringList::const_iterator i = mBaseClasses.begin(); i != mBaseClasses.end(); ++i ) { shared_ptr<Class> theClass = shared_static_cast<Class> (GetCore()->Get(*i, classDir)); if (theClass) { if (theClass->SupportsClass(name)) { return true; } } else { cout << "(Class) WARNING: Illegal BaseClass '" << (*i) << "' in Class '" << GetName() << "'" << endl; } } return false; } --- NEW FILE: object_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: object_c.cpp,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "object_c.h" using namespace zeitgeist; void CLASS(Object)::DefineClass() { } --- NEW FILE: Makefile.am --- if DEBUG pkglib_LTLIBRARIES = libzeitgeist_debug.la libzeitgeist_debug_la_SOURCES = $(sources) libzeitgeist_debug_la_CXXFLAGS = -O -g -W -Wall libzeitgeist_debug_la_LIBADD = @RUBY_LDFLAGS@ @RUBY_LDADD@ libzeitgeist_debug_la_LDFLAGS = -version-info @zeitgeist_version_info@ else pkglib_LTLIBRARIES = libzeitgeist.la libzeitgeist_la_SOURCES = $(sources) libzeitgeist_la_CXXFLAGS = -O2 libzeitgeist_la_LIBADD = @RUBY_LDFLAGS@ @RUBY_LDADD@ libzeitgeist_la_LDFLAGS = -version-info @zeitgeist_version_info@ endif bin_SCRIPTS = zeitgeist-config AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ ## define include directory local to the pkgincludedir libpkgincludedir = $(includedir)/@PACKAGE@/zeitgeist ## architecture independent data (scripts) to be installed and distributed dist_pkgdata_DATA = zeitgeist.rb sources = \ class.cpp \ class_c.cpp \ core.cpp \ corecontext.cpp \ leaf.cpp \ leaf_c.cpp \ parameterlist.cpp \ node.cpp \ node_c.cpp \ object.cpp \ object_c.cpp \ zeitgeist.cpp \ fileserver/fileserver.cpp \ fileserver/fileserver_c.cpp \ fileserver/filesystem_c.cpp \ logserver/logserver.cpp \ logserver/logserver_c.cpp \ logserver/logserverstreambuf.cpp \ randomserver/randomserver.cpp \ randomserver/randomserver_c.cpp \ scriptserver/gcvalue.cpp \ scriptserver/rubywrapper.cpp \ scriptserver/scriptserver.cpp \ scriptserver/scriptserver_c.cpp #telnetserver/telnetdaemon.cpp \ #telnetserver/telnetserver.cpp \ #telnetserver/telnetserver_c.cpp \ #telnetserver/telnetsession.cpp nobase_libpkginclude_HEADERS = \ class.h \ core.h \ corecontext.h \ leaf.h \ parameterlist.h \ node.h \ object.h \ object_c.h \ zeitgeist.h \ fileserver/fileserver.h \ fileserver/filesystem.h \ logserver/logserver.h \ logserver/logserverstreambuf.h \ randomserver/randomserver.h \ scriptserver/gcvalue.h \ scriptserver/scriptserver.h \ scriptserver/rubywrapper.h #telnetserver/telnetdaemon.h \ #telnetserver/telnetserver.h \ #telnetserver/telnetsession.h --- NEW FILE: leaf.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: leaf.cpp,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "class.h" #include "node.h" #include <iostream> using namespace boost; using namespace std; using namespace zeitgeist; Leaf::Leaf(const std::string &name) : mName(name), mCachedFullPath(NULL) { } Leaf::~Leaf() { } boost::weak_ptr<Node>& Leaf::GetParent() { return mParent; } const boost::weak_ptr<Node>& Leaf::GetParent() const { return mParent; } boost::shared_ptr<Leaf> Leaf::GetChild(const std::string &name, bool /*recursive*/) { if (name.compare("..") == 0) { return make_shared(GetParent()); } if (name.compare(".") == 0) { return shared_static_cast<Leaf>(make_shared(GetSelf())); } return boost::shared_ptr<Leaf>(); } boost::shared_ptr<Leaf> Leaf::GetChildOfClass(const std::string &/*name*/, bool /*recursive*/) { return boost::shared_ptr<Leaf>(); } boost::shared_ptr<Leaf> Leaf::GetChildSupportingClass(const std::string &/*name*/, bool /*recursive*/) { return boost::shared_ptr<Leaf>(); } void Leaf::GetChildren(const std::string &name, TLeafList &baseList, bool /*recursive*/) { if (name.compare("..") == 0) { baseList.push_back(make_shared(GetParent())); } if (name.compare(".") == 0) { baseList.push_back(shared_static_cast<Leaf>(make_shared(GetSelf()))); } } void Leaf::GetChildrenOfClass(const std::string &/*name*/, TLeafList &/*baseList*/, bool /*recursive*/) { } void Leaf::GetChildrenSupportingClass(const std::string &/*name*/, TLeafList &/*baseList*/, bool /*recursive*/) { } boost::weak_ptr<Node> Leaf::GetParentSupportingClass(const std::string &name) const { shared_ptr<Node> node = shared_static_cast<Node>(make_shared(GetParent())); while ( (node.get() != 0) && (node->GetClass()) && (! node->GetClass()->SupportsClass(name)) ) { node = make_shared(node->GetParent()); } return weak_ptr<Node>(node); } bool Leaf::IsLeaf() const { return true; } void Leaf::RemoveChildReference(const boost::shared_ptr<Leaf> &/*base*/) { } bool Leaf::AddChildReference(const boost::shared_ptr<Leaf> &/*base*/) { return false; } void Leaf::Unlink() { // here we lose our reference to the parent SetParent(boost::shared_ptr<Node>()); } void Leaf::UnlinkChildren() { } void Leaf::Dump() const { Object::Dump(); cout << "Leaf: '" << GetName() << "'" << endl; } const std::string& Leaf::GetFullPath() const { //printf("this:getfullpath %x - %s - %x %x\n", this, GetName().c_str(), GetParent(), mCachedFullPath); if (mCachedFullPath == NULL) { std::string parentPath; if (shared_ptr<Leaf> p = GetParent().lock()) { if (p) { shared_ptr<Leaf> blah = make_shared(GetParent()); parentPath = blah->GetFullPath(); } } // no cached data available if (IsLeaf()) mCachedFullPath = new std::string(parentPath + mName); else mCachedFullPath = new std::string(parentPath + mName + "/"); } return *mCachedFullPath; } void Leaf::ClearCachedData() const { delete mCachedFullPath; mCachedFullPath = NULL; } Leaf::TLeafList gFakeChildren; Leaf::TLeafList::iterator Leaf::begin() { return gFakeChildren.begin(); } Leaf::TLeafList::const_iterator Leaf::begin() const { return gFakeChildren.begin(); } Leaf::TLeafList::iterator Leaf::end() { return gFakeChildren.end(); } Leaf::TLeafList::const_iterator Leaf::end() const { return gFakeChildren.end(); } void Leaf::SetParent(const boost::shared_ptr<Node> &newParent) { shared_ptr<Node> oldParent = make_shared(GetParent()); if (oldParent.get() != 0) { // we have a parent, so update our state shared_ptr<Leaf> self = shared_static_cast<Leaf>(make_shared(GetSelf())); // here reference count should be > 1 (at least one in the // parent, and one in this routine) assert(self.use_count() > 1); if (newParent.get() == 0) { // time to clean up OnUnlink(); ClearCachedData(); oldParent->RemoveChildReference(self); } // we remove ourself from the old parent's list of children oldParent->RemoveChildReference(self); // we add ourself to the new parent's list of children if (newParent.get() != 0) { newParent->AddChildReference(self); } } mParent = newParent; if (! mParent.expired()) { // we have been linked, so now we can do something :) OnLink(); } } void Leaf::OnLink() { } void Leaf::OnUnlink() { } --- NEW FILE: object.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: object.h,v 1.1 2005/12/05 20:59:18 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Object HISTORY: 31.08.2002 MK - initial version */ #ifndef ZEITGEIST_OBJECT_H #define ZEITGEIST_OBJECT_H #include <boost/weak_ptr.hpp> #include <boost/shared_ptr.hpp> #include "core.h" #include "parameterlist.h" namespace zeitgeist { class Class; class LogServer; class ScriptServer; /** Object is the base class of all objects in the Zeitgeist * framework. An object is characterized by a single thing, the class * which created it. The core it belongs to can be reached via the * class object. Every object holds a shared_ptr to the class object, * which created it. */ class Object { // // functions // public: /** constructs an object */ Object(); virtual ~Object(); /** sets up the internal state of the object, used by Class::Create(). * \param self is a pointer to the instance of the object, i.e. a smart this pointer * \param creator is a pointer to the class object that created this object */ bool Construct(const boost::shared_ptr<Object>& self, const boost::shared_ptr<Class>& creator); // class object /** returns the corresponding class object */ boost::shared_ptr<Class> GetClass() const; /** returns a pointer to the object */ boost::weak_ptr<Object>& GetSelf(); /** returns a constant pointer to the object */ const boost::weak_ptr<Object>& GetSelf() const; /** return a pointer to the core, this object belongs to */ boost::shared_ptr<Core> GetCore() const; /** helper function to get a reference to the FileServer */ const boost::shared_ptr<FileServer>& GetFile() const; /** helper function to get a reference to the LogServer */ ... [truncated message content] |