2005-04-29 18:06:50 +08:00
|
|
|
/* -*-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) 2005 Marco Jez
|
|
|
|
|
2004-12-09 13:28:20 +08:00
|
|
|
#ifndef OSGINTROSPECTION_ATTRIBUTES_
|
|
|
|
#define OSGINTROSPECTION_ATTRIBUTES_
|
|
|
|
|
|
|
|
#include <osgIntrospection/CustomAttribute>
|
|
|
|
#include <osgIntrospection/Value>
|
|
|
|
#include <osgIntrospection/Exceptions>
|
2005-04-04 21:50:07 +08:00
|
|
|
#include <osgIntrospection/Type>
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
namespace osgIntrospection
|
|
|
|
{
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
/// 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:
|
2005-04-29 19:19:58 +08:00
|
|
|
DefaultValueAttribute(const Value& v): _v(v) {}
|
|
|
|
const Value& getDefaultValue() const { return _v; }
|
2005-03-14 17:28:31 +08:00
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
Value _v;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
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); }
|
2005-03-14 17:28:31 +08:00
|
|
|
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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomPropertyGetAttribute(const PropertyGetter* getter)
|
|
|
|
: CustomAttribute(), _getter(getter) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyGetter* getGetter() const { return _getter; }
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
~CustomPropertyGetAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _getter;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyGetter* _getter;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
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); }
|
2005-03-14 17:28:31 +08:00
|
|
|
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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomPropertySetAttribute(const PropertySetter* setter)
|
|
|
|
: CustomAttribute(), _setter(setter) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertySetter* getSetter() const { return _setter; }
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
~CustomPropertySetAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _setter;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertySetter* _setter;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
virtual int count(const Value& /*instance*/) const { throw PropertyAccessException("[n/a inside a custom accessor]", PropertyAccessException::COUNT); }
|
2005-03-14 17:28:31 +08:00
|
|
|
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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomPropertyCountAttribute(const PropertyCounter* counter)
|
|
|
|
: CustomAttribute(), _counter(counter) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyCounter* getCounter() const { return _counter; }
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
~CustomPropertyCountAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _counter;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyCounter* _counter;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomPropertyAddAttribute(const PropertyAdder* adder)
|
|
|
|
: CustomAttribute(), _adder(adder) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyAdder* getAdder() const { return _adder; }
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
~CustomPropertyAddAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _adder;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyAdder* _adder;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// 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 ~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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomPropertyRemoveAttribute(const PropertyRemover* remover)
|
|
|
|
: CustomAttribute(), _remover(remover) {}
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyRemover* getRemover() const { return _remover; }
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
~CustomPropertyRemoveAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _remover;
|
2005-04-04 21:50:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const PropertyRemover* _remover;
|
2005-04-04 21:50:07 +08:00
|
|
|
};
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
virtual const ParameterInfoList& getIndexParameters() const = 0;
|
|
|
|
virtual void getIndexValueSet(int whichindex, const Value& instance, ValueList& values) const = 0;
|
2005-03-14 17:28:31 +08:00
|
|
|
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:
|
2005-04-29 19:19:58 +08:00
|
|
|
CustomIndexAttribute(const IndexInfo* ii)
|
|
|
|
: CustomAttribute(), _ii(ii) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const IndexInfo* getIndexInfo() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _ii;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CustomIndexAttribute()
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
delete _ii;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const IndexInfo* _ii;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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:
|
2005-04-29 19:19:58 +08:00
|
|
|
PropertyTypeAttribute(const Type& type)
|
|
|
|
: CustomAttribute(), _type(type) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const Type& getPropertyType() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _type;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
const Type& _type;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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:
|
2005-04-29 19:19:58 +08:00
|
|
|
IndexTypeAttribute(int whichindex, const Type& type)
|
|
|
|
: CustomAttribute(), _wi(whichindex), _type(type) {}
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
int getWhichIndex() const
|
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _wi;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
const Type& getIndexType() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _type;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
int _wi;
|
|
|
|
const Type& _type;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|