Hi Vincent

>>   I have tested the code snipper under Ubuntu gcc version 4.0.2 with OSG
>>   1.0.0. It just segfaulting :(
>>   Though, I wonder why it was working before (OSG 0.9.9 / gcc 3.4.2).



    I don't know why this code segfault, there are too possibility.
        Have you recompile all osg with your new gcc and libc++ version ?
        Did you use the CVS Head version ?

  
>> Is there another mean to get a method invocation from an existing object ?

    you could use the osgIntrospection::Value::getInstanceType() instead of the osgIntrospection::Type::getPointedType()
    this allow you to get the pointer type if it is a pointer, or the non-pointer type if it's not. you get automaticaly the type that you must use to avoid the osgIntrospection::TypeNotDefinedException throwing.

    To get the value of a property, you can find the property with the function
    osgIntrospection::Type::getProperty(const std::string & name, const Type& ptype, const ParameterInfoList& indices, bool inherit) const



see the file attached



to compile:

gcc main.cpp -losg -losgDB -losgIntrospection -Wl,-E

best regards
David
#include <osg/Group>
#include <osgDB/DynamicLibrary>
#include <osgIntrospection/Value>
#include <osgIntrospection/Type>
#include <osgIntrospection/PropertyInfo>
#include <osgIntrospection/Reflection>
#include <iostream>


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

}

void test_type3()
{
  osg::ref_ptr<osg::Group> myNode = new osg::Group;
  myNode->setName( "Node : My first name" );

  osgIntrospection::Value v(std::string("Node : My new name "));
  osgIntrospection::Value myVal(myNode.get());
  const osgIntrospection::Type& myType = myVal.getInstanceType();

 
  osgIntrospection::ParameterInfoList paramIL;
  const osgIntrospection::PropertyInfo* pi = myType.getProperty("Name", osgIntrospection::Reflection::getType("std::string"), paramIL, true);

  pi->setValue(myVal, v);
  std::cout << "returned value type : " << pi->getValue(myVal).toString() << "\n";

}

void test_type2()
{
  osg::ref_ptr<osg::Group> myNode = new osg::Group;
  myNode->setName( "Node : My first name" );

  osgIntrospection::ValueList vl;
  osgIntrospection::Value myVal(myNode.get());

  
  const osgIntrospection::Type& myType = myVal.getInstanceType();

  vl.push_back(std::string( "Node : My new name " ));
 
  myType.invokeMethod("setName", myVal, vl, true);
  
  osgIntrospection::ValueList vl2;
  std::cout << "returned value type : " << myType.invokeMethod("getName", myVal, vl2, true).toString() << "\n";
}


void test_type()
{
   osg::ref_ptr<osg::Node> myNode = new osg::Node;
   myNode->setName( "Node : My first name" );

   osgIntrospection::ValueList vl;
   osgIntrospection::Value val=osgIntrospection::Value(myNode.get());

   vl.push_back(std::string( "Node : My new name " ));

   osgIntrospection::Value val2 =
val.getType().getPointedType().invokeMethod("setName",val, vl, true );

   std::cout << "returned value type : " << ( val2.getType () ).getName
() << "\n";
}

int main()
{
  osg::ref_ptr<osgDB::DynamicLibrary> osg_reflectors = 
    osgDB::DynamicLibrary::loadLibrary(createLibraryNameForWrapper("osg"));

  try
    {
      test_type();
      test_type2();
      test_type3();
    }
  catch(osgIntrospection::Exception& ex)
    {
      std::cout << "exception catch : " << ex.what() << std::endl;
    }

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

Reply via email to