00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef RUBYSCENEIMPORTER_H
00023 #define RUBYSCENEIMPORTER_H
00024
00025 #include <oxygen/sceneserver/sceneimporter.h>
00026 #include <oxygen/sceneserver/basenode.h>
00027 #include <sfsexp/sexp.h>
00028
00029 class RubySceneImporter : public oxygen::SceneImporter
00030 {
00031 protected:
00033 typedef std::map<std::string, int> TParameterMap;
00034
00036 struct MethodInvocation
00037 {
00038 boost::weak_ptr<zeitgeist::Node> node;
00039 std::string method;
00040 zeitgeist::ParameterList parameter;
00041 };
00042
00043 typedef std::list<MethodInvocation> TMethodInvocationList;
00044
00046 struct ParamEnv
00047 {
00048 TParameterMap parameterMap;
00049 boost::shared_ptr<zeitgeist::ParameterList> parameter;
00050 TMethodInvocationList invocationList;
00051
00052 ParamEnv();
00053 ParamEnv(boost::shared_ptr<zeitgeist::ParameterList> p)
00054 : parameter(p) {};
00055 };
00056
00057 typedef std::list<ParamEnv> TParameterStack;
00058
00059 public:
00060 RubySceneImporter();
00061 virtual ~RubySceneImporter();
00062
00063 virtual bool ImportScene(const std::string& fileName,
00064 boost::shared_ptr<oxygen::BaseNode> root,
00065 boost::shared_ptr<zeitgeist::ParameterList> parameter);
00066
00067 virtual bool ParseScene(const std::string& scene,
00068 boost::shared_ptr<oxygen::BaseNode> root,
00069 boost::shared_ptr<zeitgeist::ParameterList> parameter);
00070
00076 void SetUnlinkOnCompleteScenes(bool unlink);
00077
00078 protected:
00079 virtual bool ParseScene(const char* scene, int size,
00080 boost::shared_ptr<oxygen::BaseNode> root,
00081 boost::shared_ptr<zeitgeist::ParameterList> parameter);
00082
00083
00084 bool ReadHeader(sexp_t* sexp);
00085 bool ReadGraph(sexp_t* sexp, boost::shared_ptr<oxygen::BaseNode> root);
00086 bool ReadDeltaGraph(sexp_t* sexp, boost::shared_ptr<oxygen::BaseNode> root);
00087 boost::shared_ptr<zeitgeist::Object> CreateInstance(const std::string& className);
00088
00089 void PushInvocation(const MethodInvocation& invoc);
00090 bool Invoke(const MethodInvocation& invoc);
00091 bool InvokeMethods();
00092 bool ReadMethodCall(sexp_t* _sexp, boost::shared_ptr<oxygen::BaseNode> node);
00093
00094 bool ReplaceVariable(std::string& param);
00095 bool EvalParameter(sexp_t* sexp, std::string& value);
00096
00097 boost::shared_ptr<oxygen::BaseNode> CreateNode(sexp_t* sexp);
00098 bool ParseTemplate(sexp_t* sexp);
00099 bool ParseDefine(sexp_t* sexp);
00100
00101 void PushParameter(boost::shared_ptr<zeitgeist::ParameterList> parameter);
00102 void PopParameter();
00103 ParamEnv& GetParamEnv();
00104
00105 protected:
00108 bool mAutoUnlink;
00109
00111 bool mDeltaScene;
00112
00114 float mVersionMajor;
00115
00117 float mVersionMinor;
00118
00120 std::string mFileName;
00121
00123 TParameterStack mParameterStack;
00124 };
00125
00126 DECLARE_CLASS(RubySceneImporter);
00127
00128 #endif // RUBYSCENEIMPORTER_H