/* -*-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 #include #include #include #include #include #include #include "rtti.h" #include "Type.h" #include "Utility.h" using namespace boost::python; namespace osgPython { const osgIntrospection::Type& getTypeInfoStr(const std::string& type) { return osgIntrospection::Reflection::getType(type); } const osgIntrospection::Type& getTypeInfoType(const Type* type) { return type->getType(); } const osgIntrospection::Type& getTypeInfoValue(const Value* value) { return value->getValue().getInstanceType(); } osgIntrospection::PropertyInfoList getAllProperties(const osgIntrospection::Type& self) { try{ osgIntrospection::PropertyInfoList plist; self.getAllProperties(plist); return plist; } catch(osgIntrospection::Exception& e) { throw std::runtime_error(e.what()); } } osgIntrospection::MethodInfoList getAllMethods(const osgIntrospection::Type& self) { try{ osgIntrospection::MethodInfoList plist; self.getAllMethods(plist); return plist; } catch(osgIntrospection::Exception& e) { throw std::runtime_error(e.what()); } } std::vector getEnumLabels(const osgIntrospection::Type& self) { std::vector labels; const osgIntrospection::EnumLabelMap &labelmap = self.getEnumLabels(); osgIntrospection::EnumLabelMap::const_iterator it; for(it=labelmap.begin(); it != labelmap.end(); ++it){ labels.push_back(it->second); } return labels; } class MethodInfo { public: MethodInfo(const osgIntrospection::MethodInfo *mi) : _mi(mi) {} ~MethodInfo() {} const osgIntrospection::Type& getDeclaringType() const { return _mi->getDeclaringType(); } const std::string& getName() const {return _mi->getName();} const osgIntrospection::Type& getReturnType() const {return _mi->getReturnType();} const osgIntrospection::ParameterInfoList& getParameters() const {return _mi->getParameters(); } const std::string& getBriefHelp() const {return _mi->getBriefHelp();} const std::string& getDetailedHelp() const {return _mi->getDetailedHelp();} bool isConst() const {return _mi->isConst();} bool isStatic() const {return _mi->isStatic();} protected: const osgIntrospection::MethodInfo *_mi; }; class ConstructorInfo { public: ConstructorInfo(const osgIntrospection::ConstructorInfo *ci) : _ci(ci) {} ~ConstructorInfo() {} const osgIntrospection::Type& getDeclaringType() const { return _ci->getDeclaringType(); } const osgIntrospection::ParameterInfoList& getParameters() const {return _ci->getParameters(); } protected: const osgIntrospection::ConstructorInfo *_ci; }; void initRTTI() { std_vector_to_python_converter(); std_vector_to_python_converter(); std_vector_abstract_to_python_converter(); std_vector_abstract_to_python_converter(); class_("TypeInfo", no_init) .def("getTypeInfo", getTypeInfoStr, return_internal_reference<>()) .def("getTypeInfo", getTypeInfoType, return_internal_reference<>()) .def("getTypeInfo", getTypeInfoValue, return_internal_reference<>()) .staticmethod("getTypeInfo") .add_property("isDefined", &osgIntrospection::Type::isDefined) .def("getName", &osgIntrospection::Type::getName, return_value_policy()) .def("getNamespace", &osgIntrospection::Type::getNamespace, return_value_policy()) .def("getQualifiedName", &osgIntrospection::Type::getQualifiedName) .def("matchesName", &osgIntrospection::Type::matchesName) .add_property("numBaseTypes", &osgIntrospection::Type::getNumBaseTypes) .def("getBaseType", &osgIntrospection::Type::getBaseType, return_internal_reference<>()) .add_property("numAliases", &osgIntrospection::Type::getNumAliases) .def("getAlias", &osgIntrospection::Type::getAlias, return_value_policy()) .add_property("isAbstract", &osgIntrospection::Type::isAbstract) .add_property("isAtomic", &osgIntrospection::Type::isAtomic) .add_property("isEnum", &osgIntrospection::Type::isEnum) .add_property("isVoid", &osgIntrospection::Type::isVoid) .add_property("isPointer", &osgIntrospection::Type::isPointer) .add_property("isConstPointer", &osgIntrospection::Type::isConstPointer) .add_property("isNonConstPointer", &osgIntrospection::Type::isNonConstPointer) .def("getPointedType", &osgIntrospection::Type::getPointedType, return_internal_reference<>()) .def("getProperties", &osgIntrospection::Type::getProperties, return_value_policy()) .def("getAllProperties", getAllProperties) .def("getConstructors", &osgIntrospection::Type::getConstructors, return_value_policy()) .def("getMethods", &osgIntrospection::Type::getMethods, return_value_policy()) .def("getAllMethods", getAllMethods) .def("getEnumLabels", getEnumLabels) .def("isSubclassOf", &osgIntrospection::Type::isSubclassOf) ; class_("PropertyInfo", no_init) .def("getNunIndices", &osgIntrospection::PropertyInfo::getNumIndices) .def("getName", &osgIntrospection::PropertyInfo::getName, return_value_policy()) .def("getDeclaringType", &osgIntrospection::PropertyInfo::getDeclaringType, return_internal_reference<>()) .def("getPropertyType", &osgIntrospection::PropertyInfo::getPropertyType, return_internal_reference<>()) .def("canGet", &osgIntrospection::PropertyInfo::canGet) .def("canSet", &osgIntrospection::PropertyInfo::canSet) .def("canCount", &osgIntrospection::PropertyInfo::canCount) .def("canAdd", &osgIntrospection::PropertyInfo::canAdd) .def("canRemove", &osgIntrospection::PropertyInfo::canRemove) .def("isSimple", &osgIntrospection::PropertyInfo::isSimple) .def("isIndexed", &osgIntrospection::PropertyInfo::isIndexed) .def("isArray", &osgIntrospection::PropertyInfo::isArray) .def("getIndexParameters", &osgIntrospection::PropertyInfo::getIndexParameters, return_value_policy()) .def("getDefaultValue", &osgIntrospection::PropertyInfo::getDefaultValue) ; class_("ParameterInfo", no_init) .def("getName", &osgIntrospection::ParameterInfo::getName, return_value_policy()) .def("getParameterType", &osgIntrospection::ParameterInfo::getParameterType, return_internal_reference<>()) .def("getAttributes", &osgIntrospection::ParameterInfo::getAttributes) .def("getDefaultValue", &osgIntrospection::ParameterInfo::getDefaultValue, return_value_policy()) .def("isIn", &osgIntrospection::ParameterInfo::isIn) .def("isOut", &osgIntrospection::ParameterInfo::isOut) .def("isInOut", &osgIntrospection::ParameterInfo::isInOut) ; class_("ConstructorInfo", no_init) .def("getDeclaringType", &ConstructorInfo::getDeclaringType, return_internal_reference<>()) .def("getParameters", &ConstructorInfo::getParameters, return_value_policy()) ; class_("MethodInfo", no_init) .def("getDeclaringType", &MethodInfo::getDeclaringType, return_internal_reference<>()) .def("getName", &MethodInfo::getName, return_value_policy()) .def("getReturnType", &MethodInfo::getReturnType, return_internal_reference<>()) .def("getParameters", &MethodInfo::getParameters, return_value_policy()) .def("getBriefHelp", &MethodInfo::getBriefHelp, return_value_policy()) .def("getDetailedHelp", &MethodInfo::getDetailedHelp, return_value_policy()) .def("isConst", &MethodInfo::isConst) .def("isStatic", &MethodInfo::isStatic) ; } } //end of osgPython namespace