/* -*-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 "Namespace.h" #include "Type.h" #include namespace osgPython { boost::python::object readObjectFile(const std::string& filename); // borrowed from osgDB... std::string createLibraryNameForWrapper(const std::string& ext) { #if defined(WIN32) // !! recheck evolving Cygwin DLL extension naming protocols !! NHV #ifdef __CYGWIN__ return "cygosgwrapper_"+ext+".dll"; #elif defined(__MINGW32__) return "libosgwrapper_"+ext+".dll"; #else #ifdef _DEBUG return "osgwrapper_"+ext+"d.dll"; #else return "osgwrapper_"+ext+".dll"; #endif #endif #elif macintosh return "osgwrapper_"+ext; #elif defined(__hpux__) // why don't we use PLUGIN_EXT from the makefiles here? return "osgwrapper_"+ext+".sl"; #else return "osgwrapper_"+ext+".so"; #endif } boost::python::object Namespace::loadWrapper(const std::string& name) { osgDB::DynamicLibrary *lib = osgDB::DynamicLibrary::loadLibrary(createLibraryNameForWrapper(name)); if (lib) return boost::python::object(new Namespace(name, lib)); return boost::python::object(); } boost::python::object Namespace::getAttr(const std::string& nameattribute) { std::string ns = _namespace; if (ns != "") ns += "::"; ns += nameattribute; if (ns == "osgDB::readObjectFile") return boost::python::object(readObjectFile); try{ const osgIntrospection::Type &t = osgIntrospection::Reflection::getType(ns); return Base::toPython(new Type(t)); } catch(osgIntrospection::Exception&) { } return Base::toPython(new Namespace(ns,_lib.get())); } std::vector Namespace::getAllTypes(const std::string& filter) { std::vector v; osgIntrospection::TypeMap::const_iterator it; const osgIntrospection::TypeMap &tmap = osgIntrospection::Reflection::getTypes(); for (it=tmap.begin(); it != tmap.end(); ++it){ osgIntrospection::Type *type = it->second; if (type->isDefined() && !type->isPointer() ){ const std::string& name = type->getQualifiedName(); v.push_back(name); } } return v; } } //end of osgPython namespace