---------- Forwarded message ----------
From: David Callu <[EMAIL PROTECTED]>
Date: 27 juil. 2007 16:11
Subject: Re: [osg-users] Re: about osgIntrospection...
To: osg users <[EMAIL PROTECTED]>
Hi Manu,
Patch merged and submitted to SVN.
see the test file joint with this mail to an example of convertion
from void* to T*
Cheers
David Callu
// gcc -W -Wall main.cpp -rdynamic -losg -losgDB -losgIntrospection
#include <sstream>
#include <iostream>
#include <osgIntrospection/Reflection>
#include <osgIntrospection/Value>
#include <osgIntrospection/ReaderWriter>
#include <osgIntrospection/Type>
#include <osgIntrospection/Converter>
#include <osgIntrospection/PropertyInfo>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/Utility>
#include <osgIntrospection/variant_cast>
#include <osgDB/DynamicLibrary>
#include <osg/Geode>
// 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
return "osgwrapper_"+ext+".dll";
#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
}
osgDB::DynamicLibrary *loadWrapper(const std::string &name)
{
std::cout << "loading ... " << name << std::endl;
return osgDB::DynamicLibrary::loadLibrary(createLibraryNameForWrapper(name));
}
template <typename T>
void process(std::string & ptrTypeName)
{
std::cout << "\n\n/ ******************************************************** /" << std::endl;
std::cout << "test convertion from void* to " << ptrTypeName << std::endl;
const osgIntrospection::Converter * c;
T * t = new T;
t->setThreadSafeRefUnref(false);
std::cout << "type ptr = " << t << std::endl;
void * voidPtr = t;
std::cout << "void ptr = " << voidPtr << std::endl;
try
{
// ** make a Value with a void *
osgIntrospection::Value voidValue(voidPtr);
// ** get the real pointer Type of the void *
const osgIntrospection::Type & ptype = osgIntrospection::Reflection::getType(ptrTypeName);
// search a converter from void * to T *
c = osgIntrospection::Reflection::getConverter(voidValue.getType(), ptype);
if (c)
{
// ** do convertion
osgIntrospection::Value v = c->convert(voidValue);
// ** get the pointer in the value
T * tConverted = &osgIntrospection::getInstance<T>(v);
std::cout << "TypeConverted = " << tConverted << std::endl;
// ** use it with osgIntrospection
osgIntrospection::ValueList vlgrp;
osgIntrospection::ValueList vlcall;
vlcall.push_back(osgIntrospection::Value(true));
const osgIntrospection::MethodInfo *m = v.getInstanceType().getCompatibleMethod("setThreadSafeRefUnref", vlcall, true);
if (m)
{
osgIntrospection::ValueList::const_iterator it;
std::string str;
// ** print to screen some info
str = "Calling to: " + v.getInstanceType().getQualifiedName() + "::setThreadSafeRefUnref (";
for (it=vlcall.begin(); it != vlcall.end(); ++it){
str += it->getType().getQualifiedName() + ", ";
}
str += "\b\b)";
std::cout << str << std::endl;
// ** call method
try
{
m->invoke(v, vlcall);
}
catch(osgIntrospection::Exception & ex)
{
std::cout << ex.what() << std::endl;
}
}
// ** use it directly
std::cout << " getThreadSafeRefUnref = " << tConverted->getThreadSafeRefUnref() << std::endl;
}
else
std::cout << "converter not found from void* to " << ptype.getQualifiedName() << std::endl;
}
catch(osgIntrospection::Exception & ex)
{
std::cout << "Exception Catched : " << ex.what() << std::endl;
}
}
int main()
{
// ** load the wrapper
osg::ref_ptr<osgDB::DynamicLibrary> osg_lib = loadWrapper("osg");
std::string referencedPtrTypeName("osg::Referenced *");
process<osg::Referenced>(referencedPtrTypeName);
std::string geodePtrTypeName("osg::Geode *");
process<osg::Geode>(geodePtrTypeName);
std::string drawableUpdateCallbackPtrTypeName("osg::Drawable::UpdateCallback *");
process<osg::Drawable::UpdateCallback>(drawableUpdateCallbackPtrTypeName);
return (0);
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org