00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ZEITGEIST_CORE_H
00023 #define ZEITGEIST_CORE_H
00024
00025 #include <string>
00026 #include <list>
00027 #include <map>
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/weak_ptr.hpp>
00030
00031 namespace salt
00032 {
00033 class SharedLibrary;
00034 }
00035
00036 namespace zeitgeist
00037 {
00038
00039 class Class;
00040 class Leaf;
00041 class Node;
00042 class FileServer;
00043 class LogServer;
00044 class ScriptServer;
00045 class CoreContext;
00046 class Object;
00047 class RandomServer;
00048
00055 class Core
00056 {
00057 protected:
00058
00059
00060
00061
00065 struct CacheKey
00066 {
00067 public:
00069 boost::weak_ptr<Leaf> root;
00070
00072 std::string path;
00073
00074 public:
00075 CacheKey(boost::weak_ptr<Leaf> r, const std::string& p) : root(r), path(p) {};
00076 bool operator == (const CacheKey& key) const;
00077 bool operator < (const CacheKey& key) const;
00078 };
00079
00083 typedef std::map<CacheKey, boost::weak_ptr<Leaf> > TPathCache;
00084
00085
00086
00087
00088 public:
00089 Core();
00090 ~Core();
00091
00096 void Construct(const boost::weak_ptr<Core>& self);
00097
00100 void Desctruct();
00101
00103 boost::shared_ptr<CoreContext> CreateContext();
00104
00106 boost::shared_ptr<Object> New(const std::string& className);
00107
00109 bool ExistsClass(const std::string& className);
00110
00116 bool RegisterClassObject(const boost::shared_ptr<Class> &classObject, const std::string &subDir);
00117
00123 bool RegisterClassObject(Class *classObject, const std::string &subDir);
00124
00129 bool ImportBundle(const std::string& bundleName);
00130
00132 const boost::shared_ptr<FileServer>& GetFileServer() const;
00133
00135 const boost::shared_ptr<LogServer>& GetLogServer() const;
00136
00138 const boost::shared_ptr<ScriptServer>& GetScriptServer() const;
00139
00141 boost::shared_ptr<Leaf> GetRoot() const { return mRoot; }
00142
00144 boost::shared_ptr<Leaf> Get(const std::string &pathStr);
00145
00149 boost::shared_ptr<Leaf> Get(const std::string &pathStr,
00150 const boost::shared_ptr<Leaf>& base);
00151
00155 bool Test(const std::string &pathStr,
00156 const boost::shared_ptr<Leaf>& base);
00157
00161 bool Test(const std::string &pathStr);
00162
00166 boost::shared_ptr<Leaf> GetChild(const boost::shared_ptr<Leaf> &parent,
00167 const std::string &childName);
00168
00170 void BindClass(const boost::shared_ptr<Class> &newClass) const;
00171
00174 void GarbageCollectBundles();
00175
00176 protected:
00180 boost::shared_ptr<Leaf> GetInternal(const std::string &pathStr,
00181 const boost::shared_ptr<Leaf>& base);
00182
00183
00184
00185
00186 private:
00187
00189 boost::shared_ptr<Leaf> mRoot;
00190
00192 boost::shared_ptr<Class> mNodeClass;
00193
00195 boost::shared_ptr<Class> mClassClass;
00196
00198 boost::shared_ptr<FileServer> mFileServer;
00199
00201 boost::shared_ptr<LogServer> mLogServer;
00202
00204 boost::shared_ptr<ScriptServer> mScriptServer;
00205
00207 boost::shared_ptr<RandomServer> mRandomServer;
00208
00210 boost::weak_ptr<Core> mSelf;
00211
00238 std::list<boost::shared_ptr<salt::SharedLibrary> > mBundles;
00239
00241 TPathCache mPathCache;
00242 };
00243
00244 }
00245
00246 #endif //ZEITGEIST_CORE_H