On 10/17/06, david callu <[EMAIL PROTECTED]> wrote:
For now, the only thing a can say to you is "check the Type compatibility
before use variant_cast"

Hi David!
   Ok, I'm trying to check the type compatibility, but I haven't got
a successful result. Can you point me how to do it? I attach a new
test, the problem is osg::Group doesn't return "is a referenced
object, try now a variant_cast" :(

I promise to learn about osgIntrospection and help in the near future,
do you have a list of  tasks to do? where to start?

Thanks for the help.

Jose L. Hidalgo

--
 Jose L. Hidalgo ValiƱo (PpluX)
 ---- http://www.pplux.com ----
#include <osgIntrospection/Value>
#include <osgIntrospection/variant_cast>
#include <osgIntrospection/Exceptions>
#include <osg/Vec3>
#include <osg/Referenced>
#include <osg/Group>
#include <osgProducer/Viewer>
#include <osgDB/DynamicLibrary>
#include <osg/io_utils>

// 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)
{
	std::cout << "loading ... " << name << std::endl;
	return osgDB::DynamicLibrary::loadLibrary(
		createLibraryNameForWrapper(name)
	);
}

void check(const std::string &test_name, const osgIntrospection::Value &value)
{
	const osgIntrospection::Type &t_referenced =
            osgIntrospection::Reflection::getType(typeid(osg::Referenced*));

	const osgIntrospection::Type &type = value.getType();

	std::cout << "---------------------------" << std::endl;
	std::cout << "Test " << test_name << " - > " << 
		value.getType().getStdTypeInfo().name() << std::endl;
	if (type.isDefined()) 
	{
		std::cout << " - Defined " << std::endl;
		if (type.isNonConstPointer()) 
		{
			std::cout << " - is non-const pointer " << std::endl;
			if (type.isSubclassOf(t_referenced))
			{
				std::cout << " - is subclass of referenced " << std::endl;

				osg::Referenced *ref = 
					osgIntrospection::variant_cast<osg::Referenced*>(value); 
				std::cout << "Result --> " << ref << std::endl;
			} std::cout << " - NOT referenced " << std::endl;
		} else std::cout << " - NOT non-const pointer " << std::endl;
	} else std::cout << " - NOT Defined " << std::endl;

	/* This is how it will look in the real world :)
	if (type.isDefined() && type.isNonConstPointer() && type.isSubclassOf(t_referenced) ) 
	{
	}
	*/
}

class Dummy {};

int main() 
{

    osg::ref_ptr<osgDB::DynamicLibrary> osg_lib = load("osg");
    osg::ref_ptr<osgDB::DynamicLibrary> osgProducer_lib = load("osgProducer");

	std::cout << "osg = " << osg_lib.valid() << std::endl;
	std::cout << "osgProducer = " << osgProducer_lib.valid() << std::endl;

	osg::Vec3 v3;
	osgProducer::Viewer viewer;
	osg::ref_ptr<osg::Group> group = new osg::Group();
	Dummy dummy;

	check("Normal Vec3", osgIntrospection::Value(v3));
	check("Pointer Vec3", osgIntrospection::Value(&v3));
	check("Group", osgIntrospection::Value(group.get()));
	check("Viewer",osgIntrospection::Value(viewer));
	check("Pointer to Viewer", osgIntrospection::Value(&viewer));
	check("Dummy!", osgIntrospection::Value(dummy));
	check("Dummy pointer!", osgIntrospection::Value(&dummy));

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

Reply via email to