/* -*-c++-*- osgPython - Copyright (C) 2006 Miguel Escriva Gregori * * 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 #include "Method.h" #include "Value.h" #include #include #include #include #include namespace osgPython { Base* Method::call(osgIntrospection::ValueList& vl) { try{ const osgIntrospection::Type &type = (_type.valid()) ? _type->getType() : _value->getValue().getInstanceType(); const osgIntrospection::MethodInfo *m = type.getCompatibleMethod(_method, vl, true); if (m){ if (m->isStatic()){ osgIntrospection::Value v = m->invoke(vl); return new Value(v); } else{ osgIntrospection::ValueList::const_iterator it; osgIntrospection::Value v = m->invoke(_value->getValue(), vl); return new Value(v); } } else{ osgIntrospection::ValueList::const_iterator it; std::string error = "Method " + type.getQualifiedName() + "::" + _method + " ("; for (it=vl.begin(); it != vl.end(); ++it){ error += it->getType().getQualifiedName() + ", "; } error += ") not found."; throw std::runtime_error(error); } } catch(osgIntrospection::Exception& e) { throw std::runtime_error(e.what()); } return Base::call(vl); } std::string Method::__str__() const { if (_type.valid()){ const osgIntrospection::Type &type = _type->getType(); return ""; } else{ const osgIntrospection::Type &type = _value->getValue().getInstanceType(); return "__repr__() +">"; } } std::string Method::__repr__() const { return __str__(); } } //end of osgPython namespace