2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-04-29 18:06:50 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
//osgIntrospection - Copyright (C) 2005 Marco Jez
|
2005-04-29 19:22:15 +08:00
|
|
|
#ifndef OSGINTROSPECTION_TYPE
|
|
|
|
#define OSGINTROSPECTION_TYPE
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
#include <osgIntrospection/Export>
|
|
|
|
#include <osgIntrospection/Exceptions>
|
|
|
|
#include <osgIntrospection/Value>
|
|
|
|
#include <osgIntrospection/CustomAttributeProvider>
|
2007-02-13 01:14:46 +08:00
|
|
|
#include <osgIntrospection/ExtendedTypeInfo>
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <typeinfo>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2005-04-04 21:50:07 +08:00
|
|
|
#include <algorithm>
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
namespace osgIntrospection
|
|
|
|
{
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
// forward declarations
|
|
|
|
class MethodInfo;
|
|
|
|
class PropertyInfo;
|
|
|
|
class ParameterInfo;
|
|
|
|
class ReaderWriter;
|
2005-04-04 21:50:07 +08:00
|
|
|
class ConstructorInfo;
|
|
|
|
struct Comparator;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
// typedefs for member info lists
|
2006-09-01 20:52:15 +08:00
|
|
|
typedef std::vector<const MethodInfo* > MethodInfoList;
|
|
|
|
typedef std::vector<const PropertyInfo* > PropertyInfoList;
|
2005-04-29 19:19:58 +08:00
|
|
|
typedef std::vector<const ParameterInfo* > ParameterInfoList;
|
|
|
|
typedef std::vector<const ConstructorInfo* > ConstructorInfoList;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2006-09-01 20:52:15 +08:00
|
|
|
// typedefs for member info map
|
|
|
|
typedef std::map<const Type*, PropertyInfoList > PropertyInfoMap;
|
|
|
|
typedef std::map<const Type*, MethodInfoList > MethodInfoMap;
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
// typedef for enum label map
|
|
|
|
typedef std::map<int, std::string> EnumLabelMap;
|
|
|
|
|
2006-09-01 20:52:15 +08:00
|
|
|
// typedef for base type
|
|
|
|
typedef std::vector<const Type* > TypeList;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Objects of class Type are used to maintain information about
|
|
|
|
/// reflected types. They also provide a number of services, like
|
|
|
|
/// instance creation and dynamic calling of methods.
|
|
|
|
/// All details about the data type being described are available
|
|
|
|
/// at runtime, provided that the type was defined (and not just
|
|
|
|
/// declared) through a Reflector class.
|
|
|
|
/// It is not possible to modify a Type object once it has been
|
|
|
|
/// created, unless you are a class derived from Reflector (which
|
|
|
|
/// has firm friendship with this class).
|
|
|
|
class OSGINTROSPECTION_EXPORT Type: public CustomAttributeProvider
|
|
|
|
{
|
|
|
|
public:
|
2007-03-01 19:54:30 +08:00
|
|
|
/// Function category specifier for querying constructors and
|
|
|
|
/// methods.
|
|
|
|
enum FunctionCategory
|
|
|
|
{
|
|
|
|
PUBLIC_FUNCTIONS,
|
|
|
|
PROTECTED_FUNCTIONS
|
|
|
|
};
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Destructor. Note that this class is not meant to be subclassed.
|
|
|
|
~Type();
|
|
|
|
|
|
|
|
/// Returns a reference to the std::type_info instance associated
|
|
|
|
/// to this Type.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::type_info& getStdTypeInfo() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
/// Returns a reference to the ExtendedTypeInfo associated
|
|
|
|
/// to this Type.
|
|
|
|
inline ExtendedTypeInfo getExtendedTypeInfo() const;
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Returns true if this Type is defined, false if it's just
|
|
|
|
/// declared. See class Reflector if you want to create a new Type.
|
|
|
|
inline bool isDefined() const;
|
|
|
|
|
|
|
|
/// Returns the name of the reflected type.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& getName() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the namespace of the reflected type.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& getNamespace() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the qualified name of the reflected type. The qualified
|
|
|
|
/// name is formed by the namespace, if present, plus other modifiers
|
|
|
|
/// like 'const' and/or '*' (pointer) where applicable.
|
|
|
|
inline std::string getQualifiedName() const;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
/// Returns true if either the fully-qualified name or one of the
|
|
|
|
/// name aliases match the given argument
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool matchesName(const std::string& name) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
From David Callu:
"
the main problem is the wrapper generation:
The PropertyInfo class use MethodInfo class to access to the value.
When the property are define with the I_Property* macro,
the MethodInfo use by the property to have access to the value
are instancied in the I_Property* macro, but there
are already instantied by the I_Method* macro before
secondary problem:
- the function used by the property could no be customized
in the genwrapper.conf file
- an array property can't insert a value
- the std::map reflector (and indexedProperty in general) haven't remove method
- about the help in wrapper ... why not ...
solution :
To use the function define by the I_Method, I add a MethodInfo variable in the I_Method0 macro
old macro :
#define I_Method0(ret, fn) (\
params.clear(),\
addMethod(new osgIntrospection::TypedMethodIn
fo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params)))
new macro :
#define I_Method0(ret, fn, signature, briefHelp, detailedHelp) \
params.clear(); \
osgIntrospection::MethodInfo* signature = addMethod(new osgIntrospection::TypedMethodInfo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params, briefHelp, detailedHelp)); sink(signature)
the osgIntrospection::MethodInfo* signature is used by the I_Property macro to define the MethodInfo that it use
so for I_Property macro :
old macro :
#define I_PropertyWithReturnType(t, n, r) \
cap=addProperty(new osgIntrospection::PropertyInfo(osgIntrospection::Reflection::getType(typeid(reflected_type)), osgIntrospection::Reflection::getType(typeid(t)), #n, \
I_Method0(t, get##n), \
I_Method1(r, set##n, IN, t, value)))
new macro:
#define I_SimpleProperty(t, n, get, set) \
get, \
set))
The genwrapper has been modified in this way.
The method signature is define by the prototype of the method
For example, the "const char* libraryName();" have "__C5_char_P1__libraryName" for signature
solution for secondary problem:
The genwrapper accept new tokens in the configuration to custumize the property.
The new PropertyInserter and the CustomPropertyInsertAttribute class has been defined
The PropertyRemover has been added to the StdMapReflector
The _briefHelp and _detailedHelp variable has been added in PropertyInfo, MethodInfo and ContructorInfo class
modification:
I have modify the genwrapper files
Configuration.cpp Configuration.h add some tokens to custumize the property
Doxyfile.template add the comment in the output xml
genwrapper.conf customize some property in osg::Geometry
RegistryBuilder.h RegistryBuilder.cpp add the process_help function (to extract help from xml)
TypeRegister.cpp TypeRegister.h optimize the property detection
TypeDesc.h TypeDesc.cpp modify FunctionDesc and PropertyDesc
WrapperGenerator.h WrapperGenerator.cpp modify the output
I also modify the fallowing osgIntrospection files:
include/osgIntrospection/Attributes add the PropertyInserter and the CustomPropertyInsertAttribute class
include/osgIntrospection/ConstructorInfo add the _briefHelp and _detailedHelp variable in the ConstructorInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/MethodInfo add the _briefHelp and _detailedHelp variable in the MethodInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/PropertyInfo add the _briefHelp and _detailedHelp variable in the PropertyInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/ReflectionMacro remove unused I_Property* macro
modify all I_Method macro to accept the help string
modify all I_Method macro to define a MethodInfo signature
include/osgIntrospection/Reflector add the PropertyInserter in StdVectorReflector and StdListReflector
add the PropertyRemover in the StdMapReflector
include/osgIntrospection/StaticMethodInfo modify all StaticMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedMethodInfo modify all TypedMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedConstructorInfo modify all TypedConstructorInfo* to accept the help in parameter
include/osgIntrospection/Type add the _briefHelp and _detailedHelp variable in the Type class
"
2006-10-17 23:17:06 +08:00
|
|
|
/// Returns the brief help of the reflected type.
|
|
|
|
inline virtual const std::string& getBriefHelp() const;
|
|
|
|
|
|
|
|
/// Returns the detailed help of the reflected type.
|
|
|
|
inline virtual const std::string& getDetailedHelp() const;
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Returns the number of base types.
|
|
|
|
/// This number is zero if the type is not derived from any other
|
|
|
|
/// type.
|
|
|
|
inline int getNumBaseTypes() const;
|
|
|
|
|
|
|
|
/// Returns the i-th base type.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& getBaseType(int i) const;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2006-09-01 20:52:15 +08:00
|
|
|
/// Returns the base type list.
|
|
|
|
inline const TypeList& getBaseTypeList() const;
|
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Returns the number of type name aliases.
|
|
|
|
inline int getNumAliases() const;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Returns the i-th name alias
|
2005-04-29 19:19:58 +08:00
|
|
|
const std::string& getAlias(int i) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns whether the reflected type is abstract.
|
|
|
|
inline bool isAbstract() const;
|
|
|
|
|
|
|
|
/// Returns whether the reflected type is "atomic", that is
|
|
|
|
/// it can be rendered to and decoded from a stream directly.
|
|
|
|
inline bool isAtomic() const;
|
|
|
|
|
|
|
|
/// Returns whether the reflected type is an enumeration.
|
|
|
|
inline bool isEnum() const;
|
|
|
|
|
|
|
|
/// Returns whether the reflected type is the type void.
|
|
|
|
inline bool isVoid() const;
|
|
|
|
|
|
|
|
/// Returns true if the reflected type is a pointer, false otherwise.
|
|
|
|
inline bool isPointer() const;
|
|
|
|
|
|
|
|
/// Returns true if the reflected type is a pointer AND it is const,
|
|
|
|
/// false otherwise.
|
|
|
|
inline bool isConstPointer() const;
|
|
|
|
|
|
|
|
/// Returns true if the reflected type is a pointer AND it is not
|
|
|
|
/// const, false otherwise.
|
|
|
|
inline bool isNonConstPointer() const;
|
|
|
|
|
|
|
|
/// Returns the pointed type. If the reflected type is not a pointer,
|
|
|
|
/// the object returned is typeof(void).
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& getPointedType() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
/// Returns true if the reflected type is a reference, false otherwise.
|
|
|
|
inline bool isReference() const;
|
|
|
|
|
|
|
|
/// Returns true if the reflected type is a reference AND it is const,
|
|
|
|
/// false otherwise.
|
|
|
|
inline bool isConstReference() const;
|
|
|
|
|
|
|
|
/// Returns true if the reflected type is a reference AND it is not
|
|
|
|
/// const, false otherwise.
|
|
|
|
inline bool isNonConstReference() const;
|
|
|
|
|
|
|
|
/// Returns the referenced type. If the reflected type is not a reference,
|
|
|
|
/// the object returned is typeof(void).
|
|
|
|
inline const Type& getReferencedType() const;
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Returns the list of properties defined for this type. The list
|
|
|
|
/// does not include properties inherited from base types.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const PropertyInfoList& getProperties() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Fills a list of properties that are either defined in this Type
|
|
|
|
/// or in inherited types.
|
2005-04-29 19:19:58 +08:00
|
|
|
void getAllProperties(PropertyInfoList& props) const;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
|
|
|
/// Fills a map of "type <-> propertyInfoList" that are either defined in this Type
|
|
|
|
/// or in inherited types.
|
|
|
|
void getPropertiesMap(PropertyInfoMap& props) const;
|
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Returns the list of constructors defined for this type.
|
2007-03-01 19:54:30 +08:00
|
|
|
inline const ConstructorInfoList& getConstructors(FunctionCategory category = PUBLIC_FUNCTIONS) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the list of methods defined for this type. The list
|
|
|
|
/// does not include methods inherited from base types.
|
2007-03-01 19:54:30 +08:00
|
|
|
inline const MethodInfoList& getMethods(FunctionCategory category = PUBLIC_FUNCTIONS) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Fills a list of methods that are either defined in this Type
|
|
|
|
/// or in inherited types.
|
2007-03-01 19:54:30 +08:00
|
|
|
void getAllMethods(MethodInfoList& methods, FunctionCategory category = PUBLIC_FUNCTIONS) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2006-09-01 20:52:15 +08:00
|
|
|
/// Fills a map of "type <-> MethodInfoList" that are either defined in this Type
|
|
|
|
/// or in inherited types.
|
2007-03-01 19:54:30 +08:00
|
|
|
void getMethodsMap(MethodInfoMap& methods, FunctionCategory category = PUBLIC_FUNCTIONS) const;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Returns the map of enumeration labels. If the type is not an
|
|
|
|
/// enumeration, an empty map is returned.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const EnumLabelMap& getEnumLabels() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Searches for a constructor that can be called with the given list
|
|
|
|
/// of arguments without raising type conversion errors. If more than
|
|
|
|
/// one constructors are suitable for calling, the best match is
|
|
|
|
/// returned.
|
2005-04-29 19:19:58 +08:00
|
|
|
const ConstructorInfo* getCompatibleConstructor(const ValueList& values) const;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Searches for a constructor whose parameters match exactly the given
|
|
|
|
/// list of parameter descriptions.
|
2005-04-29 19:19:58 +08:00
|
|
|
const ConstructorInfo* getConstructor(const ParameterInfoList& params) const;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Searches for a method that can be called with the given list of
|
|
|
|
/// arguments without raising type conversion errors. If more than
|
|
|
|
/// one method are suitable for calling, the best match is returned.
|
2005-04-29 19:19:58 +08:00
|
|
|
const MethodInfo* getCompatibleMethod(const std::string& name, const ValueList& values, bool inherit) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Searches for a method whose parameters match exactly the given
|
|
|
|
/// list of parameter descriptions.
|
2005-04-29 19:19:58 +08:00
|
|
|
const MethodInfo* getMethod(const std::string& name, const ParameterInfoList& params, bool inherit) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Searches for a property given its name, type and list of indices.
|
|
|
|
/// Only exact matches are returned.
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyInfo* getProperty(const std::string& name, const Type& ptype, const ParameterInfoList& indices, bool inherit) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Searches for a suitable method and invokes it with the given list
|
|
|
|
/// of arguments (const instance).
|
2005-04-29 19:19:58 +08:00
|
|
|
Value invokeMethod(const std::string& name, const Value& instance, ValueList& args, bool inherit) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Searches for a suitable method and invokes it with the given list
|
|
|
|
/// of arguments.
|
2005-04-29 19:19:58 +08:00
|
|
|
Value invokeMethod(const std::string& name, Value& instance, ValueList& args, bool inherit) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns whether the reflected type is derived from another type.
|
2005-04-29 19:19:58 +08:00
|
|
|
bool isSubclassOf(const Type& type) const;
|
2004-12-09 13:28:20 +08:00
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Returns the instance of the reader/writer object assigned to
|
|
|
|
/// this type, if any. Otherwise it returns the null pointer.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const ReaderWriter* getReaderWriter() const;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
/// Returns the instance of the comparator object assigned to
|
|
|
|
/// this type, if any. Otherwise it returns the null pointer.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Comparator* getComparator() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2007-06-08 18:11:00 +08:00
|
|
|
/// Returns the path to the file where this type is declared,
|
|
|
|
/// relative the the OpenSceneGraph include directory. Returns
|
|
|
|
/// the empty string if no path information is available.
|
|
|
|
inline const std::string &getDeclaringFile() const;
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// Creates an instance of the reflected type. The returned Value
|
|
|
|
/// can be casted to T*, where T is the reflected type. If the type
|
|
|
|
/// is abstract, an exception is thrown.
|
2005-04-29 19:19:58 +08:00
|
|
|
Value createInstance(ValueList& args) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
inline Value createInstance() const;
|
|
|
|
|
2008-02-26 00:26:30 +08:00
|
|
|
// This function is called internally to reset all the elements contained in that type.
|
|
|
|
// used in the type loading process: it solves a false positive issue on VS 7.1 and 8 compilers in debug builds.
|
|
|
|
void reset();
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
protected:
|
2007-02-13 01:14:46 +08:00
|
|
|
Type(const ExtendedTypeInfo &ti)
|
2005-04-29 19:19:58 +08:00
|
|
|
: _ti(ti),
|
|
|
|
_is_const(false),
|
|
|
|
_is_abstract(false),
|
|
|
|
_pointed_type(0),
|
2007-02-13 01:14:46 +08:00
|
|
|
_referenced_type(0),
|
2005-04-29 19:19:58 +08:00
|
|
|
_is_defined(false),
|
|
|
|
_rw(0),
|
|
|
|
_cmp(0)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// throws an exception if the type is not defined.
|
|
|
|
void check_defined() const;
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename C> friend class Reflector;
|
2005-04-04 21:50:07 +08:00
|
|
|
template<typename C> friend struct TypeNameAliasProxy;
|
2005-03-14 17:28:31 +08:00
|
|
|
friend class Reflection;
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
Type(const Type& copy): CustomAttributeProvider(copy), _ti(copy._ti) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
ExtendedTypeInfo _ti;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
std::string _name;
|
|
|
|
std::string _namespace;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
TypeList _base;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
bool _is_const;
|
|
|
|
bool _is_abstract;
|
|
|
|
const Type* _pointed_type;
|
2007-02-13 01:14:46 +08:00
|
|
|
const Type* _referenced_type;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
ConstructorInfoList _cons;
|
2007-03-01 19:54:30 +08:00
|
|
|
ConstructorInfoList _protected_cons;
|
2005-04-29 19:19:58 +08:00
|
|
|
PropertyInfoList _props;
|
|
|
|
MethodInfoList _methods;
|
2007-03-01 19:54:30 +08:00
|
|
|
MethodInfoList _protected_methods;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
EnumLabelMap _labels;
|
|
|
|
bool _is_defined;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const ReaderWriter* _rw;
|
|
|
|
const Comparator* _cmp;
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
typedef std::vector<std::string> AliasList;
|
2005-04-29 19:19:58 +08:00
|
|
|
AliasList _aliases;
|
From David Callu:
"
the main problem is the wrapper generation:
The PropertyInfo class use MethodInfo class to access to the value.
When the property are define with the I_Property* macro,
the MethodInfo use by the property to have access to the value
are instancied in the I_Property* macro, but there
are already instantied by the I_Method* macro before
secondary problem:
- the function used by the property could no be customized
in the genwrapper.conf file
- an array property can't insert a value
- the std::map reflector (and indexedProperty in general) haven't remove method
- about the help in wrapper ... why not ...
solution :
To use the function define by the I_Method, I add a MethodInfo variable in the I_Method0 macro
old macro :
#define I_Method0(ret, fn) (\
params.clear(),\
addMethod(new osgIntrospection::TypedMethodIn
fo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params)))
new macro :
#define I_Method0(ret, fn, signature, briefHelp, detailedHelp) \
params.clear(); \
osgIntrospection::MethodInfo* signature = addMethod(new osgIntrospection::TypedMethodInfo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params, briefHelp, detailedHelp)); sink(signature)
the osgIntrospection::MethodInfo* signature is used by the I_Property macro to define the MethodInfo that it use
so for I_Property macro :
old macro :
#define I_PropertyWithReturnType(t, n, r) \
cap=addProperty(new osgIntrospection::PropertyInfo(osgIntrospection::Reflection::getType(typeid(reflected_type)), osgIntrospection::Reflection::getType(typeid(t)), #n, \
I_Method0(t, get##n), \
I_Method1(r, set##n, IN, t, value)))
new macro:
#define I_SimpleProperty(t, n, get, set) \
get, \
set))
The genwrapper has been modified in this way.
The method signature is define by the prototype of the method
For example, the "const char* libraryName();" have "__C5_char_P1__libraryName" for signature
solution for secondary problem:
The genwrapper accept new tokens in the configuration to custumize the property.
The new PropertyInserter and the CustomPropertyInsertAttribute class has been defined
The PropertyRemover has been added to the StdMapReflector
The _briefHelp and _detailedHelp variable has been added in PropertyInfo, MethodInfo and ContructorInfo class
modification:
I have modify the genwrapper files
Configuration.cpp Configuration.h add some tokens to custumize the property
Doxyfile.template add the comment in the output xml
genwrapper.conf customize some property in osg::Geometry
RegistryBuilder.h RegistryBuilder.cpp add the process_help function (to extract help from xml)
TypeRegister.cpp TypeRegister.h optimize the property detection
TypeDesc.h TypeDesc.cpp modify FunctionDesc and PropertyDesc
WrapperGenerator.h WrapperGenerator.cpp modify the output
I also modify the fallowing osgIntrospection files:
include/osgIntrospection/Attributes add the PropertyInserter and the CustomPropertyInsertAttribute class
include/osgIntrospection/ConstructorInfo add the _briefHelp and _detailedHelp variable in the ConstructorInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/MethodInfo add the _briefHelp and _detailedHelp variable in the MethodInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/PropertyInfo add the _briefHelp and _detailedHelp variable in the PropertyInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/ReflectionMacro remove unused I_Property* macro
modify all I_Method macro to accept the help string
modify all I_Method macro to define a MethodInfo signature
include/osgIntrospection/Reflector add the PropertyInserter in StdVectorReflector and StdListReflector
add the PropertyRemover in the StdMapReflector
include/osgIntrospection/StaticMethodInfo modify all StaticMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedMethodInfo modify all TypedMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedConstructorInfo modify all TypedConstructorInfo* to accept the help in parameter
include/osgIntrospection/Type add the _briefHelp and _detailedHelp variable in the Type class
"
2006-10-17 23:17:06 +08:00
|
|
|
|
|
|
|
std::string _briefHelp;
|
|
|
|
std::string _detailedHelp;
|
2007-06-08 18:11:00 +08:00
|
|
|
|
|
|
|
std::string _declaringFile;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// OPERATORS
|
|
|
|
|
|
|
|
/// Equality test operator. Returns true if the two instances of Type
|
|
|
|
/// describe the same type, false otherwise.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool operator==(const Type& t1, const Type& t2)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
return (t1.getStdTypeInfo() == t2.getStdTypeInfo()) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Inequality test operator. Returns false if the two instances of Type
|
|
|
|
/// describe the same type, true otherwise.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool operator!=(const Type& t1, const Type& t2)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
return (t1.getStdTypeInfo() != t2.getStdTypeInfo()) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Less than operator. Returns true if the first type comes before the
|
|
|
|
/// second one. The actual ordering is implementation-dependent.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool operator<(const Type& t1, const Type& t2)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
return (t1.getStdTypeInfo().before(t2.getStdTypeInfo())) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Greater than or equal to operator. Returns !operator<().
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool operator>=(const Type& t1, const Type& t2)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
return !operator<(t1, t2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
|
|
|
inline void Type::check_defined() const
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
if (!_is_defined)
|
|
|
|
throw TypeNotDefinedException(_ti);
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::type_info& Type::getStdTypeInfo() const
|
2007-02-13 01:14:46 +08:00
|
|
|
{
|
|
|
|
return _ti.getStdTypeInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ExtendedTypeInfo Type::getExtendedTypeInfo() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _ti;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& Type::getName() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _name;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& Type::getNamespace() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _namespace;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string Type::getQualifiedName() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
std::string qname;
|
2005-04-29 19:19:58 +08:00
|
|
|
if (_is_const) qname = "const ";
|
|
|
|
if (!_namespace.empty())
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
qname.append(_namespace);
|
2005-03-14 17:28:31 +08:00
|
|
|
qname.append("::");
|
|
|
|
}
|
2005-04-29 19:19:58 +08:00
|
|
|
qname.append(_name);
|
|
|
|
if (_pointed_type)
|
2005-03-14 17:28:31 +08:00
|
|
|
qname.append(" *");
|
2007-02-13 01:14:46 +08:00
|
|
|
else if (_referenced_type)
|
|
|
|
qname.append(" &");
|
2005-03-14 17:28:31 +08:00
|
|
|
return qname;
|
|
|
|
}
|
|
|
|
|
From David Callu:
"
the main problem is the wrapper generation:
The PropertyInfo class use MethodInfo class to access to the value.
When the property are define with the I_Property* macro,
the MethodInfo use by the property to have access to the value
are instancied in the I_Property* macro, but there
are already instantied by the I_Method* macro before
secondary problem:
- the function used by the property could no be customized
in the genwrapper.conf file
- an array property can't insert a value
- the std::map reflector (and indexedProperty in general) haven't remove method
- about the help in wrapper ... why not ...
solution :
To use the function define by the I_Method, I add a MethodInfo variable in the I_Method0 macro
old macro :
#define I_Method0(ret, fn) (\
params.clear(),\
addMethod(new osgIntrospection::TypedMethodIn
fo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params)))
new macro :
#define I_Method0(ret, fn, signature, briefHelp, detailedHelp) \
params.clear(); \
osgIntrospection::MethodInfo* signature = addMethod(new osgIntrospection::TypedMethodInfo0<reflected_type, ret >(qualifyName(#fn), &reflected_type::fn, params, briefHelp, detailedHelp)); sink(signature)
the osgIntrospection::MethodInfo* signature is used by the I_Property macro to define the MethodInfo that it use
so for I_Property macro :
old macro :
#define I_PropertyWithReturnType(t, n, r) \
cap=addProperty(new osgIntrospection::PropertyInfo(osgIntrospection::Reflection::getType(typeid(reflected_type)), osgIntrospection::Reflection::getType(typeid(t)), #n, \
I_Method0(t, get##n), \
I_Method1(r, set##n, IN, t, value)))
new macro:
#define I_SimpleProperty(t, n, get, set) \
get, \
set))
The genwrapper has been modified in this way.
The method signature is define by the prototype of the method
For example, the "const char* libraryName();" have "__C5_char_P1__libraryName" for signature
solution for secondary problem:
The genwrapper accept new tokens in the configuration to custumize the property.
The new PropertyInserter and the CustomPropertyInsertAttribute class has been defined
The PropertyRemover has been added to the StdMapReflector
The _briefHelp and _detailedHelp variable has been added in PropertyInfo, MethodInfo and ContructorInfo class
modification:
I have modify the genwrapper files
Configuration.cpp Configuration.h add some tokens to custumize the property
Doxyfile.template add the comment in the output xml
genwrapper.conf customize some property in osg::Geometry
RegistryBuilder.h RegistryBuilder.cpp add the process_help function (to extract help from xml)
TypeRegister.cpp TypeRegister.h optimize the property detection
TypeDesc.h TypeDesc.cpp modify FunctionDesc and PropertyDesc
WrapperGenerator.h WrapperGenerator.cpp modify the output
I also modify the fallowing osgIntrospection files:
include/osgIntrospection/Attributes add the PropertyInserter and the CustomPropertyInsertAttribute class
include/osgIntrospection/ConstructorInfo add the _briefHelp and _detailedHelp variable in the ConstructorInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/MethodInfo add the _briefHelp and _detailedHelp variable in the MethodInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/PropertyInfo add the _briefHelp and _detailedHelp variable in the PropertyInfo class
add access function for the two new variables (_briefHelp and _detailedHelp)
modify the constructor to define the two new variables (_briefHelp and _detailedHelp)
include/osgIntrospection/ReflectionMacro remove unused I_Property* macro
modify all I_Method macro to accept the help string
modify all I_Method macro to define a MethodInfo signature
include/osgIntrospection/Reflector add the PropertyInserter in StdVectorReflector and StdListReflector
add the PropertyRemover in the StdMapReflector
include/osgIntrospection/StaticMethodInfo modify all StaticMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedMethodInfo modify all TypedMethodInfo* to accept the help in parameter
include/osgIntrospection/TypedConstructorInfo modify all TypedConstructorInfo* to accept the help in parameter
include/osgIntrospection/Type add the _briefHelp and _detailedHelp variable in the Type class
"
2006-10-17 23:17:06 +08:00
|
|
|
inline const std::string& Type::getBriefHelp() const
|
|
|
|
{
|
|
|
|
return _briefHelp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const std::string& Type::getDetailedHelp() const
|
|
|
|
{
|
|
|
|
return _detailedHelp;
|
|
|
|
}
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
inline int Type::getNumBaseTypes() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return static_cast<int>(_base.size());
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isConstPointer() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _is_const && _pointed_type;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isNonConstPointer() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return !_is_const && _pointed_type;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
inline bool Type::isConstReference() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
return _is_const && _referenced_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isNonConstReference() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
return !_is_const && _referenced_type;
|
|
|
|
}
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
inline bool Type::isAbstract() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _is_abstract;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isAtomic() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _rw != 0;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const PropertyInfoList& Type::getProperties() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _props;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2007-03-01 19:54:30 +08:00
|
|
|
inline const ConstructorInfoList& Type::getConstructors(FunctionCategory category) const
|
2005-04-04 21:50:07 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
check_defined();
|
2007-03-01 19:54:30 +08:00
|
|
|
return category == PUBLIC_FUNCTIONS ? _cons : _protected_cons;
|
2005-04-04 21:50:07 +08:00
|
|
|
}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2007-03-01 19:54:30 +08:00
|
|
|
inline const MethodInfoList& Type::getMethods(FunctionCategory category) const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2007-03-01 19:54:30 +08:00
|
|
|
return category == PUBLIC_FUNCTIONS ? _methods : _protected_methods;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isPointer() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _pointed_type != 0;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
inline bool Type::isReference() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
return _referenced_type != 0;
|
|
|
|
}
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
inline bool Type::isVoid() const
|
|
|
|
{
|
2007-02-13 01:14:46 +08:00
|
|
|
return (_ti == extended_typeid<void>()) != 0;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& Type::getPointedType() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
if (_pointed_type)
|
|
|
|
return *_pointed_type;
|
2005-03-14 17:28:31 +08:00
|
|
|
return Reflection::type_void();
|
|
|
|
}
|
|
|
|
|
2007-02-13 01:14:46 +08:00
|
|
|
inline const Type& Type::getReferencedType() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
if (_referenced_type)
|
|
|
|
return *_referenced_type;
|
|
|
|
return Reflection::type_void();
|
|
|
|
}
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
inline bool Type::isEnum() const
|
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return !_labels.empty();
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const EnumLabelMap& Type::getEnumLabels() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _labels;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Type::isDefined() const
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _is_defined;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const ReaderWriter* Type::getReaderWriter() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _rw;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Comparator* Type::getComparator() const
|
2005-04-04 21:50:07 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return _cmp;
|
2005-04-04 21:50:07 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& Type::getBaseType(int i) const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
check_defined();
|
2005-04-29 19:19:58 +08:00
|
|
|
return *_base.at(i);
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2006-09-01 20:52:15 +08:00
|
|
|
inline const TypeList& Type::getBaseTypeList() const
|
|
|
|
{
|
|
|
|
check_defined();
|
|
|
|
return _base;
|
|
|
|
}
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
inline Value Type::createInstance() const
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
ValueList args;
|
2005-04-04 21:50:07 +08:00
|
|
|
return createInstance(args);
|
|
|
|
}
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-04 21:50:07 +08:00
|
|
|
inline int Type::getNumAliases() const
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return static_cast<int>(_aliases.size());
|
2005-04-04 21:50:07 +08:00
|
|
|
}
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& Type::getAlias(int i) const
|
2005-04-04 21:50:07 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _aliases[i];
|
2005-04-04 21:50:07 +08:00
|
|
|
}
|
2006-09-01 20:52:15 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline bool Type::matchesName(const std::string& name) const
|
2005-04-04 21:50:07 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
if (getQualifiedName() == name)
|
|
|
|
return true;
|
|
|
|
if (std::find(_aliases.begin(), _aliases.end(), name) != _aliases.end())
|
|
|
|
return true;
|
|
|
|
return false;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
2004-12-09 13:28:20 +08:00
|
|
|
|
2007-06-08 18:11:00 +08:00
|
|
|
inline const std::string &Type::getDeclaringFile() const
|
|
|
|
{
|
|
|
|
return _declaringFile;
|
|
|
|
}
|
2004-12-09 13:28:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|