Show ControlList.h syntax highlighted
#ifndef __CONTROLLIST_H__
#define __CONTROLLIST_H__ 1
#include <iostream>
#include <osg/Referenced>
#include <osg/ref_ptr>
#include <osgIntrospection/Type>
#include <osgIntrospection/PropertyInfo>
#include <osgIntrospectionToolKit/Export.h>
namespace osgIntrospectionToolKit
{
enum Policy
{
Reject = 0,
Allow,
Next
};
template <typename T>
class Control: public osg::Referenced
{
public:
Control() : _t(NULL), _policy(Reject) {}
explicit Control(T t, Policy policy) : _t(t), _policy(policy) {}
virtual ~Control() {}
virtual Policy check(T t) const;
T _t;
Policy _policy;
};
template <typename T>
Policy Control< T >::check(T t) const
{ return ((t == _t) ? (_policy) : (Next)); }
template <typename T>
class ControlAllow: public Control< T >
{
virtual Policy check(T) const
{ return (Allow); }
};
template <typename T>
class ControlReject: public Control< T >
{
virtual Policy check(T) const
{ return (Reject); }
};
template <typename T>
class ControlNext: public Control< T >
{
virtual Policy check(T) const
{ return (Next); }
};
template <typename T>
class ControlList: public std::vector< osg::ref_ptr< Control< T > > >
{
public:
typedef typename std::vector< osg::ref_ptr< Control< T > > > Base;
typedef typename Base::const_iterator const_iterator;
public:
Policy check(T t) const;
};
template <typename T>
inline Policy ControlList< T >::check(const T t) const
{
Policy result;
for (const_iterator it = Base::begin(); it != Base::end(); ++it)
{
result = (*it)->check(t);
if (result != Next)
return (result);
}
return (Next);
}
typedef Control< const osgIntrospection::Type* > TypeControl;
typedef ControlAllow< const osgIntrospection::Type* > TypeControlAllow;
typedef ControlReject< const osgIntrospection::Type* > TypeControlReject;
typedef ControlNext< const osgIntrospection::Type* > TypeControlNext;
typedef Control< const osgIntrospection::PropertyInfo* > PropertyInfoControl;
typedef ControlAllow< const osgIntrospection::PropertyInfo* > PropertyInfoControlAllow;
typedef ControlReject< const osgIntrospection::PropertyInfo* > PropertyInfoControlReject;
typedef ControlNext< const osgIntrospection::PropertyInfo* > PropertyInfoControlNext;
typedef ControlList< const osgIntrospection::Type* > TypeControlList;
typedef ControlList< const osgIntrospection::PropertyInfo* > PropertyInfoControlList;
template <>
inline Policy Control<const osgIntrospection::Type*>::check(const osgIntrospection::Type* type) const
{
const osgIntrospection::Type* typeCheck = ((type->isPointer()) ? (&type->getPointedType()) : (type));
if ((typeCheck == _t) || (typeCheck->isSubclassOf(*_t)))
return (_policy);
return (Next);
}
}
#endif // ** __CONTROLLIST_H__ ** //
See more files for this project here