2006/10/17, Jose Luis Hidalgo <[EMAIL PROTECTED]
>:
In the wrapper, the type reflected it the "not-const and not-pointer and not-referenced" type
so only the osgIntrospection::Type "osg::Group" is defined. This Type define itself the Type for pointer and for the const pointer. (See the Doxygen)
To avoid duplication information, only the Type "osg::Group" have a baseTypeList, MethodList and PropertyList and ...
So if you have a value with a "osg::Group * " inside (more generally, if you have a pointer type), you must find the PointedType with Type::getPointedType. With this new Type (the same as before but not a pointer) you could have some request on it (getMethod or getBasePointer or isSubclassOf).
So in order:
1) get the Type of the value
2) check if Type isNonConstPointer
3) get the pointed type
4) check the pointed type based list
5) use variant_cast
see the modified test.cpp joint
Lol, this is not a really intuitive way, but when you learn who to work osgIntrospection, this mechanism become more logic.
To learn howto work osgIntrospection (or any library), generate a Doxygen with the source, and all Dot feature (callgraph, ...) and read it.
go to the ReflectionFramwork wiki page and read "Requirements" and "Design suggestions"
go to the Reflect Home Page (very good introspection library, evolution of the Cern Seal Project)
If you are not confident with template and meta-programming template, look it because
introspection is a good target for this programming method (all things that could be define at compile time must be done)
The first task to do is to redifine the needs we have about the osgIntrospection.
For example:
- allow the reflection of global method and property
- allow a safe way to unload wrapper
- allow the possibility to create a new instance on the heap of a not-ObjectValue (for exemple do a "new int")
- allow the possibility to delete pointer
- redifine some concept (Scope, cast, ...)
- allow the reflection of a template with all property and method
and reflection of a template instance with just the parameter template
...
In two or three week, we start a discution on the evolution (or revolution) of osgIntrospection.
in one or two month, we start a first implementation, must be finish two month later.
in three or four month, we restart a new implementation based on the first and optimized (with for example template and template meta-programming), must be finish in two or three month later.
In six or seven month, a robust and stable osgIntrospection library must be done. Be Happy :-)
so see you soon
Thank for your futur help
David
On 10/17/06, david callu <[EMAIL PROTECTED]> wrote:
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?
In the wrapper, the type reflected it the "not-const and not-pointer and not-referenced" type
so only the osgIntrospection::Type "osg::Group" is defined. This Type define itself the Type for pointer and for the const pointer. (See the Doxygen)
To avoid duplication information, only the Type "osg::Group" have a baseTypeList, MethodList and PropertyList and ...
So if you have a value with a "osg::Group * " inside (more generally, if you have a pointer type), you must find the PointedType with Type::getPointedType. With this new Type (the same as before but not a pointer) you could have some request on it (getMethod or getBasePointer or isSubclassOf).
So in order:
1) get the Type of the value
2) check if Type isNonConstPointer
3) get the pointed type
4) check the pointed type based list
5) use variant_cast
see the modified test.cpp joint
Lol, this is not a really intuitive way, but when you learn who to work osgIntrospection, this mechanism become more logic.
I promise to learn about osgIntrospection and help in the near future,
do you have a list of tasks to do? where to start?
To learn howto work osgIntrospection (or any library), generate a Doxygen with the source, and all Dot feature (callgraph, ...) and read it.
go to the ReflectionFramwork wiki page and read "Requirements" and "Design suggestions"
go to the Reflect Home Page (very good introspection library, evolution of the Cern Seal Project)
If you are not confident with template and meta-programming template, look it because
introspection is a good target for this programming method (all things that could be define at compile time must be done)
The first task to do is to redifine the needs we have about the osgIntrospection.
For example:
- allow the reflection of global method and property
- allow a safe way to unload wrapper
- allow the possibility to create a new instance on the heap of a not-ObjectValue (for exemple do a "new int")
- allow the possibility to delete pointer
- redifine some concept (Scope, cast, ...)
- allow the reflection of a template with all property and method
and reflection of a template instance with just the parameter template
...
In two or three week, we start a discution on the evolution (or revolution) of osgIntrospection.
in one or two month, we start a first implementation, must be finish two month later.
in three or four month, we restart a new implementation based on the first and optimized (with for example template and template meta-programming), must be finish in two or three month later.
In six or seven month, a robust and stable osgIntrospection library must be done. Be Happy :-)
so see you soon
Thank for your futur help
David
#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)
{
try
{
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;
const osgIntrospection::Type &ptype = type.getPointedType();
if (ptype.isDefined() && ptype.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;
}
else 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) )
{
}
*/
}
catch(osgIntrospection::Exception & ex)
{
std::cerr << "catch exception " << ex.what() << std::endl;
}
}
class Dummy {};
int main()
{
osg::ref_ptr<osgDB::DynamicLibrary> osg_lib = load("osg");
// ** try without this: an exception is throw because osgProducer use osgGA
// ** and when we call Type::isSubclassOf, all base cllas must be define
//osg::ref_ptr<osgDB::DynamicLibrary> osgGA_lib = load("osgGA");
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/
