osg/ScriptEngine
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library 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
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SCRIPTENGINE
#define OSG_SCRIPTENGINE 1
#include <osg/Object>
#include <osg/Callback>
#include <osg/NodeVisitor>
#include <osg/UserDataContainer>
namespace osg
{
// forward declare
class ScriptEngine;
/* Script class for wrapping a script and the language used in the script.*/
class Script : public osg::Object
{
public:
Script():_modifiedCount(0) {}
Script(const std::string& language, const std::string& str): _language(language), _script(str), _modifiedCount(0) {}
Script(const Script& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): osg::Object(rhs,copyop), _language(rhs._language), _script(rhs._script), _modifiedCount(0) {}
META_Object(osg, Script)
void setLanguage(const std::string& language) { _language = language; dirty(); }
const std::string& getLanguage() const{ return _language; }
void setScript(const std::string& str) { _script = str; dirty(); }
const std::string& getScript() const { return _script; }
void dirty() { ++_modifiedCount; }
unsigned int getModifiedCount() const { return _modifiedCount; }
protected:
virtual ~Script() {}
std::string _language;
std::string _script;
unsigned int _modifiedCount;
};
class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback
{
public:
ScriptNodeCallback(Script* script=0, const std::string& entryPoint="") : _script(script), _entryPoint(entryPoint) {}
ScriptNodeCallback(const ScriptNodeCallback& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(rhs,copyop),
osg::Callback(rhs,copyop),
osg::NodeCallback(rhs,copyop), _script(rhs._script) {}
META_Object(osg, ScriptNodeCallback)
void setScript(osg::Script* script) { _script = script; }
osg::Script* getScript() { return _script.get(); }
const osg::Script* getScript() const { return _script.get(); }
void setEntryPoint(const std::string& script) { _entryPoint = script; }
const std::string& getEntryPoint() const { return _entryPoint; }
osg::ScriptEngine* getScriptEngine(osg::NodePath& nodePath);
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
protected:
virtual ~ScriptNodeCallback() {}
osg::ref_ptr<Script> _script;
std::string _entryPoint;
};
class ScriptEngine : public osg::Object
{
public:
inline const std::string& getLanguage() const { return _language; }
bool run(osg::Script* script)
{
// assumpt empty input and output parameters lists
Parameters inputParameters, outputParameters;
return run(script, "", inputParameters, outputParameters);
}
virtual bool run(osg::Script* script, const std::string& entryPoint, Parameters& inputParameters, Parameters& outputParameters) = 0;
protected:
ScriptEngine(const std::string& language):_language(language) { setName(language); }
virtual ~ScriptEngine() {}
std::string _language;
};
}
#endif
Callback
NodeVisitor
Object
UserDataContainer
osg::Callback
Definition Callback:34
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::NodeCallback
Definition Callback:215
osg::NodeCallback::NodeCallback
NodeCallback()
Definition Callback:219
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::Object::setName
virtual void setName(const std::string &name)
Definition Object:203
osg::Object::Object
Object()
Definition Object:69
osg::ScriptEngine
Definition osg/ScriptEngine:101
osg::ScriptEngine::ScriptEngine
ScriptEngine(const std::string &language)
Definition osg/ScriptEngine:120
osg::ScriptEngine::_language
std::string _language
Definition osg/ScriptEngine:123
osg::ScriptEngine::run
bool run(osg::Script *script)
Definition osg/ScriptEngine:108
osg::ScriptEngine::run
virtual bool run(osg::Script *script, const std::string &entryPoint, Parameters &inputParameters, Parameters &outputParameters)=0
osg::ScriptEngine::~ScriptEngine
virtual ~ScriptEngine()
Definition osg/ScriptEngine:121
osg::ScriptEngine::getLanguage
const std::string & getLanguage() const
Definition osg/ScriptEngine:105
osg::ScriptNodeCallback::getEntryPoint
const std::string & getEntryPoint() const
Definition osg/ScriptEngine:82
osg::ScriptNodeCallback::_entryPoint
std::string _entryPoint
Definition osg/ScriptEngine:95
osg::ScriptNodeCallback::getScript
const osg::Script * getScript() const
Definition osg/ScriptEngine:76
osg::ScriptNodeCallback::ScriptNodeCallback
ScriptNodeCallback(const ScriptNodeCallback &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition osg/ScriptEngine:62
osg::ScriptNodeCallback::META_Object
META_Object(osg, ScriptNodeCallback) void setScript(osg
Definition osg/ScriptEngine:67
osg::ScriptNodeCallback::getScriptEngine
osg::ScriptEngine * getScriptEngine(osg::NodePath &nodePath)
osg::ScriptNodeCallback::setEntryPoint
void setEntryPoint(const std::string &script)
Definition osg/ScriptEngine:79
osg::ScriptNodeCallback::_script
osg::ref_ptr< Script > _script
Definition osg/ScriptEngine:94
osg::ScriptNodeCallback::operator()
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
osg::ScriptNodeCallback::ScriptNodeCallback
ScriptNodeCallback(Script *script=0, const std::string &entryPoint="")
Definition osg/ScriptEngine:61
osg::ScriptNodeCallback::getScript
osg::Script * getScript()
Definition osg/ScriptEngine:73
osg::ScriptNodeCallback::~ScriptNodeCallback
virtual ~ScriptNodeCallback()
Definition osg/ScriptEngine:92
osg::Script
Definition osg/ScriptEngine:30
osg::Script::dirty
void dirty()
Definition osg/ScriptEngine:44
osg::Script::_script
std::string _script
Definition osg/ScriptEngine:52
osg::Script::getScript
const std::string & getScript() const
Definition osg/ScriptEngine:42
osg::Script::Script
Script(const Script &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition osg/ScriptEngine:34
osg::Script::getModifiedCount
unsigned int getModifiedCount() const
Definition osg/ScriptEngine:45
osg::Script::META_Object
META_Object(osg, Script) void setLanguage(const std
Definition osg/ScriptEngine:36
osg::Script::getLanguage
const std::string & getLanguage() const
Definition osg/ScriptEngine:39
osg::Script::_language
std::string _language
Definition osg/ScriptEngine:51
osg::Script::Script
Script()
Definition osg/ScriptEngine:32
osg::Script::setScript
void setScript(const std::string &str)
Definition osg/ScriptEngine:41
osg::Script::Script
Script(const std::string &language, const std::string &str)
Definition osg/ScriptEngine:33
osg::Script::_modifiedCount
unsigned int _modifiedCount
Definition osg/ScriptEngine:53
osg::Script::~Script
virtual ~Script()
Definition osg/ScriptEngine:49
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::Parameters
std::vector< osg::ref_ptr< osg::Object > > Parameters
Definition Callback:130
osg::NodePath
std::vector< Node * > NodePath
Definition Node:47
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39