/* -*-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 "Type.h" #include "Method.h" #include #include #include using namespace boost::python; namespace osgPython { boost::python::object Type::getAttr(const std::string& name) { std::string ns = _type.getQualifiedName(); if (ns != "") ns += "::"; ns += name; if (_type.isEnum()){ const osgIntrospection::EnumLabelMap &emap = _type.getEnumLabels(); osgIntrospection::EnumLabelMap::const_iterator eit; for (eit = emap.begin(); eit != emap.end(); ++eit){ if (name == eit->second){ osgIntrospection::Value v = osgIntrospection::Value(eit->first); return Base::toPython(new Value(v)); } } throw std::runtime_error("TODO: Enum not found"); } try{ const osgIntrospection::Type &t = osgIntrospection::Reflection::getType(ns); return Base::toPython(new Type(t)); } catch(osgIntrospection::Exception&) { return Base::toPython(new Method(this, name)); } return Base::getAttr(name); } Base* Type::call(osgIntrospection::ValueList& vl) { try{ osgIntrospection::Value value = _type.createInstance(vl); return new Value(value); } catch(osgIntrospection::Exception& e) { throw std::runtime_error(e.what()); } } std::string Type::__str__() const { return _type.getQualifiedName(); } std::string Type::__repr__() const { return "Type("+_type.getQualifiedName()+")"; } } //end of osgPython namespace