Here I attached a test program with my very 3 problems with osgIntrospection.

(test1) osgIntrospection::Value( osg::Vec3(1,2,3) ) is not "valid",
because the osgIntrospection::Type returned is different from the type
returned by osgIntrospection::Reflection::getType("osg::Vec3"). So,
how do I pass a vec3 to a Value ?

(test2) I get a very strange exception without doing anything? when I
try to get the method setText from osgText::Text type.

(test3) The previous mail, how to access a static method (I wondering
if the static method is been reflected) of a class?


Thank you in advance !

Jose L.

--
 Jose L. Hidalgo ValiƱo (PpluX)
 ---- http://www.pplux.com ----
#include <iostream>

#include <osgDB/DynamicLibrary>

#include <osgIntrospection/Value>
#include <osgIntrospection/Reflection>
#include <osgIntrospection/variant_cast>
#include <osgIntrospection/MethodInfo>

using namespace osgIntrospection;

// 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
}

osgDB::DynamicLibrary *load(const std::string &name)
{
	return osgDB::DynamicLibrary::loadLibrary(
		createLibraryNameForWrapper(name)
	);
}


template<class T>
void test1(const std::string &name)
{
	std::cout << "Problem with some types...(" <<name<<")"<< std::endl;

	//create a vec3
	const Type &t1 = Reflection::getType(name);
	std::cout << "\t (t1) Vec3 created with osgIntrospection is " << t1.isDefined()
	   << std::endl;	

	const Type &t2 = Reflection::getType( typeid(T) );
	std::cout << "\t (t2) Vec3 created with typeid is " << t2.isDefined()
	   << std::endl;

	const Type &t3 = Value( T() ).getType();
	std::cout << "\t (t3) Vec3 created with from value is " << t3.isDefined()
	   << std::endl;

	std::cout << "Compare the typeinfos..." << std::endl
		<< "t1 == typeid("<<name<<") -> " << 
			(t1.getStdTypeInfo() == typeid(T)) << " -> " <<
			t1.getStdTypeInfo().name() << " == " << typeid(T).name()
			<< std ::endl

		<< "t2 == typeid("<<name<<") -> " << 
			(t2.getStdTypeInfo() == typeid(T)) << " -> " <<
			t2.getStdTypeInfo().name() << " == " << typeid(T).name()
			<< std ::endl

		<< "t3 == typeid("<<name<<") -> " << 
			(t3.getStdTypeInfo() == typeid(T)) << " -> " <<
			t3.getStdTypeInfo().name() << " == " << typeid(T).name()
			<< std ::endl
			<< std ::endl
		;
}

void test2()
{
	std::cout << "In my machine that code gives the following exception... "
		<< "Exception = type `PKw' is declared but not defined " << std::endl;
	try
	{
		const Type &t = Reflection::getType("osgText::Text");
		ValueList vl;
		vl.push_back("hello");

		// just try to get a method 
		t.getCompatibleMethod("setText",vl,false);
	}
	catch(Exception &e)
	{
		std::cout << "Exception = " << e.what() << std::endl;
	}
	std::cout << std::endl;
}

void test3()
{
	std::cout << "Trying to call osgDB::Registry::invoke resutl = ";
    try
    {
		const osgIntrospection::Type& t = 
			osgIntrospection::Reflection::getType("osgDB::Registry");

		osgIntrospection::ParameterInfoList params;
		const osgIntrospection::MethodInfo* method = 
			t.getMethod("instance", params, false);
		
		if(method) 
		{
			osgIntrospection::Value osgDB_Registry_instance = method->invoke();
			std::cout << " OK!!!" << std::endl;
		}
		else
		{
			std::cout << "Method not found!!!!" << std::endl;
		}
    }
    catch(const osgIntrospection::Exception &e)
    {
        std::cout << e.what() << std::endl;
    }
	std::cout << std::endl;
}

int main(int argc, char **argv)
{
    osg::ref_ptr<osgDB::DynamicLibrary> osg_lib = load("osg");
    osg::ref_ptr<osgDB::DynamicLibrary> osgDB_lib = load("osgDB");
    osg::ref_ptr<osgDB::DynamicLibrary> osgText_lib = load("osgText");
    osg::ref_ptr<osgDB::DynamicLibrary> osgProducer_lib = load("osgProducer");


	// there is no way to pass a osg::Vec3 directly to a 
	//	osgIntrospection::Value ? like floats ?
	test1<osg::Vec3>("osg::Vec3");
	test1<float>("float");
	
	// that gives an exception... without doing anything...
	test2();

	// and how to do that?
	test3();

	return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to