Removed the prototype MethodObject classes

This commit is contained in:
Robert Osfield
2014-01-06 15:46:36 +00:00
parent 6490f1b6a5
commit fa7f25d75d
4 changed files with 0 additions and 333 deletions

View File

@@ -1,82 +0,0 @@
/* -*-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.
*/
#include <osg/Geode>
#include <osg/ValueObject>
#include "MethodObject.h"
struct GeodeGetNumDrawables : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
osg::Geode* geode = reinterpret_cast<osg::Geode*>(objectPtr);
outputParameters.push_back(new osg::UIntValueObject("return", geode->getNumDrawables()));
return true;
}
};
struct GeodeGetDrawable : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Object* indexObject = inputParameters[0].get();
osg::UIntValueObject* uivo = dynamic_cast<osg::UIntValueObject*>(indexObject);
if (!uivo) return false;
osg::Geode* geode = reinterpret_cast<osg::Geode*>(objectPtr);
outputParameters.push_back(geode->getDrawable(uivo->getValue()));
return true;
}
};
struct GeodeAddDrawable : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Drawable* child = dynamic_cast<osg::Drawable*>(inputParameters[0].get());
if (!child) return false;
osg::Geode* geode = reinterpret_cast<osg::Geode*>(objectPtr);
geode->addDrawable(child);
return true;
}
};
struct GeodeRemoveDrawable : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Drawable* child = dynamic_cast<osg::Drawable*>(inputParameters[0].get());
if (!child) return false;
osg::Geode* geode = reinterpret_cast<osg::Geode*>(objectPtr);
geode->removeDrawable(child);
return true;
}
};
static osgDB::RegisterMethodObjectProxy s_getNumDrawables("osg::Geode","getNumDrawables",new GeodeGetNumDrawables());
static osgDB::RegisterMethodObjectProxy s_getNumDrawable("osg::Geode","getDrawable",new GeodeGetDrawable());
static osgDB::RegisterMethodObjectProxy s_getAddDrawable("osg::Geode","addDrawable",new GeodeAddDrawable());
static osgDB::RegisterMethodObjectProxy s_getRemoveDrawable("osg::Geode","removeDrawable",new GeodeRemoveDrawable());

View File

@@ -1,91 +0,0 @@
/* -*-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.
*/
#include <osg/Group>
#include <osg/ValueObject>
#include "MethodObject.h"
using namespace osgDB;
struct GroupGetNumChildren : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
osg::Group* group = reinterpret_cast<osg::Group*>(objectPtr);
outputParameters.push_back(new osg::UIntValueObject("return", group->getNumChildren()));
return true;
}
};
struct GroupGetChild : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Object* indexObject = inputParameters[0].get();
OSG_NOTICE<<"GroupGetChild "<<indexObject->className()<<std::endl;
unsigned int index = 0;
osg::DoubleValueObject* dvo = dynamic_cast<osg::DoubleValueObject*>(indexObject);
if (dvo) index = static_cast<unsigned int>(dvo->getValue());
else
{
osg::UIntValueObject* uivo = dynamic_cast<osg::UIntValueObject*>(indexObject);
if (uivo) index = uivo->getValue();
}
osg::Group* group = reinterpret_cast<osg::Group*>(objectPtr);
outputParameters.push_back(group->getChild(index));
return true;
}
};
struct GroupAddChild : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Node* child = dynamic_cast<osg::Node*>(inputParameters[0].get());
if (!child) return false;
osg::Group* group = reinterpret_cast<osg::Group*>(objectPtr);
group->addChild(child);
return true;
}
};
struct GroupRemoveChild : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
if (inputParameters.empty()) return false;
osg::Node* child = dynamic_cast<osg::Node*>(inputParameters[0].get());
if (!child) return false;
osg::Group* group = reinterpret_cast<osg::Group*>(objectPtr);
group->removeChild(child);
return true;
}
};
static osgDB::RegisterMethodObjectProxy s_getNumChildren("osg::Group","getNumChildren",new GroupGetNumChildren());
static osgDB::RegisterMethodObjectProxy s_getNumChild("osg::Group","getChild",new GroupGetChild());
static osgDB::RegisterMethodObjectProxy s_getAddChild("osg::Group","addChild",new GroupAddChild());
static osgDB::RegisterMethodObjectProxy s_getRemoveChild("osg::Group","removeChild",new GroupRemoveChild());

View File

@@ -1,85 +0,0 @@
/* -*-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.
*/
#include "MethodObject.h"
#include <osg/Notify>
using namespace osgDB;
void MethodsObject::add(const std::string& methodName, MethodObject* mo)
{
methodMap.insert(MethodMap::value_type(methodName, mo));
}
bool MethodsObject::run(void* objectPtr, const std::string& methodName, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
MethodMap::const_iterator itr = methodMap.find(methodName);
while (itr != methodMap.end())
{
if (itr->first==methodName)
{
OSG_NOTICE<<"Calling methodObject for "<<methodName<<std::endl;
if (itr->second->run(objectPtr, inputParameters, outputParameters)) return true;
}
++itr;
}
OSG_NOTICE<<"No matching methodObject found for "<<methodName<<std::endl;
return false;
}
bool MethodsObject::hasMethod(const std::string& methodName) const
{
return (methodMap.find(methodName)!=methodMap.end());
}
osg::ref_ptr<MethodsObjectManager>& MethodsObjectManager::instance()
{
static osg::ref_ptr<MethodsObjectManager> s_MethodsObjectManager = new MethodsObjectManager;
return s_MethodsObjectManager;
}
void MethodsObjectManager::add(const std::string& compoundClassName, const std::string& methodName, MethodObject* mo)
{
MethodsObjectMap::iterator itr = methodsObjects.find( compoundClassName );
if (itr==methodsObjects.end())
{
methodsObjects[compoundClassName] = new MethodsObject;
itr = methodsObjects.find( compoundClassName );
}
itr->second->add(methodName, mo);
}
bool MethodsObjectManager::run(void* objectPtr, const std::string& compoundClassName, const std::string& methodName, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
MethodsObjectMap::const_iterator itr = methodsObjects.find( compoundClassName );
if (itr!=methodsObjects.end())
{
return itr->second->run(objectPtr, methodName, inputParameters, outputParameters);
}
OSG_NOTICE<<"No matching methodObject found for class "<<compoundClassName<<", method "<<methodName<<std::endl;
return false;
}
bool MethodsObjectManager::hasMethod(const std::string& compoundClassName, const std::string& methodName) const
{
MethodsObjectMap::const_iterator itr = methodsObjects.find( compoundClassName );
if (itr!=methodsObjects.end())
{
return itr->second->hasMethod(methodName);
}
return false;
}

View File

@@ -1,75 +0,0 @@
/* -*-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 METHODSOBJECT_H
#define METHODSOBJECT_H
#include <osg/ScriptEngine>
#include <osgDB/ObjectWrapper>
namespace osgDB
{
#if 0
struct MethodObject : public osg::Referenced
{
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const = 0;
virtual ~MethodObject() {}
};
#endif
struct MethodsObject : public osg::Referenced
{
MethodsObject() {}
virtual ~MethodsObject() {}
void add(const std::string& methodName, MethodObject* mo);
bool run(void* objectPtr, const std::string& methodName, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
bool hasMethod(const std::string& methodName) const;
typedef std::multimap< std::string, osg::ref_ptr<MethodObject> > MethodMap;
MethodMap methodMap;
};
struct MethodsObjectManager : public osg::Referenced
{
MethodsObjectManager() {}
virtual ~MethodsObjectManager() {}
static osg::ref_ptr<MethodsObjectManager>& instance();
void add(const std::string& compoundClassName, const std::string& methodName, MethodObject* mo);
bool run(void* objectPtr, const std::string& compoundClassName, const std::string& methodName, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
bool hasMethod(const std::string& compoundClassName, const std::string& methodName) const;
typedef std::map< std::string, osg::ref_ptr<MethodsObject> > MethodsObjectMap;
MethodsObjectMap methodsObjects;
};
struct RegisterMethodObjectProxy
{
RegisterMethodObjectProxy(const std::string& compoundClassName, const std::string& methodName, MethodObject* mo)
{
MethodsObjectManager::instance()->add(compoundClassName, methodName, mo);
}
};
}
#endif