Removed osgIntrospection as it's now available as a seperate osgIntrospection project that can be checked out thus:

svn co http://www.openscenegraph.org/svn/osg/osgIntrospection osgIntrospection
This commit is contained in:
Robert Osfield
2010-06-23 13:28:19 +00:00
parent 36366f61d5
commit 422a5e7058
499 changed files with 13 additions and 111818 deletions

View File

@@ -1,326 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_ATTRIBUTES_
#define OSGINTROSPECTION_ATTRIBUTES_
#include <osgIntrospection/CustomAttribute>
#include <osgIntrospection/Value>
#include <osgIntrospection/Exceptions>
#include <osgIntrospection/Type>
namespace osgIntrospection
{
/// By adding this attribute to a PropertyInfo you specify that there
/// is no default value for that property.
class NoDefaultValueAttribute: public CustomAttribute {};
/// By adding this attribute to a PropertyInfo you specify a custom
/// default value for that property.
class DefaultValueAttribute: public CustomAttribute
{
public:
DefaultValueAttribute(const Value& v): _v(v) {}
const Value& getDefaultValue() const { return _v; }
private:
Value _v;
};
/// Base struct for custom property getters. Descendants may override
/// one or more of the get() methods to provide the means for retrieving
/// the value of a property. The first version of get() is used with
/// indexed properties, the second one serves simple properties and the
/// last one is used with array properties.
struct PropertyGetter
{
virtual Value get(Value& /*instance*/, const ValueList& /*indices*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::IGET); }
virtual Value get(Value& /*instance*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::GET); }
virtual Value get(Value& /*instance*/, int /*i*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::AGET); }
virtual Value get(const Value& /*instance*/, const ValueList& /*indices*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::IGET); }
virtual Value get(const Value& /*instance*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::GET); }
virtual Value get(const Value& /*instance*/, int /*i*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::AGET); }
virtual ~PropertyGetter() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to retrieve the value of a property instead of the
/// default getter method.
class CustomPropertyGetAttribute: public CustomAttribute
{
public:
CustomPropertyGetAttribute(const PropertyGetter* getter)
: CustomAttribute(), _getter(getter) {}
const PropertyGetter* getGetter() const { return _getter; }
~CustomPropertyGetAttribute()
{
delete _getter;
}
private:
const PropertyGetter* _getter;
};
/// Base struct for custom property setters. Descendants may override
/// one or more of the set() methods to provide the means for setting
/// the value of a property. The first version of set() is used with
/// indexed properties, the second one serves simple properties and the
/// last one is used with array properties.
struct PropertySetter
{
virtual void set(Value& /*instance*/, ValueList& /*indices*/, const Value& /*value*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::ISET); }
virtual void set(Value& /*instance*/, const Value& /*value*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::SET); }
virtual void set(Value& /*instance*/, int /*i*/, const Value& /*value*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::ASET); }
virtual ~PropertySetter() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to set the value of a property instead of the
/// default setter method.
class CustomPropertySetAttribute: public CustomAttribute
{
public:
CustomPropertySetAttribute(const PropertySetter* setter)
: CustomAttribute(), _setter(setter) {}
const PropertySetter* getSetter() const { return _setter; }
~CustomPropertySetAttribute()
{
delete _setter;
}
private:
const PropertySetter* _setter;
};
/// Base struct for custom array property counters. Descendants should
/// override the count() method which must return the number of items
/// in a chosen array property for the given instance.
struct PropertyCounter
{
virtual int count(const Value& /*instance*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::COUNT); }
virtual ~PropertyCounter() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to count the number of items in an array property.
class CustomPropertyCountAttribute: public CustomAttribute
{
public:
CustomPropertyCountAttribute(const PropertyCounter* counter)
: CustomAttribute(), _counter(counter) {}
const PropertyCounter* getCounter() const { return _counter; }
~CustomPropertyCountAttribute()
{
delete _counter;
}
private:
const PropertyCounter* _counter;
};
/// Base struct for custom array property adders. Descendants should
/// override the add() method whose purpose is to add a new item to
/// an array property.
struct PropertyAdder
{
virtual void add(Value&, const Value&) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::ADD); }
virtual ~PropertyAdder() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to add a new item to an array property.
class CustomPropertyAddAttribute: public CustomAttribute
{
public:
CustomPropertyAddAttribute(const PropertyAdder* adder)
: CustomAttribute(), _adder(adder) {}
const PropertyAdder* getAdder() const { return _adder; }
~CustomPropertyAddAttribute()
{
delete _adder;
}
private:
const PropertyAdder* _adder;
};
/// Base struct for custom array property inserters. Descendants should
/// override the insert() method whose purpose is to insert a new item to
/// an array property.
struct PropertyInserter
{
virtual void insert(Value&, int, const Value&) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::INSERT); }
virtual void insert(Value&, const ValueList&, const Value&) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::INSERT); }
virtual ~PropertyInserter() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to insert a new item to an array property.
class CustomPropertyInsertAttribute: public CustomAttribute
{
public:
CustomPropertyInsertAttribute(const PropertyInserter* inserter)
: CustomAttribute(), _inserter(inserter) {}
const PropertyInserter* getInserter() const { return _inserter; }
~CustomPropertyInsertAttribute()
{
delete _inserter;
}
private:
const PropertyInserter* _inserter;
};
/// Base struct for custom array property removers. Descendants should
/// override the remove() method whose purpose is to remove an item from
/// an array property.
struct PropertyRemover
{
virtual void remove(Value&, int) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::REMOVE); }
virtual void remove(Value&, ValueList&) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::REMOVE); }
virtual ~PropertyRemover() {}
};
/// By setting an attribute of this class you can specify a custom object
/// that will be used to remove an item from an array property.
class CustomPropertyRemoveAttribute: public CustomAttribute
{
public:
CustomPropertyRemoveAttribute(const PropertyRemover* remover)
: CustomAttribute(), _remover(remover) {}
const PropertyRemover* getRemover() const { return _remover; }
~CustomPropertyRemoveAttribute()
{
delete _remover;
}
private:
const PropertyRemover* _remover;
};
/// This struct allows customization of an indexed property's index set.
/// You must derive from this struct and provide a concrete implementation
/// of getIndexValueSet(), which must return (in parameter values) a list
/// of valid values to be used as indices. The whichindex parameter
/// specifies which index is being queried (0 = first index, 1 = second
/// index, ...).
/// See CustomIndexAttribute for details.
struct IndexInfo
{
virtual const ParameterInfoList& getIndexParameters() const = 0;
virtual void getIndexValueSet(int whichindex, const Value& instance, ValueList& values) const = 0;
virtual ~IndexInfo() {}
};
/// By default each index in an indexed property is assumed to be an
/// enumeration. When serialization is performed, indices are chosen
/// from the set of enum labels that were defined for the index type.
/// With this attribute you can provide custom code to determine the
/// set of values to be used as indices, instead of the default enum
/// values. This attribute is required, for example, when the number
/// and/or value of indices is not constant over time (such as in
/// associative containers).
class CustomIndexAttribute: public CustomAttribute
{
public:
CustomIndexAttribute(const IndexInfo* ii)
: CustomAttribute(), _ii(ii) {}
const IndexInfo* getIndexInfo() const
{
return _ii;
}
~CustomIndexAttribute()
{
delete _ii;
}
private:
const IndexInfo* _ii;
};
/// Attribute for overriding the type of a property with a custom
/// type. If you add this attribute to a PropertyInfo object, then
/// all subsequent calls to getValue()/getArrayItem()/getIndexedValue()
/// will perform a conversion from the actual property's type to
/// the custom type specified through this attribute. Similarly, all
/// methods in PropertyInfo that alter the property's value will accept
/// a value of the custom type instead of the actual type. In this
/// case the conversion is implicit and occurs later within the accessor
/// methods.
class PropertyTypeAttribute: public CustomAttribute
{
public:
PropertyTypeAttribute(const Type& type)
: CustomAttribute(), _type(type) {}
const Type& getPropertyType() const
{
return _type;
}
private:
const Type& _type;
PropertyTypeAttribute& operator = (const PropertyTypeAttribute&) { return *this; }
};
/// Attribute for overriding the type of an index (of an indexed
/// property) with a custom type. Behaves like PropertyTypeAttribute,
/// but it affects the value of an index instead of the property's
/// value itself.
/// NOTE: property with custom indexing attributes are not affected
/// by this attribute!
class IndexTypeAttribute: public CustomAttribute
{
public:
IndexTypeAttribute(int whichindex, const Type& type)
: CustomAttribute(), _wi(whichindex), _type(type) {}
int getWhichIndex() const
{
return _wi;
}
const Type& getIndexType() const
{
return _type;
}
private:
IndexTypeAttribute& operator = (const IndexTypeAttribute&) { return *this; }
int _wi;
const Type& _type;
};
}
#endif

View File

@@ -1,67 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_COMPARATOR_
#define OSGINTROSPECTION_COMPARATOR_
namespace osgIntrospection
{
class Value;
struct Comparator
{
virtual bool isEqualTo(const Value& l, const Value& r) const = 0;
virtual bool isLessThanOrEqualTo(const Value& l, const Value& r) const = 0;
virtual ~Comparator() {}
};
template<typename T>
struct TotalOrderComparator: Comparator
{
virtual bool isEqualTo(const Value& l, const Value& r) const
{
const T &vl = variant_cast<const T &>(l);
const T &vr = variant_cast<const T &>(r);
return vl <= vr && vr <= vl;
}
virtual bool isLessThanOrEqualTo(const Value& l, const Value& r) const
{
return variant_cast<const T &>(l) <= variant_cast<const T &>(r);
}
virtual ~TotalOrderComparator() {}
};
template<typename T>
struct PartialOrderComparator: Comparator
{
virtual bool isEqualTo(const Value& l, const Value& r) const
{
return variant_cast<const T &>(l) == variant_cast<const T &>(r);
}
virtual bool isLessThanOrEqualTo(const Value& , const Value& ) const
{
throw ComparisonOperatorNotSupportedException(extended_typeid<T>(), "less than or equal to");
}
virtual ~PartialOrderComparator() {}
};
}
#endif

View File

@@ -1,108 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_CONSTRUCTORINFO_
#define OSGINTROSPECTION_CONSTRUCTORINFO_
#include <osgIntrospection/Export>
#include <osgIntrospection/Type>
#include <osgIntrospection/ParameterInfo>
#include <osgIntrospection/CustomAttributeProvider>
namespace osgIntrospection
{
class OSGINTROSPECTION_EXPORT ConstructorInfo: public CustomAttributeProvider
{
public:
// Standard constructor.
ConstructorInfo(const Type& declaratiionType, const ParameterInfoList& params, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: _declarationType(declaratiionType),
_params(params),
_explicit(false),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
}
// Constructor allowing explicit state specification.
ConstructorInfo(const Type& declaratiionType, const ParameterInfoList& params, bool isExplicit, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: _declarationType(declaratiionType),
_params(params),
_explicit(isExplicit),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
}
virtual ~ConstructorInfo()
{
for (ParameterInfoList::iterator i=_params.begin(); i!=_params.end(); ++i)
delete *i;
}
/// Returns the brief help of the reflected construtor.
inline virtual const std::string& getBriefHelp() const
{
return _briefHelp;
}
/// Returns the detailed help of the reflected contructor.
inline virtual const std::string& getDetailedHelp() const
{
return _detailedHelp;
}
/// Returns the Type object associated to the type that
/// declares the reflected constructor.
inline const Type& getDeclaringType() const
{
return _declarationType;
}
/// Returns a list of objects that describe the reflected
/// constructor's parameters.
inline const ParameterInfoList& getParameters() const
{
return _params;
}
/// Returns true if this constructor is explicit.
inline bool isExplicit() const
{
return _explicit;
}
/// Invokes the reflected constructor dynamically passing it the
/// arguments as a list of Value objects.
virtual Value createInstance(ValueList& args) const = 0;
protected:
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
private:
ConstructorInfo& operator = (const ConstructorInfo&) { return *this; }
const Type& _declarationType;
ParameterInfoList _params;
bool _explicit;
std::string _briefHelp;
std::string _detailedHelp;
};
}
#endif

View File

@@ -1,91 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_CONVERTER_
#define OSGINTROSPECTION_CONVERTER_
#include <osgIntrospection/Value>
#include <list>
namespace osgIntrospection
{
struct Converter
{
virtual CastType getCastType() const = 0;
virtual Value convert(const Value& ) const = 0;
virtual ~Converter() {}
};
typedef std::list<const Converter* > ConverterList;
class CompositeConverter: public Converter
{
public:
CompositeConverter(const ConverterList& cvt): cvt_(cvt) {}
CompositeConverter(ConverterList& cvt) { cvt_.swap(cvt); }
virtual ~CompositeConverter() {}
virtual Value convert(const Value& src) const
{
Value accum(src);
for (ConverterList::const_iterator i=cvt_.begin(); i!=cvt_.end(); ++i)
accum = (*i)->convert(accum);
return accum;
}
virtual CastType getCastType() const { return COMPOSITE_CAST; }
private:
ConverterList cvt_;
};
template<typename S, typename D>
struct StaticConverter: Converter
{
virtual ~StaticConverter() {}
virtual Value convert(const Value& src) const
{
return static_cast<D>(variant_cast<S>(src));
}
virtual CastType getCastType() const { return STATIC_CAST; }
};
template<typename S, typename D>
struct DynamicConverter: Converter
{
virtual ~DynamicConverter() {}
virtual Value convert(const Value& src) const
{
return dynamic_cast<D>(variant_cast<S>(src));
}
virtual CastType getCastType() const { return DYNAMIC_CAST; }
};
template<typename S, typename D>
struct ReinterpretConverter: Converter
{
virtual ~ReinterpretConverter() {}
virtual Value convert(const Value& src) const
{
return reinterpret_cast<D>(variant_cast<S>(src));
}
virtual CastType getCastType() const { return REINTERPRET_CAST; }
};
}
#endif

View File

@@ -1,36 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_CONVERTERPROXY_
#define OSGINTROSPECTION_CONVERTERPROXY_
#include <osgIntrospection/Reflection>
namespace osgIntrospection
{
struct Converter;
struct ConverterProxy
{
ConverterProxy(const Type& source, const Type& dest, const Converter* cvt)
{
Reflection::registerConverter(source, dest, cvt);
}
};
}
#endif

View File

@@ -1,31 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_CUSTOMATTRIBUTE_
#define OSGINTROSPECTION_CUSTOMATTRIBUTE_
namespace osgIntrospection
{
/// The base class for custom attributes. This is an empty class
/// for now.
class CustomAttribute
{
public:
virtual ~CustomAttribute() {}
};
}
#endif

View File

@@ -1,130 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_CUSTOMATTRIBUTEPROVIDER_
#define OSGINTROSPECTION_CUSTOMATTRIBUTEPROVIDER_
#include <osgIntrospection/Export>
#include <osgIntrospection/CustomAttribute>
#include <vector>
#include <typeinfo>
namespace osgIntrospection
{
// forward declarations
class Type;
class CustomAttribute;
class CustomAttributeProvider;
// vector of attributes
typedef std::vector<const CustomAttribute* > CustomAttributeList;
// vector of attribute providers
typedef std::vector<const CustomAttributeProvider *> CustomAttributeProviderList;
/// This is the base class for custom attribute providers, that is objects
/// that can be assigned a list of custom attributes. Methods defined in
/// this class provide the means for adding, retrieving and searching for
/// attributes.
class OSGINTROSPECTION_EXPORT CustomAttributeProvider
{
public:
/// Returns the const list of custom attributes.
inline const CustomAttributeList& getCustomAttributes() const
{
return attribs_;
}
/// Returns the list of custom attributes.
inline CustomAttributeList& getCustomAttributes()
{
return attribs_;
}
/// Adds a new attribute to the list.
inline CustomAttributeProvider *addAttribute(const CustomAttribute* attr)
{
attribs_.push_back(attr);
return this;
}
/// Returns whether at least one attribute of the given type is
/// present in the attribute list. If the inherit parameter is
/// set to true, the search is forwarded to base types.
bool isDefined(const Type& type, bool inherit) const;
/// Returns whether at least one attribute of the given type is
/// present in the attribute list. If the inherit parameter is
/// set to true, the search is forwarded to base types.
/// [template version]
template<typename T> inline bool isDefined(bool inherit) const
{
for (CustomAttributeList::const_iterator i=attribs_.begin(); i!=attribs_.end(); ++i)
if (typeid(**i) == typeid(T)) return true;
if (inherit)
{
CustomAttributeProviderList providers;
getInheritedProviders(providers);
for (CustomAttributeProviderList::const_iterator i=providers.begin(); i!=providers.end(); ++i)
{
if ((*i)->isDefined<T>(true)) return true;
}
}
return false;
}
/// Searchs for an attribute of the given type and returns a pointer
/// to it if found, a null pointer otherwise. If the inherit parameter
/// is set to true, the search is forwarded to base types.
const CustomAttribute* getAttribute(const Type& type, bool inherit) const;
/// Searchs for an attribute of the given type and returns a pointer
/// to it if found, a null pointer otherwise. If the inherit parameter
/// is set to true, the search is forwarded to base types.
/// [template version]
template<typename T> inline const T *getAttribute(bool inherit) const
{
for (CustomAttributeList::const_iterator i=attribs_.begin(); i!=attribs_.end(); ++i)
if (typeid(**i) == typeid(T)) return static_cast<const T *>(*i);
if (inherit)
{
CustomAttributeProviderList providers;
getInheritedProviders(providers);
for (CustomAttributeProviderList::const_iterator i=providers.begin(); i!=providers.end(); ++i)
{
const T *ca = (*i)->getAttribute<T>(true);
if (ca) return ca;
}
}
return 0;
}
protected:
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const = 0;
virtual ~CustomAttributeProvider() {
for(CustomAttributeList::iterator it = attribs_.begin(); it != attribs_.end(); ++it) {
delete (*it);
}
}
private:
CustomAttributeList attribs_;
};
}
#endif

View File

@@ -1,255 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_EXCEPTIONS_
#define OSGINTROSPECTION_EXCEPTIONS_
#include <string>
#include <osgIntrospection/ExtendedTypeInfo>
namespace osgIntrospection
{
class Exception
{
public:
Exception(const std::string& msg): msg_(msg) {}
const std::string& what() const throw() { return msg_; }
private:
std::string msg_;
};
struct ReflectionException: public Exception
{
ReflectionException(const std::string& msg): Exception(msg) {}
};
struct TypeNotDefinedException: public ReflectionException
{
TypeNotDefinedException(const ExtendedTypeInfo &ti)
: ReflectionException("type `" + std::string(ti.name()) + "' is declared but not defined")
{
}
};
struct TypeIsAbstractException: public ReflectionException
{
TypeIsAbstractException(const ExtendedTypeInfo &ti)
: ReflectionException("cannot create instances of abstract type `" + std::string(ti.name()) + "'")
{
}
};
struct ConstructorNotFoundException: public ReflectionException
{
ConstructorNotFoundException(const ExtendedTypeInfo &ti)
: ReflectionException("could not find a suitable constructor in type `" + std::string(ti.name()) + "'")
{
}
};
struct ProtectedConstructorInvocationException: public ReflectionException
{
ProtectedConstructorInvocationException()
: ReflectionException("cannot invoke protected constructor")
{
}
};
struct InvokeNotImplementedException: public ReflectionException
{
InvokeNotImplementedException()
: ReflectionException("invoke() not implemented")
{
}
};
struct InvalidFunctionPointerException: public ReflectionException
{
InvalidFunctionPointerException()
: ReflectionException("invalid function pointer during invoke()")
{
}
};
struct ConstIsConstException: public ReflectionException
{
ConstIsConstException()
: ReflectionException("cannot modify a const value")
{
}
};
struct ProtectedMethodInvocationException: public ReflectionException
{
ProtectedMethodInvocationException()
: ReflectionException("cannot invoke protected method")
{
}
};
struct EmptyValueException: public ReflectionException
{
EmptyValueException()
: ReflectionException("cannot retrieve an empty value")
{
}
};
struct TypeNotFoundException: public ReflectionException
{
TypeNotFoundException(const std::string& qname)
: ReflectionException("type `" + qname + "' not found")
{
}
};
struct MethodNotFoundException: public ReflectionException
{
MethodNotFoundException(const std::string& name, const std::string& cname)
: 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
};
StreamingNotSupportedException(OperationType op, const ExtendedTypeInfo &type)
: ReflectionException(build_msg(op, type))
{
}
private:
std::string build_msg(OperationType op, const ExtendedTypeInfo &type)
{
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
{
TypeConversionException(const ExtendedTypeInfo &type1, const ExtendedTypeInfo &type2)
: 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,
INSERT,
REMOVE,
COUNT
};
PropertyAccessException(const std::string& pname, AccessType denied)
: ReflectionException(build_msg(pname, denied))
{
}
private:
std::string build_msg(const std::string& pname, AccessType denied) const
{
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;
case INSERT: msg = "inserted"; break;
case REMOVE: msg = "removed"; break;
case COUNT: msg = "counted"; break;
default: msg = "?";
}
return std::string("value for property `" + pname + "' cannot be " + msg);
}
};
struct IndexValuesNotDefinedException: ReflectionException
{
IndexValuesNotDefinedException(const std::string& name, const std::string& iname)
: 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.")
{
}
};
struct ComparisonNotPermittedException: ReflectionException
{
ComparisonNotPermittedException(const ExtendedTypeInfo &ti)
: ReflectionException("comparison not permitted on type `" + std::string(ti.name()) + "'")
{
}
};
struct ComparisonOperatorNotSupportedException: ReflectionException
{
ComparisonOperatorNotSupportedException(const ExtendedTypeInfo &ti, const std::string& op)
: ReflectionException("comparison operator `" + op + "' is not supported on type `" + std::string(ti.name()) + "'")
{
}
};
}
#endif

View File

@@ -1,71 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_EXPORTHDR
#define OSGINTROSPECTION_EXPORTHDR 1
#include <osg/Config>
#if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS)
#pragma warning( disable : 4251 )
#pragma warning( disable : 4121 )
#pragma warning( disable : 4180 )
#pragma warning( disable : 4702 )
#endif
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSG_LIBRARY_STATIC )
# define OSGINTROSPECTION_EXPORT
# elif defined( OSGINTROSPECTION_LIBRARY )
# define OSGINTROSPECTION_EXPORT __declspec(dllexport)
# else
# define OSGINTROSPECTION_EXPORT __declspec(dllimport)
# endif
#else
# define OSGINTROSPECTION_EXPORT
#endif
// set up define for whether member templates are supported by VisualStudio compilers.
#ifdef _MSC_VER
# if (_MSC_VER < 1300)
# error Your compiler doesn't support member templates. The reflection framework can't be compiled.
# endif
#endif
/**
\namespace osgIntrospection
The osgIntrospection library provides the an introspection/reflection framework for non intrusive
run-time querying and calling of class properties and methods.
osgIntrospection is ideal for providing non native language binding to the OpenSceneGraph, convenient means
for editing properties in a generic way, such as required in scene graph editors,
and also facilitates the automatic serealization of objects.
osgIntrospection can be used to provide introspection support to 3rd Party libraries without the need to
modify them to add this support, the wrappers providing the actual binding can be
automatically generated by parsing header files via gen_wrapper utility. All the
core OpenSceneGraph libraries have pre built wrappers available for you use.
*/
/**
\namespace Properties
Properties is a set of helper definations used by the osgIntrospectoin wrappers.
*/
#endif

View File

@@ -1,123 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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.
*/
#ifndef OSGINTROSPECTION_EXTENDEDTYPEINFO_
#define OSGINTROSPECTION_EXTENDEDTYPEINFO_
#include <typeinfo>
#include <string>
#include <osgIntrospection/type_traits>
namespace osgIntrospection
{
/// This class is a wrapper for std::type_info that also records whether
/// a type is a reference or const reference. It permits osgIntrospection
/// to make use of reference information that is ignored by typeid(), and
/// to generate reference types based on it. The ExtendedTypeInfo for a
/// class can be produced via the extended_typeid() functions, analogous
/// to typeid().
///
class ExtendedTypeInfo
{
public:
ExtendedTypeInfo(const std::type_info &ti, bool isReference, bool isConstReference) :
_ti(&ti), _is_reference(isReference), _is_const_reference(isConstReference)
{
}
/// Orders ExtendedTypeInfo based first on std::type_info, then on
/// reference, then on const reference. Note that we can't rely on
/// default pointer comparison for std::type_info because it is not
/// guaranteed that &typeid(T) always returns the same pointer for a
/// given T (thanks Andrew Koenig).
bool operator<(const ExtendedTypeInfo &other) const
{
if (_ti->before(*other._ti))
return true;
else if (other._ti->before(*_ti))
return false;
else if (_is_reference < other._is_reference)
return true;
else if (other._is_reference < _is_reference)
return false;
else
return _is_const_reference < other._is_const_reference;
}
/// Returns true if *this and other are the same type.
bool operator==(const ExtendedTypeInfo &other) const
{
return (*_ti == *other._ti &&
_is_reference == other._is_reference &&
_is_const_reference == other._is_const_reference);
}
/// Gets the std::type_info object for this type.
const std::type_info &getStdTypeInfo() const
{
return *_ti;
}
/// Returns true if this type is a reference or const reference.
bool isReference() const
{
return _is_reference;
}
/// Returns true if this type is a const reference.
bool isConstReference() const
{
return _is_const_reference;
}
/// Returns the name of this type, based on the std::type_info name.
std::string name() const
{
if (_is_const_reference)
return std::string("const ") + _ti->name() + " &";
else if (_is_reference)
return std::string(_ti->name()) + " &";
else
return _ti->name();
}
private:
const std::type_info *_ti;
bool _is_reference;
bool _is_const_reference;
};
}
/// extended_typeid works like typeid, but returns an ExtendedTypeInfo. This
/// version operates on expressions.
template <typename T>
osgIntrospection::ExtendedTypeInfo
extended_typeid(T)
{
return osgIntrospection::ExtendedTypeInfo(typeid(T),
is_reference<T>::value,
is_const_reference<T>::value);
}
/// extended_typeid works like typeid, but returns an ExtendedTypeInfo. This
/// version operates on types, which must be specified as a template parameter.
template <typename T>
osgIntrospection::ExtendedTypeInfo
extended_typeid()
{
return osgIntrospection::ExtendedTypeInfo(typeid(T),
is_reference<T>::value,
is_const_reference<T>::value);
}
#endif

View File

@@ -1,454 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_INSTANCECREATOR_
#define OSGINTROSPECTION_INSTANCECREATOR_
#include <osgIntrospection/Value>
#include <osgIntrospection/variant_cast>
namespace osgIntrospection
{
/// The ObjectInstanceCreator struct template is a collection of
/// static methods that provide the means for creating instances
/// of object types dynamically. Such methods are usually called
/// from within TypedConstructorInfo{n}::createInstance().
template<typename T>
struct ObjectInstanceCreator
{
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13, Value& a14, Value& a15)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13), variant_cast<P14>(a14), variant_cast<P15>(a15));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13, Value& a14)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13), variant_cast<P14>(a14));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4));
}
template<typename P0, typename P1, typename P2, typename P3>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3));
}
template<typename P0, typename P1, typename P2>
static Value create(Value& a0, Value& a1, Value& a2)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2));
}
template<typename P0, typename P1>
static Value create(Value& a0, Value& a1)
{
return new T(variant_cast<P0>(a0), variant_cast<P1>(a1));
}
template<typename P0>
static Value create(Value& a0)
{
return new T(variant_cast<P0>(a0));
}
static Value create()
{
return new T();
}
};
template<typename T>
struct ValueInstanceCreator
{
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13, Value& a14, Value& a15)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13), variant_cast<P14>(a14), variant_cast<P15>(a15));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13, Value& a14)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13), variant_cast<P14>(a14));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12, Value& a13)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12), variant_cast<P13>(a13));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11, Value& a12)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11), variant_cast<P12>(a12));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10, Value& a11)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10), variant_cast<P11>(a11));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9, Value& a10)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9), variant_cast<P10>(a10));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8, Value& a9)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8), variant_cast<P9>(a9));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7, Value& a8)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7), variant_cast<P8>(a8));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6, Value& a7)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6), variant_cast<P7>(a7));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5, Value& a6)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5), variant_cast<P6>(a6));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4, Value& a5)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4), variant_cast<P5>(a5));
}
template<typename P0, typename P1, typename P2, typename P3, typename P4>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3, Value& a4)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3), variant_cast<P4>(a4));
}
template<typename P0, typename P1, typename P2, typename P3>
static Value create(Value& a0, Value& a1, Value& a2, Value& a3)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2), variant_cast<P3>(a3));
}
template<typename P0, typename P1, typename P2>
static Value create(Value& a0, Value& a1, Value& a2)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1), variant_cast<P2>(a2));
}
template<typename P0, typename P1>
static Value create(Value& a0, Value& a1)
{
return T(variant_cast<P0>(a0), variant_cast<P1>(a1));
}
template<typename P0>
static Value create(Value& a0)
{
return T(variant_cast<P0>(a0));
}
static Value create()
{
return T();
}
};
template<typename T>
struct DummyInstanceCreator
{
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4>
static Value create(Value& , Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2, typename P3>
static Value create(Value& , Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1, typename P2>
static Value create(Value& , Value& , Value& )
{
return Value();
}
template<typename P0, typename P1>
static Value create(Value& , Value& )
{
return Value();
}
template<typename P0>
static Value create(Value& )
{
return Value();
}
static Value create()
{
return Value();
}
};
template<typename T>
struct ProtectedConstructorInstanceCreator
{
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
static Value create(Value& , Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3, typename P4>
static Value create(Value& , Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2, typename P3>
static Value create(Value& , Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1, typename P2>
static Value create(Value& , Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0, typename P1>
static Value create(Value& , Value& )
{
throw ProtectedConstructorInvocationException();
}
template<typename P0>
static Value create(Value& )
{
throw ProtectedConstructorInvocationException();
}
static Value create()
{
throw ProtectedConstructorInvocationException();
}
};
}
#endif

View File

@@ -1,249 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_METHODINFO_
#define OSGINTROSPECTION_METHODINFO_
#include <osgIntrospection/Export>
#include <osgIntrospection/CustomAttributeProvider>
#include <osgIntrospection/Value>
#include <osgIntrospection/Exceptions>
#include <osgIntrospection/ParameterInfo>
#include <cstdarg>
#include <string>
#include <vector>
namespace osgIntrospection
{
class Type;
/// Class MethodInfo stores information about a class method. It is an
/// abstract class, so it must be derived to provide the actual
/// implementation of isConst() and invoke(). Instances of this class
/// can't be modified after their creation.
class OSGINTROSPECTION_EXPORT MethodInfo: public CustomAttributeProvider
{
public:
/// Possible virtual states of the function.
enum VirtualState
{
NON_VIRTUAL = 0x0,
VIRTUAL = 0x1,
PURE_VIRTUAL = 0x3
};
/// Direct initialization constructor.
inline MethodInfo(const std::string& qname, const Type& declarationType, const Type& rtype, const ParameterInfoList& plist, VirtualState virtualState, std::string briefHelp = std::string(), std::string detailedHelp = std::string());
/// Direct initialization constructor for static functions (no virtual specifier).
inline MethodInfo(const std::string& qname, const Type& declarationType, const Type& rtype, const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string());
/// Destructor
inline ~MethodInfo();
/// Returns the Type object associated to the type that
/// declares the reflected method.
inline virtual const Type& getDeclaringType() const;
/// Returns the name of the reflected method.
inline virtual const std::string& getName() const;
/// Returns the return type of the reflected method.
inline const Type& getReturnType() const;
/// Returns a list of objects that describe the reflected
/// method's parameters.
inline const ParameterInfoList& getParameters() const;
/// Returns the brief help of the reflected method.
inline virtual const std::string& getBriefHelp() const;
/// Returns the detailed help of the reflected method.
inline virtual const std::string& getDetailedHelp() const;
/// Returns whether the reflected method is const or not.
virtual bool isConst() const = 0;
/// Returns whether the reflected method is static or not.
virtual bool isStatic() const = 0;
/// Returns whether the reflected method is virtual or not.
virtual bool isVirtual() const;
/// Returns whether the reflected method is pure virtual or not.
virtual bool isPureVirtual() const;
/// Returns whether this method would override the given
/// method.
bool overrides(const MethodInfo* other) const;
/// Invokes the reflected method dynamically on the given const
/// instance, passing it the arguments as a list of Value objects.
inline virtual Value invoke(const Value& instance, ValueList& args) const;
/// Invokes the reflected method dynamically on the given instance,
/// passing it the arguments as a list of Value objects.
inline virtual Value invoke(Value& instance, ValueList& args) const;
/// Invokes the reflected static method dynamically passing it the
/// arguments as a list of Value objects.
inline virtual Value invoke(ValueList& args) const;
/// Invokes the reflected method dynamically on the given const
/// instance, without arguments.
inline Value invoke(const Value& instance) const;
/// Invokes the reflected method dynamically on the given
/// instance, without arguments.
inline Value invoke(Value& instance) const;
/// Invokes the reflected static method without arguments.
inline Value invoke() const;
private:
MethodInfo& operator = (const MethodInfo&) { return *this; }
inline std::string strip_namespace(const std::string& s) const;
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
std::string _name;
const Type& _declarationType;
const Type& _rtype;
ParameterInfoList _params;
VirtualState _virtualState;
std::string _briefHelp;
std::string _detailedHelp;
};
// INLINE METHODS
inline MethodInfo::MethodInfo(const std::string& qname, const Type& declarationType, const Type& rtype, const ParameterInfoList& plist, VirtualState virtualState, std::string briefHelp, std::string detailedHelp)
: CustomAttributeProvider(),
_declarationType(declarationType),
_rtype(rtype),
_params(plist),
_virtualState(virtualState),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
_name = strip_namespace(qname);
}
inline MethodInfo::MethodInfo(const std::string& qname, const Type& declarationType, const Type& rtype, const ParameterInfoList& plist, std::string briefHelp, std::string detailedHelp)
: CustomAttributeProvider(),
_declarationType(declarationType),
_rtype(rtype),
_params(plist),
_virtualState(NON_VIRTUAL),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
_name = strip_namespace(qname);
}
inline std::string MethodInfo::strip_namespace(const std::string& s) const
{
std::string::size_type p = s.rfind("::");
if (p != std::string::npos)
return s.substr(p+2);
return s;
}
inline const std::string& MethodInfo::getName() const
{
return _name;
}
inline const Type& MethodInfo::getDeclaringType() const
{
return _declarationType;
}
inline const Type& MethodInfo::getReturnType() const
{
return _rtype;
}
inline const ParameterInfoList& MethodInfo::getParameters() const
{
return _params;
}
inline const std::string& MethodInfo::getBriefHelp() const
{
return _briefHelp;
}
inline const std::string& MethodInfo::getDetailedHelp() const
{
return _detailedHelp;
}
inline bool MethodInfo::isVirtual() const
{
return (_virtualState & VIRTUAL) == VIRTUAL;
}
inline bool MethodInfo::isPureVirtual() const
{
return (_virtualState & PURE_VIRTUAL) == PURE_VIRTUAL;
}
inline Value MethodInfo::invoke(const Value& , ValueList& ) const
{
throw InvokeNotImplementedException();
}
inline Value MethodInfo::invoke(Value& , ValueList& ) const
{
throw InvokeNotImplementedException();
}
inline Value MethodInfo::invoke(ValueList& ) const
{
throw InvokeNotImplementedException();
}
inline Value MethodInfo::invoke(const Value& instance) const
{
ValueList args;
return invoke(instance, args);
}
inline Value MethodInfo::invoke(Value& instance) const
{
ValueList args;
return invoke(instance, args);
}
inline Value MethodInfo::invoke() const
{
ValueList args;
return invoke(args);
}
inline MethodInfo::~MethodInfo()
{
for (ParameterInfoList::iterator i=_params.begin(); i!=_params.end(); ++i)
delete *i;
}
}
#endif

View File

@@ -1,112 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_PARAMETERINFO_
#define OSGINTROSPECTION_PARAMETERINFO_
#include <osgIntrospection/Type>
#include <osgIntrospection/Value>
#include <string>
#include <vector>
namespace osgIntrospection
{
/// This class stores information about a function parameter. A parameter
/// is defined by its name, its type, its position within the parameter
/// list, and zero or more attributes. Attributes describe how the
/// parameter behave, for example whether it is an input or an output
/// parameter.
class ParameterInfo
{
public:
enum ParameterAttributes
{
NONE = 0,
IN = 1, // parameter is used to pass data to the function
OUT = 2, // parameter is used to return data from the function
INOUT = IN | OUT
};
/// Direct initialization constructor.
inline ParameterInfo(const std::string& name, const Type& type, int attribs, const Value& defval = Value());
/// Returns the parameter's name.
inline const std::string& getName() const;
/// Returns the parameter's type.
inline const Type& getParameterType() const;
/// Returns the parameter's attributes.
inline int getAttributes() const;
/// Returns the default value.
inline const Value& getDefaultValue() const;
/// Returns whether the parameter has the IN attribute.
inline bool isIn() const { return (attribs_ & IN) != 0; }
/// Returns whether the parameter has the OUT attribute.
inline bool isOut() const { return (attribs_ & OUT) != 0; }
/// Returns whether the parameter has both the IN and the
/// OUT attribute.
inline bool isInOut() const { return isIn() && isOut(); }
private:
ParameterInfo& operator = (const ParameterInfo&) { return *this; }
std::string _name;
const Type& _type;
int attribs_;
Value default_;
};
// INLINE METHODS
inline ParameterInfo::ParameterInfo(const std::string& name, const Type& type, int attribs, const Value& defval)
: _name(name),
_type(type),
attribs_(attribs),
default_(defval)
{
}
inline const std::string& ParameterInfo::getName() const
{
return _name;
}
inline const Type& ParameterInfo::getParameterType() const
{
return _type;
}
inline int ParameterInfo::getAttributes() const
{
return attribs_;
}
inline const Value& ParameterInfo::getDefaultValue() const
{
return default_;
}
}
#endif

View File

@@ -1,384 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_PROPERTYINFO_
#define OSGINTROSPECTION_PROPERTYINFO_
#include <osgIntrospection/Export>
#include <osgIntrospection/Type>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/Attributes>
#include <string>
#include <typeinfo>
#include <iosfwd>
#include <vector>
namespace osgIntrospection
{
/// This class keeps information about a class' property. A property is
/// defined by a name and a set of methods that store and retrieve
/// values. When the user wants to "get" the value of a property, the
/// getter method will be invoked and its value returned. When the user
/// wants to "set" the value of a property, the setter method will be
/// called. There are three kinds of property: simple (get/set), indexed
/// (get[i1, i2, ...]/set[i1, i2, ...]), and array (count/add/get[i]/
/// set[i]).
/// Objects of class PropertyInfo can't be modified once they have been
/// created, but they can be queried without restrictions. You can either
/// retrieve the accessor methods and invoke them manually, or you can
/// call getValue() / setValue() etc. methods to perform direct operations
/// on the property, given an instance of the declaring type to work on.
/// The latter technique is preferred because it checks for custom
/// attributes associated to the PropertyInfo object and passes control
/// to them when needed.
///
class OSGINTROSPECTION_EXPORT PropertyInfo: public CustomAttributeProvider
{
public:
/// Direct initialization constructor for simple properties.
/// You must pass the Type object associated to the class that
/// declares the property, the Type object that describes the
/// type of the property's value, the property name and the
/// getter/setter methods. Either the setter or the getter can
/// be null, meaning a restricted access. If both are null, the
/// user is expected to add a custom accessor attribute to this
/// PropertyInfo object.
PropertyInfo(const Type& declaratiionType, const Type& ptype, const std::string& name, const MethodInfo* getm, const MethodInfo* setm, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: CustomAttributeProvider(),
_declarationType(declaratiionType),
_ptype(ptype),
_name(name),
_getm(getm),
_setm(setm),
_numm(0),
_addm(0),
_insm(0),
_remm(0),
_is_array(false),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
}
/// Direct initialization constructor for "array" properties.
/// You must pass the Type object associated to the type that
/// declares the property, the Type object that describes the
/// type of the property's value, the property name and the
/// getter/setter/counter/adder/insert/remover methods.
PropertyInfo(const Type& declaratiionType, const Type& ptype, const std::string& name, const MethodInfo* getm, const MethodInfo* setm, const MethodInfo* numm, const MethodInfo* addm, const MethodInfo* insm, const MethodInfo* remm, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: CustomAttributeProvider(),
_declarationType(declaratiionType),
_ptype(ptype),
_name(name),
_getm(getm),
_setm(setm),
_numm(numm),
_addm(addm),
_insm(insm),
_remm(remm),
_is_array(true),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
}
/// Direct initialization constructor for indexed properties.
/// You must pass the Type object associated to the class that
/// declares the property, the Type object that describes the
/// type of the property's value, the property name and the
/// getter/setter methods. Either the setter or the getter can
/// be null, meaning a restricted access. If both are null, the
/// user is expected to add a custom accessor attribute to this
/// PropertyInfo object.
/// If the getter method has parameters, the property is considered
/// to be indexed. The same is true if the getter is null and the
/// setter has more than one parameter.
PropertyInfo(const Type& declaratiionType, const Type& ptype, const std::string& name, const MethodInfo* getm, const MethodInfo* setm, const MethodInfo* remm, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: CustomAttributeProvider(),
_declarationType(declaratiionType),
_ptype(ptype),
_name(name),
_getm(getm),
_setm(setm),
_numm(0),
_addm(0),
_insm(0),
_remm(remm),
_is_array(false),
_briefHelp(briefHelp),
_detailedHelp(detailedHelp)
{
if (_getm)
{
for (ParameterInfoList::size_type i=0; i<_getm->getParameters().size(); ++i)
_indices.push_back(_getm->getParameters().at(i));
}
else
{
if (_setm)
{
for (ParameterInfoList::size_type i=0; i<(_setm->getParameters().size()-1); ++i)
_indices.push_back(_setm->getParameters().at(i));
}
}
}
/// Returns the number of indices
inline int getNumIndices() const
{
return static_cast<int>(getIndexParameters().size());
}
/// Returns the name of the property being described.
inline virtual const std::string& getName() const
{
return _name;
}
/// Returns the brief help of the property being described.
inline virtual const std::string& getBriefHelp() const
{
return _briefHelp;
}
/// Returns the detailed help of the property being described.
inline virtual const std::string& getDetailedHelp() const
{
return _detailedHelp;
}
/// Returns the type that declares the property.
inline virtual const Type& getDeclaringType() const
{
return _declarationType;
}
/// Returns the type of the reflected property.
inline const Type& getPropertyType() const
{
const PropertyTypeAttribute *pta = getAttribute<PropertyTypeAttribute>(false);
if (pta) return pta->getPropertyType();
return _ptype;
}
/// Returns the getter method.
inline const MethodInfo* getGetMethod() const
{
return _getm;
}
/// Returns the setter method.
inline const MethodInfo* getSetMethod() const
{
return _setm;
}
/// Returns the counter method.
inline const MethodInfo* getCountMethod() const
{
return _numm;
}
/// Returns the adder method.
inline const MethodInfo* getAddMethod() const
{
return _addm;
}
/// Returns the insert method.
inline const MethodInfo* getInsertMethod() const
{
return _insm;
}
/// Returns the remover method.
inline const MethodInfo* getRemoveMethod() const
{
return _remm;
}
/// Returns whether the property's value can be retrieved.
inline bool canGet() const
{
return (_getm != 0) || isDefined<CustomPropertyGetAttribute>(false);
}
/// Returns whether the property's value can be set.
inline bool canSet() const
{
return _setm != 0 || isDefined<CustomPropertySetAttribute>(false);
}
/// Returns whether the property's array of values can be counted.
inline bool canCount() const
{
return _numm != 0 || isDefined<CustomPropertyCountAttribute>(false);
}
/// Returns whether items can be added to the array property.
inline bool canAdd() const
{
return _addm != 0 || isDefined<CustomPropertyAddAttribute>(false);
}
/// Returns whether items can be insert to the array property.
inline bool canInsert() const
{
return _insm != 0 || isDefined<CustomPropertyInsertAttribute>(false);
}
/// Returns whether items can be removed from the array property.
inline bool canRemove() const
{
return _remm != 0 || isDefined<CustomPropertyRemoveAttribute>(false);
}
/// Returns whether the property is simple.
inline bool isSimple() const
{
return !isIndexed() && !isArray();
}
/// Returns whether the property is indexed.
inline bool isIndexed() const
{
return getNumIndices() > 0;
}
/// Returns whether the property is an array.
inline bool isArray() const
{
return _is_array;
}
/// Returns the list of index parameters.
/// If the property is not indexed, this list is empty. If neither
/// the get method nor the set method are defined, this list is
/// empty unless a custom indexing attribute is defined.
const ParameterInfoList& getIndexParameters() const;
/// Returns a list of valid values that can be used for the specified
/// index. If a custom indexing attribute is defined for this property,
/// then it will be queried for the index set, otherwise the index
/// will be treated as an enumeration and the set of enumeration
/// values will be returned.
void getIndexValueSet(int whichindex, const Value& instance, ValueList& values) const;
/// Invokes the getter method on the given const instance and
/// returns the property's value. If a custom getter attribute
/// is defined, it will be invoked instead.
Value getValue(const Value& instance) const;
/// Invokes the getter method on the given instance and
/// returns the property's value. If a custom getter attribute
/// is defined, it will be invoked instead.
Value getValue(Value& instance) const;
/// Invokes the setter method on the given instance and
/// sets the property's value. If a custom setter attribute
/// is defined, it will be invoked instead.
void setValue(Value& instance, const Value& value) const;
/// Invokes the getter method on the given const instance passing a
/// list of indices and returns the indexed property's value. If a
/// custom getter attribute is defined, it will be invoked instead.
Value getIndexedValue(Value& instance, ValueList& indices) const;
/// Invokes the getter method on the given instance passing a list
/// of indices and returns the indexed property's value. If a custom
/// getter attribute is defined, it will be invoked instead.
Value getIndexedValue(const Value& instance, ValueList& indices) const;
/// Invokes the setter method on the given instance passing a list
/// of indices and sets the indexed property's value. If a custom
/// setter attribute is defined, it will be invoked instead.
void setIndexedValue(Value& instance, ValueList& indices, const Value& value) const;
/// Invokes the remover method on the given instance and removes
/// an item from the indexed property. If a custom remover attribute
/// is defined, it will be invoked instead.
void removeIndexedItem(Value& instance, ValueList& indices) const;
/// Invokes the counter method on the given instance and returns
/// the number of items of the array property. If a custom counter
/// attribute is defined, it will be invoked instead.
int getNumArrayItems(const Value& instance) const;
/// Invokes the getter method on the given const instance and returns
/// the i-th item of the array property. If a custom getter attribute
/// us defined, it will be invoked instead.
Value getArrayItem(const Value& instance, int i) const;
/// Invokes the getter method on the given instance and returns
/// the i-th item of the array property. If a custom getter attribute
/// us defined, it will be invoked instead.
Value getArrayItem(Value& instance, int i) const;
/// Invokes the setter method on the given instance and sets
/// the i-th item of the array property. If a custom setter attribute
/// is defined, it will be invoked instead.
void setArrayItem(Value& instance, int i, const Value& value) const;
/// Invokes the adder method on the given instance and adds
/// an item to the array property. If a custom adder attribute is
/// defined, it will be invoked instead.
void addArrayItem(Value& instance, const Value& value) const;
/// Invokes the insert method on the given instance and inserts
/// an item to the array property after the i-th item of the array
/// property. If a custom adder attribute is defined,
/// it will be invoked instead.
void insertArrayItem(Value& instance, int i, const Value& value) const;
/// Invokes the remover method on the given instance and removes
/// an item from the array property. If a custom remover attribute
/// is defined, it will be invoked instead.
void removeArrayItem(Value& instance, int i) const;
/// Returns the default value associated to the reflected property.
/// If no default value has been specified, this method tries to
/// create an instance of the property type and then returns its
/// value. There are some attributes that change the behavior of
/// this method, for example NoDefaultValueAttribute.
Value getDefaultValue() const;
virtual ~PropertyInfo() {};
protected:
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
private:
PropertyInfo& operator = (const PropertyInfo&) { return *this; }
const Type& _declarationType;
const Type& _ptype;
std::string _name;
const MethodInfo* _getm;
const MethodInfo* _setm;
const MethodInfo* _numm;
const MethodInfo* _addm;
const MethodInfo* _insm;
const MethodInfo* _remm;
ParameterInfoList _indices;
bool _is_array;
std::string _briefHelp;
std::string _detailedHelp;
};
}
#endif

View File

@@ -1,59 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* 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) 2006 David Callu
#ifndef OSGINTROSPECTION_PUBLICMEMBERACCESSOR_
#define OSGINTROSPECTION_PUBLICMEMBERACCESSOR_
#include <osgIntrospection/Export>
#include <osgIntrospection/Type>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/PropertyInfo>
#include <osgIntrospection/Attributes>
#include <string>
#include <typeinfo>
#include <iosfwd>
#include <vector>
namespace osgIntrospection
{
template < typename C, typename P >
struct PublicMemberAccessor: public PropertyGetter, public PropertySetter
{
typedef P C::*MemberType;
PublicMemberAccessor(MemberType m)
: _m(m)
{}
virtual Value get(Value& instance) const
{
return getInstance<C>(instance).*_m;
}
virtual Value get(const Value& instance) const
{
return getInstance<C>(instance).*_m;
}
virtual void set(Value& instance, const Value& v) const
{
getInstance<C>(instance).*_m = variant_cast<const P& >(v);
}
P C::*_m;
};
}
#endif

View File

@@ -1,276 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_READERWRITER_
#define OSGINTROSPECTION_READERWRITER_
#include <osgIntrospection/Value>
#include <osgIntrospection/Type>
#include <osgIntrospection/Exceptions>
#include <osgIntrospection/variant_cast>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/ref_ptr>
#include <iostream>
#include <sstream>
namespace osgIntrospection
{
/// This is the base class for reader/writer objects. A ReaderWriter's
/// purpose is to provide the means for writing the content of a Value
/// object to a stream and for reading it back. Descendants can either
/// be specialized for just one data type or they can handle several
/// types, that's up to the implementor. A derived class is not required
/// to support all streaming operations (text write, text read, bin write
/// and bin read), it can implement just some of them, although full
/// support is strongly encouraged.
class ReaderWriter
{
public:
class Options
{
public:
Options(): fno_(false) {}
virtual ~Options() {}
bool getForceNumericOutput() const { return fno_; }
void setForceNumericOutput(bool fno) { fno_ = fno; }
private:
bool fno_;
};
/// Writes a textual representation of the value's content to a stream.
virtual std::ostream &writeTextValue(std::ostream &, const Value& v, const Options* = 0) const { throw StreamingNotSupportedException(StreamingNotSupportedException::TEXT_WRITE, v.getType().getExtendedTypeInfo()); }
/// Reads a textual representation of the value's content from a stream.
virtual std::istream &readTextValue(std::istream &, Value& v, const Options* = 0) const { throw StreamingNotSupportedException(StreamingNotSupportedException::TEXT_READ, v.getType().getExtendedTypeInfo()); }
/// Writes a textual representation of the value's content to a stream.
virtual std::wostream &writeTextValue(std::wostream & wos, const Value& v, const Options* op = 0) const { std::ostringstream os; writeTextValue(os, v, op); wos << os; return (wos);}
/// Reads a textual representation of the value's content from a stream.
virtual std::wistream &readTextValue(std::wistream& , Value& v, const Options* = 0) const { throw StreamingNotSupportedException(StreamingNotSupportedException::TEXT_READ, v.getType().getExtendedTypeInfo()); }
/// Writes a binary representation of the value's content to a stream.
virtual std::ostream &writeBinaryValue(std::ostream &, const Value& v, const Options* = 0) const { throw StreamingNotSupportedException(StreamingNotSupportedException::BINARY_WRITE, v.getType().getExtendedTypeInfo()); }
/// Reads a binary representation of the value's content from a stream.
virtual std::istream &readBinaryValue(std::istream &, Value& v, const Options* = 0) const { throw StreamingNotSupportedException(StreamingNotSupportedException::BINARY_READ, v.getType().getExtendedTypeInfo()); }
/// Virtual destructor.
virtual ~ReaderWriter() {}
};
/// This class template provides basic default streaming capabilities
/// for all types that define streaming operators (<< and >>). Most of
/// the standard types are able to be read and written this way, so the
/// StdReaderWriter template can be a convenient default for several
/// types. The binary representation is a raw copy of the memory content.
///
/// TO-DO: improve binary streaming and avoid arch dependency.
///
template<typename T>
class StdReaderWriter: public ReaderWriter
{
public:
virtual std::ostream &writeTextValue(std::ostream &os, const Value& v, const Options * = 0) const
{
return (os << variant_cast<T>(v));
}
virtual std::istream &readTextValue(std::istream &is, Value& v, const Options * = 0) const
{
if (v.isEmpty()) v = Value(T());
return (is >> variant_cast<T &>(v));
}
virtual std::ostream &writeBinaryValue(std::ostream &os, const Value& v, const Options * = 0) const
{
return os.write(reinterpret_cast<const char *>(extract_raw_data<T>(v)), sizeof(T));
}
virtual std::istream &readBinaryValue(std::istream &is, Value& v, const Options * = 0) const
{
if (v.isEmpty()) v = Value(T());
return is.read(reinterpret_cast<char *>(extract_raw_data<T>(v)), sizeof(T));
}
};
template<typename T>
class StdWReaderWriter: public ReaderWriter
{
public:
virtual std::wostream &writeTextValue(std::wostream &wos, const Value& v, const Options * = 0) const
{
return (wos << variant_cast<T>(v));
}
virtual std::wistream &readTextValue(std::wistream &wis, Value& v, const Options * = 0) const
{
if (v.isEmpty()) v = Value(T());
return (wis >> variant_cast<T &>(v));
}
virtual std::ostream &writeBinaryValue(std::ostream &os, const Value& v, const Options * = 0) const
{
return os.write(reinterpret_cast<const char *>(extract_raw_data<T>(v)), sizeof(T));
}
virtual std::istream &readBinaryValue(std::istream &is, Value& v, const Options * = 0) const
{
if (v.isEmpty()) v = Value(T());
return is.read(reinterpret_cast<char *>(extract_raw_data<T>(v)), sizeof(T));
}
};
/// This ReaderWriter can be used to read and write enumeration values.
/// The textual representation will be the enum label, if found, or the
/// numerical value. The binary representation doesn't take label names
/// into account.
template<typename T>
class EnumReaderWriter: public ReaderWriter
{
virtual std::ostream &writeTextValue(std::ostream &os, const Value& v, const Options *options = 0) const
{
int numeric = static_cast<int>(variant_cast<T>(v));
if (!options || !options->getForceNumericOutput())
{
const Type& type = v.getType();
const EnumLabelMap& elm = type.getEnumLabels();
EnumLabelMap::const_iterator i = elm.find(numeric);
if (i != elm.end())
{
os << i->second;
return os;
}
else
{
std::vector<std::string> labels;
// it could be a bitmask
for (EnumLabelMap::const_iterator i=elm.begin(); i!=elm.end(); ++i)
{
if (i->first != 0 && ((i->first & numeric) == i->first))
{
numeric ^= i->first;
labels.push_back(i->second);
}
}
// check whether all bits were discovered
if (numeric == 0)
{
for (std::vector<std::string>::const_iterator i=labels.begin(); i!=labels.end(); ++i)
{
os << *i;
if ((i+1) != labels.end()) os << " | ";
}
return os;
}
}
}
return os << numeric;
}
virtual std::istream &readTextValue(std::istream &is, Value& v, const Options * = 0) const
{
if (v.isEmpty()) v = Value(T());
int i;
if (is >> i)
{
variant_cast<T &>(v) = static_cast<T>(i);
return is;
}
is.clear();
std::string s;
if (is >> s)
{
const Type& type = v.getType();
const EnumLabelMap& elm = type.getEnumLabels();
for (EnumLabelMap::const_iterator i=elm.begin(); i!=elm.end(); ++i)
{
if (i->second.compare(s) == 0)
{
variant_cast<T &>(v) = static_cast<T>(i->first);
return is;
}
}
}
return is;
}
virtual std::ostream &writeBinaryValue(std::ostream &os, const Value& v, const Options * = 0) const
{
return os.write(reinterpret_cast<const char *>(extract_raw_data<T>(v)), sizeof(T));
}
virtual std::istream &readBinaryValue(std::istream &is, Value& v, const Options * = 0) const
{
if (v.isEmpty())
v = Value(T());
return is.read(reinterpret_cast<char *>(extract_raw_data<T>(v)), sizeof(T));
}
};
/// This is a ReaderWriter class that can be used to read and write
/// pointer values. Note: template parameter T must be a pointer!
template<typename T>
class PtrReaderWriter: public ReaderWriter
{
public:
virtual std::ostream &writeTextValue(std::ostream &os, const Value& v, const Options* = 0) const
{
return (os << (void*)variant_cast<T>(v));
}
virtual std::istream &readTextValue(std::istream &is, Value& v, const Options* = 0) const
{
void *ptr;
is >> ptr;
v = Value(T(ptr));
return is;
}
virtual std::ostream &writeBinaryValue(std::ostream &os, const Value& v, const Options* = 0) const
{
return os.write(reinterpret_cast<const char *>(extract_raw_data<T>(v)), sizeof(T));
}
virtual std::istream &readBinaryValue(std::istream &is, Value& v, const Options* = 0) const
{
T ptr;
is.read(reinterpret_cast<char *>(&ptr), sizeof(T));
v = Value(ptr);
return is;
}
};
}
#endif

View File

@@ -1,116 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_REFLECTION_
#define OSGINTROSPECTION_REFLECTION_
#include <osgIntrospection/Export>
#include <osgIntrospection/ExtendedTypeInfo>
#include <typeinfo>
#include <map>
#include <vector>
#include <list>
/// This macro emulates the behavior of the standard typeid operator,
/// returning the Type object associated to the type of the given
/// expression.
#define typeof(type) osgIntrospection::Reflection::getType(extended_typeid< type >())
#define typeofvalue(val) osgIntrospection::Reflection::getType(osgIntrospection::ExtendedTypeInfo(typeid(val), false, false))
namespace osgIntrospection
{
class Type;
struct Converter;
typedef std::list<const Converter* > ConverterList;
/// A map of types, indexed by their associated ExtendedTypeInfo
/// structure.
typedef std::map<ExtendedTypeInfo, Type*> TypeMap;
enum CastType
{
STATIC_CAST,
DYNAMIC_CAST,
REINTERPRET_CAST,
COMPOSITE_CAST
};
/// This class provides basic reflection services such as registration
/// of new types and queries on the global type map.
class OSGINTROSPECTION_EXPORT Reflection
{
public:
/// Returns the Type object associated to the given
/// ExtendedTypeInfo structure. If the type hasn't been created
/// yet it is automatically created and added to the global type
/// map. Please note that such type will have the status of
/// "declared", you still need to give details about it through
/// a Reflector class before you can query it.
static const Type& getType(const ExtendedTypeInfo &ti);
/// Finds a Type object given its qualified name, which must
/// be identical to the qualified name returned by that Type's
/// getQualifiedName() method. If the type hasn't been created
/// yet, an exception is thrown.
static const Type& getType(const std::string& qname);
/// Returns the global map of types.
static const TypeMap& getTypes();
/// Return the Type object associated to the C++ type 'void'.
/// This is a shortcut for typeof(void), which may be slow if
/// the type map is large.
static const Type& type_void();
static const Converter* getConverter(const Type& source, const Type& dest);
static bool getConversionPath(const Type& source, const Type& dest, ConverterList& conv);
// This function should be called (at least on windows platforms using Visual Studio 7.1 or 8 as compiler) to unregister
// all the known types before exiting your program: otherwise, you will get a lot of false positive memory leaks in debug builds.
// It might also be used to dynamically reload the description of the known types (?)
static void uninitialize();
private:
template<typename C> friend class Reflector;
template<typename C> friend struct TypeNameAliasProxy;
friend struct ConverterProxy;
struct StaticData
{
TypeMap typemap;
const Type* type_void;
typedef std::map<const Type* , const Converter* > ConverterMap;
typedef std::map<const Type* , ConverterMap> ConverterMapMap;
ConverterMapMap convmap;
~StaticData();
};
static StaticData& getOrCreateStaticData();
static Type* registerType(const ExtendedTypeInfo &ti);
static Type* getOrRegisterType(const ExtendedTypeInfo &ti, bool replace_if_defined = false);
static void registerConverter(const Type& source, const Type& dest, const Converter* cvt);
private:
static bool accum_conv_path(const Type& source, const Type& dest, ConverterList& conv, std::vector<const Type* > &chain, CastType castType);
static StaticData* _static_data;
};
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,570 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_TYPE
#define OSGINTROSPECTION_TYPE
#include <osgIntrospection/Export>
#include <osgIntrospection/Exceptions>
#include <osgIntrospection/Value>
#include <osgIntrospection/CustomAttributeProvider>
#include <osgIntrospection/ExtendedTypeInfo>
#include <string>
#include <typeinfo>
#include <vector>
#include <map>
#include <algorithm>
namespace osgIntrospection
{
// forward declarations
class MethodInfo;
class PropertyInfo;
class ParameterInfo;
class ReaderWriter;
class ConstructorInfo;
struct Comparator;
// typedefs for member info lists
typedef std::vector<const MethodInfo* > MethodInfoList;
typedef std::vector<const PropertyInfo* > PropertyInfoList;
typedef std::vector<const ParameterInfo* > ParameterInfoList;
typedef std::vector<const ConstructorInfo* > ConstructorInfoList;
// typedefs for member info map
typedef std::map<const Type*, PropertyInfoList > PropertyInfoMap;
typedef std::map<const Type*, MethodInfoList > MethodInfoMap;
// typedef for enum label map
typedef std::map<int, std::string> EnumLabelMap;
// typedef for base type
typedef std::vector<const Type* > TypeList;
/// 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:
/// Function category specifier for querying constructors and
/// methods.
enum FunctionCategory
{
PUBLIC_FUNCTIONS,
PROTECTED_FUNCTIONS
};
/// 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.
inline const std::type_info& getStdTypeInfo() const;
/// Returns a reference to the ExtendedTypeInfo associated
/// to this Type.
inline ExtendedTypeInfo getExtendedTypeInfo() const;
/// 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.
inline const std::string& getName() const;
/// Returns the namespace of the reflected type.
inline const std::string& getNamespace() const;
/// 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;
/// Returns true if either the fully-qualified name or one of the
/// name aliases match the given argument
inline bool matchesName(const std::string& name) const;
/// 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;
/// 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.
inline const Type& getBaseType(int i) const;
/// Returns the base type list.
inline const TypeList& getBaseTypeList() const;
/// Returns the number of type name aliases.
inline int getNumAliases() const;
/// Returns the i-th name alias
const std::string& getAlias(int i) const;
/// 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).
inline const Type& getPointedType() const;
/// 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;
/// Returns the list of properties defined for this type. The list
/// does not include properties inherited from base types.
inline const PropertyInfoList& getProperties() const;
/// Fills a list of properties that are either defined in this Type
/// or in inherited types.
void getAllProperties(PropertyInfoList& props) const;
/// Fills a map of "type <-> propertyInfoList" that are either defined in this Type
/// or in inherited types.
void getPropertiesMap(PropertyInfoMap& props) const;
/// Returns the list of constructors defined for this type.
inline const ConstructorInfoList& getConstructors(FunctionCategory category = PUBLIC_FUNCTIONS) const;
/// Returns the list of methods defined for this type. The list
/// does not include methods inherited from base types.
inline const MethodInfoList& getMethods(FunctionCategory category = PUBLIC_FUNCTIONS) const;
/// Fills a list of methods that are either defined in this Type
/// or in inherited types.
void getAllMethods(MethodInfoList& methods, FunctionCategory category = PUBLIC_FUNCTIONS) const;
/// Fills a map of "type <-> MethodInfoList" that are either defined in this Type
/// or in inherited types.
void getMethodsMap(MethodInfoMap& methods, FunctionCategory category = PUBLIC_FUNCTIONS) const;
/// Returns the map of enumeration labels. If the type is not an
/// enumeration, an empty map is returned.
inline const EnumLabelMap& getEnumLabels() const;
/// 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.
const ConstructorInfo* getCompatibleConstructor(const ValueList& values) const;
/// Searches for a constructor whose parameters match exactly the given
/// list of parameter descriptions.
const ConstructorInfo* getConstructor(const ParameterInfoList& params) const;
/// 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.
const MethodInfo* getCompatibleMethod(const std::string& name, const ValueList& values, bool inherit) const;
/// Searches for a method whose parameters match exactly the given
/// list of parameter descriptions.
const MethodInfo* getMethod(const std::string& name, const ParameterInfoList& params, bool inherit) const;
/// Searches for a property given its name, type and list of indices.
/// Only exact matches are returned.
const PropertyInfo* getProperty(const std::string& name, const Type& ptype, const ParameterInfoList& indices, bool inherit) const;
/// Searches for a suitable method and invokes it with the given list
/// of arguments (const instance).
Value invokeMethod(const std::string& name, const Value& instance, ValueList& args, bool inherit) const;
/// Searches for a suitable method and invokes it with the given list
/// of arguments.
Value invokeMethod(const std::string& name, Value& instance, ValueList& args, bool inherit) const;
/// Returns whether the reflected type is derived from another type.
bool isSubclassOf(const Type& type) const;
/// Returns the instance of the reader/writer object assigned to
/// this type, if any. Otherwise it returns the null pointer.
inline const ReaderWriter* getReaderWriter() const;
/// Returns the instance of the comparator object assigned to
/// this type, if any. Otherwise it returns the null pointer.
inline const Comparator* getComparator() const;
/// 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;
/// 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.
Value createInstance(ValueList& args) const;
inline Value createInstance() const;
// 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();
protected:
Type(const ExtendedTypeInfo &ti)
: _ti(ti),
_is_const(false),
_is_abstract(false),
_pointed_type(0),
_referenced_type(0),
_is_defined(false),
_rw(0),
_cmp(0)
{
}
// throws an exception if the type is not defined.
void check_defined() const;
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
private:
template<typename C> friend class Reflector;
template<typename C> friend struct TypeNameAliasProxy;
friend class Reflection;
Type(const Type& copy): CustomAttributeProvider(copy), _ti(copy._ti) {}
ExtendedTypeInfo _ti;
std::string _name;
std::string _namespace;
TypeList _base;
bool _is_const;
bool _is_abstract;
const Type* _pointed_type;
const Type* _referenced_type;
ConstructorInfoList _cons;
ConstructorInfoList _protected_cons;
PropertyInfoList _props;
MethodInfoList _methods;
MethodInfoList _protected_methods;
EnumLabelMap _labels;
bool _is_defined;
const ReaderWriter* _rw;
const Comparator* _cmp;
typedef std::vector<std::string> AliasList;
AliasList _aliases;
std::string _briefHelp;
std::string _detailedHelp;
std::string _declaringFile;
};
// OPERATORS
/// Equality test operator. Returns true if the two instances of Type
/// describe the same type, false otherwise.
inline bool operator==(const Type& t1, const Type& t2)
{
return (t1.getStdTypeInfo() == t2.getStdTypeInfo()) != 0;
}
/// Inequality test operator. Returns false if the two instances of Type
/// describe the same type, true otherwise.
inline bool operator!=(const Type& t1, const Type& t2)
{
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.
inline bool operator<(const Type& t1, const Type& t2)
{
return (t1.getStdTypeInfo().before(t2.getStdTypeInfo())) != 0;
}
/// Greater than or equal to operator. Returns !operator<().
inline bool operator>=(const Type& t1, const Type& t2)
{
return !operator<(t1, t2);
}
// INLINE METHODS
inline void Type::check_defined() const
{
if (!_is_defined)
throw TypeNotDefinedException(_ti);
}
inline const std::type_info& Type::getStdTypeInfo() const
{
return _ti.getStdTypeInfo();
}
inline ExtendedTypeInfo Type::getExtendedTypeInfo() const
{
return _ti;
}
inline const std::string& Type::getName() const
{
check_defined();
return _name;
}
inline const std::string& Type::getNamespace() const
{
check_defined();
return _namespace;
}
inline std::string Type::getQualifiedName() const
{
check_defined();
std::string qname;
if (_is_const) qname = "const ";
if (!_namespace.empty())
{
qname.append(_namespace);
qname.append("::");
}
qname.append(_name);
if (_pointed_type)
qname.append(" *");
else if (_referenced_type)
qname.append(" &");
return qname;
}
inline const std::string& Type::getBriefHelp() const
{
return _briefHelp;
}
inline const std::string& Type::getDetailedHelp() const
{
return _detailedHelp;
}
inline int Type::getNumBaseTypes() const
{
check_defined();
return static_cast<int>(_base.size());
}
inline bool Type::isConstPointer() const
{
check_defined();
return _is_const && _pointed_type;
}
inline bool Type::isNonConstPointer() const
{
check_defined();
return !_is_const && _pointed_type;
}
inline bool Type::isConstReference() const
{
check_defined();
return _is_const && _referenced_type;
}
inline bool Type::isNonConstReference() const
{
check_defined();
return !_is_const && _referenced_type;
}
inline bool Type::isAbstract() const
{
check_defined();
return _is_abstract;
}
inline bool Type::isAtomic() const
{
check_defined();
return _rw != 0;
}
inline const PropertyInfoList& Type::getProperties() const
{
check_defined();
return _props;
}
inline const ConstructorInfoList& Type::getConstructors(FunctionCategory category) const
{
check_defined();
return category == PUBLIC_FUNCTIONS ? _cons : _protected_cons;
}
inline const MethodInfoList& Type::getMethods(FunctionCategory category) const
{
check_defined();
return category == PUBLIC_FUNCTIONS ? _methods : _protected_methods;
}
inline bool Type::isPointer() const
{
check_defined();
return _pointed_type != 0;
}
inline bool Type::isReference() const
{
check_defined();
return _referenced_type != 0;
}
inline bool Type::isVoid() const
{
return (_ti == extended_typeid<void>()) != 0;
}
inline const Type& Type::getPointedType() const
{
check_defined();
if (_pointed_type)
return *_pointed_type;
return Reflection::type_void();
}
inline const Type& Type::getReferencedType() const
{
check_defined();
if (_referenced_type)
return *_referenced_type;
return Reflection::type_void();
}
inline bool Type::isEnum() const
{
check_defined();
return !_labels.empty();
}
inline const EnumLabelMap& Type::getEnumLabels() const
{
check_defined();
return _labels;
}
inline bool Type::isDefined() const
{
return _is_defined;
}
inline const ReaderWriter* Type::getReaderWriter() const
{
check_defined();
return _rw;
}
inline const Comparator* Type::getComparator() const
{
check_defined();
return _cmp;
}
inline const Type& Type::getBaseType(int i) const
{
check_defined();
return *_base.at(i);
}
inline const TypeList& Type::getBaseTypeList() const
{
check_defined();
return _base;
}
inline Value Type::createInstance() const
{
ValueList args;
return createInstance(args);
}
inline int Type::getNumAliases() const
{
return static_cast<int>(_aliases.size());
}
inline const std::string& Type::getAlias(int i) const
{
return _aliases[i];
}
inline bool Type::matchesName(const std::string& name) const
{
if (getQualifiedName() == name)
return true;
if (std::find(_aliases.begin(), _aliases.end(), name) != _aliases.end())
return true;
return false;
}
inline const std::string &Type::getDeclaringFile() const
{
return _declaringFile;
}
}
#endif

View File

@@ -1,40 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_TYPENAMEALIASPROXY_
#define OSGINTROSPECTION_TYPENAMEALIASPROXY_
#include <osgIntrospection/Type>
#include <osgIntrospection/Reflection>
#include <string>
#include <algorithm>
namespace osgIntrospection
{
template<typename C>
struct TypeNameAliasProxy
{
TypeNameAliasProxy(const std::string& name)
{
Type* type = Reflection::getOrRegisterType(extended_typeid<C>());
if (std::find(type->_aliases.begin(), type->_aliases.end(), name) == type->_aliases.end())
type->_aliases.push_back(name);
}
};
}
#endif

View File

@@ -1,467 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_TYPEDCONSTRUCTORINFO_
#define OSGINTROSPECTION_TYPEDCONSTRUCTORINFO_
#include <osgIntrospection/ConstructorInfo>
#include <osgIntrospection/InstanceCreator>
#include <osgIntrospection/Utility>
namespace osgIntrospection
{
template<typename C, typename IC>
struct TypedConstructorInfo0: ConstructorInfo
{
TypedConstructorInfo0(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& /*args*/) const
{
return IC::create();
}
};
template<typename C, typename IC, typename P0>
struct TypedConstructorInfo1: ConstructorInfo
{
TypedConstructorInfo1(const ParameterInfoList& plist, bool isExplicit, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, isExplicit, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(1);
convertArgument<P0>(args, newargs, getParameters(), 0);
return IC::template create<P0>(newargs[0]);
}
};
template<typename C, typename IC, typename P0, typename P1>
struct TypedConstructorInfo2: ConstructorInfo
{
TypedConstructorInfo2(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(2);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
return IC::template create<P0, P1>(newargs[0], newargs[1]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2>
struct TypedConstructorInfo3: ConstructorInfo
{
TypedConstructorInfo3(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(3);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
return IC::template create<P0, P1, P2>(newargs[0], newargs[1], newargs[2]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3>
struct TypedConstructorInfo4: ConstructorInfo
{
TypedConstructorInfo4(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(4);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
return IC::template create<P0, P1, P2, P3>(newargs[0], newargs[1], newargs[2], newargs[3]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4>
struct TypedConstructorInfo5: ConstructorInfo
{
TypedConstructorInfo5(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(5);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
return IC::template create<P0, P1, P2, P3, P4>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
struct TypedConstructorInfo6: ConstructorInfo
{
TypedConstructorInfo6(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(6);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
return IC::template create<P0, P1, P2, P3, P4, P5>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
struct TypedConstructorInfo7: ConstructorInfo
{
TypedConstructorInfo7(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(7);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
return IC::template create<P0, P1, P2, P3, P4, P5, P6>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
struct TypedConstructorInfo8: ConstructorInfo
{
TypedConstructorInfo8(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(8);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
struct TypedConstructorInfo9: ConstructorInfo
{
TypedConstructorInfo9(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(9);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
struct TypedConstructorInfo10: ConstructorInfo
{
TypedConstructorInfo10(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(10);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
struct TypedConstructorInfo11: ConstructorInfo
{
TypedConstructorInfo11(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(11);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
struct TypedConstructorInfo12: ConstructorInfo
{
TypedConstructorInfo12(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(12);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
convertArgument<P11>(args, newargs, getParameters(), 11);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10], newargs[11]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
struct TypedConstructorInfo13: ConstructorInfo
{
TypedConstructorInfo13(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(13);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
convertArgument<P11>(args, newargs, getParameters(), 11);
convertArgument<P12>(args, newargs, getParameters(), 12);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10], newargs[11], newargs[12]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
struct TypedConstructorInfo14: ConstructorInfo
{
TypedConstructorInfo14(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(14);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
convertArgument<P11>(args, newargs, getParameters(), 11);
convertArgument<P12>(args, newargs, getParameters(), 12);
convertArgument<P13>(args, newargs, getParameters(), 13);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10], newargs[11], newargs[12], newargs[13]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
struct TypedConstructorInfo15: ConstructorInfo
{
TypedConstructorInfo15(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(15);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
convertArgument<P11>(args, newargs, getParameters(), 11);
convertArgument<P12>(args, newargs, getParameters(), 12);
convertArgument<P13>(args, newargs, getParameters(), 13);
convertArgument<P14>(args, newargs, getParameters(), 14);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10], newargs[11], newargs[12], newargs[13], newargs[14]);
}
};
template<typename C, typename IC, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
struct TypedConstructorInfo16: ConstructorInfo
{
TypedConstructorInfo16(const ParameterInfoList& plist, std::string briefHelp = std::string(), std::string detailedHelp = std::string())
: ConstructorInfo(typeof(C), plist, briefHelp, detailedHelp)
{
}
Value createInstance(ValueList& args) const
{
ValueList newargs(16);
convertArgument<P0>(args, newargs, getParameters(), 0);
convertArgument<P1>(args, newargs, getParameters(), 1);
convertArgument<P2>(args, newargs, getParameters(), 2);
convertArgument<P3>(args, newargs, getParameters(), 3);
convertArgument<P4>(args, newargs, getParameters(), 4);
convertArgument<P5>(args, newargs, getParameters(), 5);
convertArgument<P6>(args, newargs, getParameters(), 6);
convertArgument<P7>(args, newargs, getParameters(), 7);
convertArgument<P8>(args, newargs, getParameters(), 8);
convertArgument<P9>(args, newargs, getParameters(), 9);
convertArgument<P10>(args, newargs, getParameters(), 10);
convertArgument<P11>(args, newargs, getParameters(), 11);
convertArgument<P12>(args, newargs, getParameters(), 12);
convertArgument<P13>(args, newargs, getParameters(), 13);
convertArgument<P14>(args, newargs, getParameters(), 14);
convertArgument<P15>(args, newargs, getParameters(), 15);
return IC::template create<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15>(newargs[0], newargs[1], newargs[2], newargs[3], newargs[4], newargs[5], newargs[6], newargs[7], newargs[8], newargs[9], newargs[10], newargs[11], newargs[12], newargs[13], newargs[14], newargs[15]);
}
};
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_UTILITY_
#define OSGINTROSPECTION_UTILITY_
#include <osgIntrospection/Export>
#include <osgIntrospection/Value>
#include <osgIntrospection/ParameterInfo>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/variant_cast>
#include <vector>
namespace osgIntrospection
{
bool OSGINTROSPECTION_EXPORT areParametersCompatible(const ParameterInfoList& pl1, const ParameterInfoList& pl2);
bool OSGINTROSPECTION_EXPORT areArgumentsCompatible(const ValueList& vl, const ParameterInfoList& pl, float &match);
template<typename T>
void convertArgument(ValueList& src, ValueList& dest, const ParameterInfoList& pl, int index)
{
if (index >= static_cast<int>(src.size()))
{
dest[index] = pl[index]->getDefaultValue();
}
else
{
Value& sv = src[index];
if (requires_conversion<T>(sv))
dest[index] = sv.convertTo(pl[index]->getParameterType());
else
dest[index].swap(sv);
}
}
/// Return a const reference on the reflected value given on the instance
///
/// NOTE: You should NEVER paste a pointer or a reference to the template parameter T
template<typename T> const T &getInstance(const Value &instance)
{
return instance.isTypedPointer() ?
*variant_cast<const T*>(instance) : variant_cast<const T&>(instance);
}
/// Return a reference on the reflected value given on the instance
///
/// NOTE: You should NEVER paste a pointer or a reference to the template parameter T
template<typename T> T &getInstance(Value &instance)
{
return instance.isTypedPointer() ?
*variant_cast<T*>(instance) : variant_cast<T&>(instance);
}
}
#endif

View File

@@ -1,436 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_VALUE_
#define OSGINTROSPECTION_VALUE_
#include <osgIntrospection/Export>
#include <osgIntrospection/Reflection>
#include <osgIntrospection/type_traits>
#include <vector>
#include <memory>
#include <string>
namespace osgIntrospection
{
class Type;
class OSGINTROSPECTION_EXPORT Value
{
public:
/// Default constructor. Initializes internal structures
/// so that the Type returned by getType() is typeof(void),
/// and the value is empty so that isEmpty() returns true.
/// Be careful when using empty values, as some operations
/// on them may throw an exception.
inline Value();
/// Direct initialization constructor for void pointers.
/// Although one of the constructor templates below could
/// certainly handle void pointers as well, we need to treat
/// them separately because void* can't be dereferenced.
inline Value(void *v);
/// Direct initialization constructor for const void pointers.
/// Although one of the constructor templates below could
/// certainly handle void pointers as well, we need to treat
/// them separately because void* can't be dereferenced.
inline Value(const void *v);
/// Direct initialization constructor template for non-const
/// pointers. By initializing an instance of Value through
/// this constructor, internal structures will be configured
/// to handle polymorphic types. This means you'll be able to
/// call getInstanceType() to get the actual type of the
/// dereferenced value.
template<typename T> Value(T *v);
/// Direct initialization constructor template for non-const
/// pointers. By initializing an instance of Value through
/// this constructor, internal structures will be configured
/// to handle polymorphic types. This means you'll be able to
/// call getInstanceType() to get the actual type of the
/// dereferenced value.
template<typename T> Value(const T *v);
/// Direct initialization constructor template for all types
/// that are not handled by any of the constructors above.
/// Calling getInstanceType() on an instance constructed
/// this way returns the same as getType().
template<typename T> Value(const T &v);
/// Copy constructor. The underlying value's type must have
/// consistent copy semantics.
inline Value(const Value& copy);
/// Destructor. Frees internal resources but it does NOT delete
/// the value held. For example, this function will produce a
/// memory leak: void f() { Value v(new int); }
inline ~Value();
/// Assignment operator. Behaves like the copy constructor.
inline Value& operator=(const Value& copy);
/// Returns whether the value is a pointer and it points to
/// something whose type is different than void.
inline bool isTypedPointer() const;
/// Returns whether this Value is empty.
inline bool isEmpty() const;
/// Returns whether the value is a null pointer.
inline bool isNullPointer() const;
/// Returns the exact type of the value held.
inline const Type& getType() const;
/// If the value is a pointer to a non-void type, this method
/// returns the actual type of the dereferenced pointer. Please
/// note it is not the same as getType().getPointedType(),
/// because the latter would return the non-polymorphic type.
/// If the value is not a pointer, this method behaves like
/// getType().
inline const Type& getInstanceType() const;
/// Equal to operator.
bool operator==(const Value& other) const;
/// Less than or equal to operator.
bool operator<=(const Value& other) const;
/// Inequality test operator. Returns !operator==(other).
bool operator!=(const Value& other) const;
/// Greater than operator. Returns !operator<=(other).
bool operator>(const Value& other) const;
/// Less than operator. Returns !operator==(other) && operator<=(other).
bool operator<(const Value& other) const;
/// Greater than or equal to operator. Returns operator==(other) || !operator<=(other)
bool operator>=(const Value& other) const;
/// Tries to convert this instance to a Value of the given type.
/// The conversion is performed by rendering to a temporary stream
/// in the source format and trying to read back from the stream
/// in the destination format. If either the source or destination
/// types, or both, don't have a ReaderWriter object, the conversion
/// fails and an exception is thrown. If the conversion can't be
/// completed for other reasons, other exceptions may be thrown.
Value convertTo(const Type& outtype) const;
/// Tries to convert this instance to a Value of the given type.
/// The conversion is performed by rendering to a temporary stream
/// in the source format and trying to read back from the stream
/// in the destination format. If either the source or destination
/// types, or both, don't have a ReaderWriter object, the conversion
/// fails and an empty Value is returned.
/// Please note that unlike convertTo(), this method does not
/// intentionally throw any exceptions.
Value tryConvertTo(const Type& outtype) const;
/// Tries to get a string representation of the underlying value.
/// This requires the value's type to have a ReaderWriter object
/// associated to it. If the conversion can't be completed, an
/// exception is thrown.
std::string toString() const;
std::wstring toWString() const;
/// Swaps the content of this Value with another Value
void swap(Value& v);
private:
// It's good to have friends!
template<typename T> friend T variant_cast(const Value& v);
template<typename T> friend bool requires_conversion(const Value& v);
template<typename T> friend T *extract_raw_data(Value& v);
template<typename T> friend const T *extract_raw_data(const Value& v);
// throw an exception if the value is empty
void check_empty() const;
// Base class for holding values. Provides a clone() method
// which must be overriden in descendant classes.
struct Instance_base
{
virtual Instance_base *clone() const = 0;
virtual ~Instance_base() {}
};
// Generic descendant of Instance_base for holding values of
// type T. Note that values are created on the stack.
template<typename T>
struct Instance: Instance_base
{
Instance(T data): _data(data) {}
virtual Instance_base *clone() const { return new Instance<T>(*this); }
virtual ~Instance() {}
T _data;
protected:
Instance& operator = (const Instance& rhs)
{
if (&rhs!=this)
{
_data = rhs._data;
}
return *this;
}
};
// Base class for storage of Instance objects. Actually three
// instances are created: the main instance which keeps the
// desired value, an additional instance that keeps a reference
// to that value, and another instance that keeps a const
// reference to that value. These additional instances are queried
// when casting the Value to a reference type.
struct Instance_box_base
{
Instance_box_base()
: inst_(0),
_ref_inst(0),
_const_ref_inst(0)
{
}
virtual ~Instance_box_base()
{
delete inst_;
delete _ref_inst;
delete _const_ref_inst;
}
// clones the instance box
virtual Instance_box_base *clone() const = 0;
// returns the type of the value held
virtual const Type* type() const = 0;
// returns the actual pointed type if applicable
virtual const Type* ptype() const { return 0; }
// returns whether the data is a null pointer
virtual bool isNullPointer() const = 0;
Instance_base *inst_;
Instance_base *_ref_inst;
Instance_base *_const_ref_inst;
};
// Generic instance box for non-pointer values.
template<typename T>
struct Instance_box: Instance_box_base
{
Instance_box(): Instance_box_base(), _isNullPointer(false) {}
Instance_box(const T &d, bool isNullPointer = false)
: Instance_box_base(),
_isNullPointer(isNullPointer)
{
Instance<T> *vl = new Instance<T>(d);
inst_ = vl;
_ref_inst = new Instance<T &>(vl->_data);
_const_ref_inst = new Instance<const T &>(vl->_data);
}
virtual Instance_box_base *clone() const
{
Instance_box<T> *new_inbox = new Instance_box<T>();
// ??? this static_cast<> shouldn't be necessary, but the
// MSVC++ compiler complains about invalid casting without it!
Instance<T> *vl = static_cast<Instance<T> *>(inst_->clone());
new_inbox->inst_ = vl;
new_inbox->_ref_inst = new Instance<T &>(vl->_data);
new_inbox->_const_ref_inst = new Instance<const T &>(vl->_data);
new_inbox->_isNullPointer = _isNullPointer;
return new_inbox;
}
virtual const Type* type() const
{
return &typeof(T);
}
virtual bool isNullPointer() const
{
return _isNullPointer;
}
private:
bool _isNullPointer;
Instance_box& operator = (const Instance_box&) { return *this; }
};
// Generic instance box for pointer values. Unlike Instance_box<>,
// this struct template provides a ptype() method that unreferences
// the pointer (T is supposed to be a pointer) and gets its actual
// type.
template<typename T>
struct Ptr_instance_box: Instance_box_base
{
Ptr_instance_box(): Instance_box_base() {}
Ptr_instance_box(const T &d)
: Instance_box_base()
{
Instance<T> *vl = new Instance<T>(d);
inst_ = vl;
_ref_inst = new Instance<T &>(vl->_data);
_const_ref_inst = new Instance<const T &>(vl->_data);
}
virtual Instance_box_base *clone() const
{
Ptr_instance_box<T> *new_inbox = new Ptr_instance_box<T>();
// ??? this static_cast<> shouldn't be necessary, but the
// MSVC++ compiler complains about invalid casting without it!
Instance<T> *vl = static_cast<Instance<T> *>(inst_->clone());
new_inbox->inst_ = vl;
new_inbox->_ref_inst = new Instance<T &>(vl->_data);
new_inbox->_const_ref_inst = new Instance<const T &>(vl->_data);
return new_inbox;
}
virtual const Type* type() const
{
return &typeof(T);
}
virtual const Type* ptype() const
{
if (!static_cast<Instance<T> *>(inst_)->_data) return 0;
return &typeofvalue(*static_cast<Instance<T> *>(inst_)->_data);
}
virtual bool isNullPointer() const
{
return static_cast<Instance<T> *>(inst_)->_data == 0;
}
};
Instance_box_base *_inbox;
const Type* _type;
const Type* _ptype;
};
/// A vector of values.
typedef std::vector<Value> ValueList;
// INLINE METHODS
inline Value::Value()
: _inbox(0),
_type(&Reflection::type_void()),
_ptype(0)
{
}
template<typename T> Value::Value(const T &v)
: _ptype(0)
{
_inbox = new Instance_box<T>(v);
_type = _inbox->type();
}
inline Value::Value(const void *v)
: _ptype(0)
{
_inbox = new Instance_box<const void *>(v, v == 0);
_type = _inbox->type();
}
inline Value::Value(void *v)
: _ptype(0)
{
_inbox = new Instance_box<void *>(v, v == 0);
_type = _inbox->type();
}
template<typename T> Value::Value(const T *v)
{
_inbox = new Ptr_instance_box<const T *>(v);
_type = _inbox->type();
_ptype = _inbox->ptype();
}
template<typename T> Value::Value(T *v)
{
_inbox = new Ptr_instance_box<T *>(v);
_type = _inbox->type();
_ptype = _inbox->ptype();
}
inline Value::Value(const Value& copy)
: _inbox(copy._inbox? copy._inbox->clone(): 0),
_type(copy._type),
_ptype(copy._ptype)
{
}
inline Value& Value::operator=(const Value& copy)
{
std::auto_ptr<Instance_box_base> new_inbox(copy._inbox? copy._inbox->clone(): 0);
delete _inbox;
_inbox = new_inbox.release();
_type = copy._type;
_ptype = copy._ptype;
return *this;
}
inline Value::~Value()
{
delete _inbox;
}
inline const Type& Value::getType() const
{
return *_type;
}
inline const Type& Value::getInstanceType() const
{
if (_ptype)
return *_ptype;
return *_type;
}
inline bool Value::isTypedPointer() const
{
return _ptype != 0;
}
inline bool Value::isEmpty() const
{
return _inbox == 0;
}
inline bool Value::isNullPointer() const
{
return _inbox->isNullPointer();
}
}
#endif

View File

@@ -1,48 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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.
*/
#ifndef OSGINTROSPECTION_VERSION
#define OSGINTROSPECTION_VERSION 1
#include <osgIntrospection/Export>
extern "C" {
/**
* osgIntrospectionGetVersion() returns the library version number.
* Numbering convention : OpenSceneGraph-1.0 will return 1.0 from osgIntrospectionGetVersion.
*
* This C function can be also used to check for the existence of the OpenSceneGraph
* library using autoconf and its m4 macro AC_CHECK_LIB.
*
* Here is the code to add to your configure.in:
\verbatim
#
# Check for the OpenSceneGraph (OSG) Introspection library
#
AC_CHECK_LIB(osg, osgIntrospectionGetVersion, ,
[AC_MSG_ERROR(OpenSceneGraph Introspection library not found. See http://www.openscenegraph.org)],)
\endverbatim
*/
extern OSGINTROSPECTION_EXPORT const char* osgIntrospectionGetVersion();
/**
* getLibraryName_osgIntrospection() returns the library name in human friendly form.
*/
extern OSGINTROSPECTION_EXPORT const char* osgIntrospectionGetLibraryName();
}
#endif

View File

@@ -1,63 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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.
*/
#ifndef OSGINTROSPECTION_TYPE_TRAITS_
#define OSGINTROSPECTION_TYPE_TRAITS_
/// is_reference is a compile-time template predicate to determine if a
/// type is a reference type.
template <typename T>
struct is_reference
{
static const bool value = false;
};
template <typename T>
struct is_reference<T &>
{
static const bool value = true;
};
/// is_const_reference is a compile-time template predicate to determine
/// if a type is a const reference type.
template <typename T>
struct is_const_reference
{
static const bool value = false;
};
template <typename T>
struct is_const_reference<const T &>
{
static const bool value = true;
};
/// remove_pointer is a compile-time template type mapper that produces
/// the input type, but with any pointer modifier removed.
template <typename T>
struct remove_pointer
{
typedef T type;
};
template <typename T>
struct remove_pointer<T *>
{
typedef T type;
};
#endif

View File

@@ -1,98 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
#ifndef OSGINTROSPECTION_VARIANT_CAST_
#define OSGINTROSPECTION_VARIANT_CAST_
#include <osgIntrospection/Value>
#include <osgIntrospection/ReaderWriter>
#include <sstream>
namespace osgIntrospection
{
/// Tries to convert an instance of Value to an object of type T.
/// If T is a plain type or a pointer type (either const or non-const),
/// and it matches the type of the value contained in v, then the actual
/// value of type T is returned. If T is a [const] reference type, and
/// its base (non reference) type matches the internal value's type,
/// then a [const] reference to the internal value is returned.
/// If none of the above conditions are met, a conversion is attempted
/// as described in Value::convert() and then variant_cast is called again
/// with the converted value as parameter.
/// If the conversion can't be completed, an exception is thrown.
/// Conversions that attempt to make a const pointer non-const will fail.
template<typename T> T variant_cast(const Value& v)
{
// return value
Value::Instance<T> *i = dynamic_cast<Value::Instance<T> *>(v._inbox->inst_);
if (i) return i->_data;
// return reference to value
i = dynamic_cast<Value::Instance<T> *>(v._inbox->_ref_inst);
if (i) return i->_data;
// return const reference to value
i = dynamic_cast<Value::Instance<T> *>(v._inbox->_const_ref_inst);
if (i) return i->_data;
// try to convert v to type T and restart
return variant_cast<T>(v.convertTo(typeof(T)));
}
/// Returns true if the Value passed as parameter can't be casted to
/// the specified type without a (potentially slow) conversion.
/// Returns false otherwise.
template<typename T> bool requires_conversion(const Value& v)
{
// direct value
Value::Instance<T> *i = dynamic_cast<Value::Instance<T> *>(v._inbox->inst_);
if (i) return false;
// reference to value
i = dynamic_cast<Value::Instance<T> *>(v._inbox->_ref_inst);
if (i) return false;
// const reference to value
i = dynamic_cast<Value::Instance<T> *>(v._inbox->_const_ref_inst);
if (i) return false;
return true;
}
/// Returns a typed pointer to the data contained in a Value
/// instance. If the value's type is not identical to type T,
/// a null pointer is returned.
template<typename T> T* extract_raw_data(Value& v)
{
Value::Instance<T>* i = dynamic_cast<Value::Instance<T> *>(v._inbox->inst_);
if (i) return &i->_data;
return 0;
}
/// Returns a typed pointer to the data contained in a const Value
/// instance. If the value's type is not identical to type T, a
/// null pointer is returned.
template<typename T> const T* extract_raw_data(const Value& v)
{
Value::Instance<T>* i = dynamic_cast<Value::Instance<T> *>(v._inbox->inst_);
if (i) return &i->_data;
return 0;
}
}
#endif