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
2004-12-09 13:28:20 +08:00
#ifndef OSGINTROSPECTION_EXCEPTIONS_
#define OSGINTROSPECTION_EXCEPTIONS_
#include <string>
2007-02-13 01:14:46 +08:00
#include <osgIntrospection/ExtendedTypeInfo>
2004-12-09 13:28:20 +08:00
namespace osgIntrospection
{
2005-03-14 17:28:31 +08:00
class Exception
{
public:
2005-04-29 19:19:58 +08:00
Exception(const std::string& msg): msg_(msg) {}
const std::string& what() const throw() { return msg_; }
2005-03-14 17:28:31 +08:00
private:
std::string msg_;
};
struct ReflectionException: public Exception
{
2005-04-29 19:19:58 +08:00
ReflectionException(const std::string& msg): Exception(msg) {}
2005-03-14 17:28:31 +08:00
};
struct TypeNotDefinedException: public ReflectionException
{
2007-02-13 01:14:46 +08:00
TypeNotDefinedException(const ExtendedTypeInfo &ti)
2005-03-14 17:28:31 +08:00
: ReflectionException("type `" + std::string(ti.name()) + "' is declared but not defined")
{
}
};
struct TypeIsAbstractException: public ReflectionException
{
2007-02-13 01:14:46 +08:00
TypeIsAbstractException(const ExtendedTypeInfo &ti)
2005-03-14 17:28:31 +08:00
: ReflectionException("cannot create instances of abstract type `" + std::string(ti.name()) + "'")
{
}
};
2005-04-04 21:50:07 +08:00
struct ConstructorNotFoundException: public ReflectionException
{
2007-02-13 01:14:46 +08:00
ConstructorNotFoundException(const ExtendedTypeInfo &ti)
2005-04-29 19:19:58 +08:00
: ReflectionException("could not find a suitable constructor in type `" + std::string(ti.name()) + "'")
{
}
2005-04-04 21:50:07 +08:00
};
2007-03-01 19:54:30 +08:00
struct ProtectedConstructorInvocationException: public ReflectionException
{
ProtectedConstructorInvocationException()
: ReflectionException("cannot invoke protected constructor")
{
}
};
2005-04-04 21:50:07 +08:00
struct InvokeNotImplementedException: public ReflectionException
{
2005-04-29 19:19:58 +08:00
InvokeNotImplementedException()
: ReflectionException("invoke() not implemented")
{
}
2005-04-04 21:50:07 +08:00
};
2005-03-14 17:28:31 +08:00
struct InvalidFunctionPointerException: public ReflectionException
{
InvalidFunctionPointerException()
: ReflectionException("invalid function pointer during invoke()")
{
}
};
struct ConstIsConstException: public ReflectionException
{
ConstIsConstException()
: ReflectionException("cannot modify a const value")
{
}
};
2007-03-01 19:54:30 +08:00
struct ProtectedMethodInvocationException: public ReflectionException
{
ProtectedMethodInvocationException()
: ReflectionException("cannot invoke protected method")
{
}
};
2005-03-14 17:28:31 +08:00
struct EmptyValueException: public ReflectionException
{
EmptyValueException()
: ReflectionException("cannot retrieve an empty value")
{
}
};
struct TypeNotFoundException: public ReflectionException
{
2005-04-29 19:19:58 +08:00
TypeNotFoundException(const std::string& qname)
2005-03-14 17:28:31 +08:00
: ReflectionException("type `" + qname + "' not found")
{
}
};
struct MethodNotFoundException: public ReflectionException
{
2005-04-29 19:19:58 +08:00
MethodNotFoundException(const std::string& name, const std::string& cname)
2005-03-14 17:28:31 +08:00
: ReflectionException("could not find a suitable method of name `" + name + "' in class `" + cname + "'")
{
}
};
struct StreamWriteErrorException: public ReflectionException
{
StreamWriteErrorException()
: ReflectionException("an error occured while trying to write to a stream")
{
}
};
struct StreamReadErrorException: public ReflectionException
{
StreamReadErrorException()
: ReflectionException("an error occured while trying to read from a stream")
{
}
};
class StreamingNotSupportedException: public ReflectionException
{
public:
enum OperationType
{
ANY,
TEXT_WRITE,
TEXT_READ,
BINARY_WRITE,
BINARY_READ
};
2007-02-13 01:14:46 +08:00
StreamingNotSupportedException(OperationType op, const ExtendedTypeInfo &type)
2005-03-14 17:28:31 +08:00
: ReflectionException(build_msg(op, type))
{
}
private:
2007-02-13 01:14:46 +08:00
std::string build_msg(OperationType op, const ExtendedTypeInfo &type)
2005-03-14 17:28:31 +08:00
{
std::string opstr;
switch (op)
{
case TEXT_WRITE: opstr = "writing to text stream"; break;
case TEXT_READ: opstr = "reading from text stream"; break;
case BINARY_WRITE: opstr = "writing to binary stream"; break;
case BINARY_READ: opstr = "reading from binary stream"; break;
case ANY:
default: opstr = "streaming";
}
return opstr + std::string(" is not supported on type `" + std::string(type.name()) + "'");
}
};
struct TypeConversionException: public ReflectionException
{
2007-02-13 01:14:46 +08:00
TypeConversionException(const ExtendedTypeInfo &type1, const ExtendedTypeInfo &type2)
2005-03-14 17:28:31 +08:00
: ReflectionException("cannot convert from type `" + std::string(type1.name()) + "' to type `" + std::string(type2.name()) + "'")
{
}
};
class PropertyAccessException: public ReflectionException
{
public:
enum AccessType
{
GET,
SET,
IGET,
ISET,
AGET,
ASET,
ADD,
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
INSERT,
2005-04-04 21:50:07 +08:00
REMOVE,
2005-03-14 17:28:31 +08:00
COUNT
};
2005-04-29 19:19:58 +08:00
PropertyAccessException(const std::string& pname, AccessType denied)
2005-03-14 17:28:31 +08:00
: ReflectionException(build_msg(pname, denied))
{
}
private:
2005-04-29 19:19:58 +08:00
std::string build_msg(const std::string& pname, AccessType denied) const
2005-03-14 17:28:31 +08:00
{
std::string msg;
switch (denied)
{
case GET: msg = "retrieved"; break;
case SET: msg = "set"; break;
case IGET: msg = "retrieved with indices"; break;
case ISET: msg = "set with indices"; break;
case AGET: msg = "retrieved with array index"; break;
case ASET: msg = "set with array index"; break;
case ADD: msg = "added"; break;
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
case INSERT: msg = "inserted"; break;
2005-04-04 21:50:07 +08:00
case REMOVE: msg = "removed"; break;
2005-03-14 17:28:31 +08:00
case COUNT: msg = "counted"; break;
default: msg = "?";
}
return std::string("value for property `" + pname + "' cannot be " + msg);
}
};
struct IndexValuesNotDefinedException: ReflectionException
{
2005-04-29 19:19:58 +08:00
IndexValuesNotDefinedException(const std::string& name, const std::string& iname)
2005-03-14 17:28:31 +08:00
: ReflectionException("couldn't determine a finite set of values for index `" + iname + "' of property `" + name + "'. Make sure that either: 1) the index is an enumeration, or 2) a valid custom indexing attribute was assigned to the property.")
{
}
};
2005-04-04 21:50:07 +08:00
struct ComparisonNotPermittedException: ReflectionException
{
2007-02-13 01:14:46 +08:00
ComparisonNotPermittedException(const ExtendedTypeInfo &ti)
2005-04-29 19:19:58 +08:00
: ReflectionException("comparison not permitted on type `" + std::string(ti.name()) + "'")
{
}
2005-04-04 21:50:07 +08:00
};
struct ComparisonOperatorNotSupportedException: ReflectionException
{
2007-02-13 01:14:46 +08:00
ComparisonOperatorNotSupportedException(const ExtendedTypeInfo &ti, const std::string& op)
2005-04-29 19:19:58 +08:00
: ReflectionException("comparison operator `" + op + "' is not supported on type `" + std::string(ti.name()) + "'")
{
}
2005-04-04 21:50:07 +08:00
};
2004-12-09 13:28:20 +08:00
}
#endif