00001 #ifndef ATTR__ATTRID_TYPED_H
00002 #define ATTR__ATTRID_TYPED_H
00003
00015 #include "attr/_attrid.h"
00016
00017
00018 template <class _AttrIdType>
00019 class _attridTyped : public _attrid
00020 {
00021 public:
00023 _attridTyped(const char* name, Type t, uchar flags);
00025 ~_attridTyped();
00026
00027
00029 static _attridTyped<_AttrIdType>* Find( const nString& name );
00030
00031 protected:
00033 _attridTyped();
00034
00036 void AddToRegistry();
00038 void RemoveFromRegistry();
00039
00040 static nArray<_attridTyped<_AttrIdType>*>* attrIdRegistry;
00041 };
00042
00043
00044
00045 #define _DeclareAttribute( id, type ) extern const type id ## Data; extern const type* id
00046
00047 #define _DefineAttribute( id, typeConstant, type )\
00048 const type id ## Data (#id, typeConstant, _attrid::Read|_attrid::Write);\
00049 const type* id = & id ## Data
00050
00051 #define _DefineStorableAttribute( id, typeConstant, type )\
00052 const type id ## Data (#id, typeConstant, _attrid::Read|_attrid::Write|_attrid::Store);\
00053 const type* id = & id ## Data
00054
00055 #define DeclareVoid(id) _DeclareAttribute( id, _attridTyped<attr::VoidT> );
00056 #define DefineVoid(id) _DefineAttribute( id, _attrid::Void, _attridTyped<attr::VoidT> );
00057 #define DefineStorableVoid(id) _DefineStorableAttribute( id, _attrid::Void, _attridTyped<attr::VoidT> );
00058
00059 #define DeclareBool(id) _DeclareAttribute( id, _attridTyped<attr::BoolT> );
00060 #define DefineBool(id) _DefineAttribute( id, _attrid::Bool, _attridTyped<attr::BoolT> );
00061 #define DefineStorableBool(id) _DefineStorableAttribute( id, _attrid::Bool, _attridTyped<attr::BoolT> );
00062
00063 #define DeclareInt(id) _DeclareAttribute( id, _attridTyped<attr::IntT> );
00064 #define DefineInt(id) _DefineAttribute( id, _attrid::Int, _attridTyped<attr::IntT> );
00065 #define DefineStorableInt(id) _DefineStorableAttribute( id, _attrid::Int, _attridTyped<attr::IntT> );
00066
00067 #define DeclareFloat(id) _DeclareAttribute( id, _attridTyped<attr::FloatT> );
00068 #define DefineFloat(id) _DefineAttribute( id, _attrid::Float, _attridTyped<attr::FloatT> );
00069 #define DefineStorableFloat(id) _DefineStorableAttribute( id, _attrid::Float, _attridTyped<attr::FloatT> );
00070
00071 #define DeclareString(id) _DeclareAttribute( id, _attridTyped<attr::StringT> );
00072 #define DefineString(id) _DefineAttribute( id, _attrid::String, _attridTyped<attr::StringT> );
00073 #define DefineStorableString(id) _DefineStorableAttribute( id, _attrid::String, _attridTyped<attr::StringT> );
00074
00075 #define DeclareVector3(id) _DeclareAttribute( id, _attridTyped<attr::Vector3T> );
00076 #define DefineVector3(id) _DefineAttribute( id, _attrid::Vector3, _attridTyped<attr::Vector3T> );
00077 #define DefineStorableVector3(id) _DefineStorableAttribute( id, _attrid::Vector3, _attridTyped<attr::Vector3T> );
00078
00079 #define DeclareVector4(id) _DeclareAttribute( id, _attridTyped<attr::Vector4T> );
00080 #define DefineVector4(id) _DefineAttribute( id, _attrid::Vector4, _attridTyped<attr::Vector4T> );
00081 #define DefineStorableVector4(id) _DefineStorableAttribute( id, _attrid::Vector4, _attridTyped<attr::Vector4T> );
00082
00083 #define DeclareMatrix44(id) _DeclareAttribute( id, _attridTyped<attr::Matrix44T> );
00084 #define DefineMatrix44(id) _DefineAttribute( id, _attrid::Matrix44, _attridTyped<attr::Matrix44T> );
00085 #define DefineStorableMatrix44(id) _DefineStorableAttribute( id, _attrid::Matrix44, _attridTyped<attr::Matrix44T> );
00086
00087
00090 template <class _AttrIdType>
00091 _attridTyped<_AttrIdType>::_attridTyped() :
00092 _attrid()
00093 {
00094
00095 }
00096
00097
00098
00099
00100
00101
00102 template <class _AttrIdType>
00103 nArray<_attridTyped<_AttrIdType>*>* _attridTyped<_AttrIdType>::attrIdRegistry = 0;
00104
00105
00108 template <class _AttrIdType>
00109 _attridTyped<_AttrIdType>::_attridTyped(const char* n, Type t, uchar f) :
00110 _attrid( n, t, f )
00111 {
00112 AddToRegistry();
00113 }
00114
00115
00118 template <class _AttrIdType>
00119 _attridTyped<_AttrIdType>::~_attridTyped()
00120 {
00121 RemoveFromRegistry();
00122 }
00123
00124
00128 template <class _AttrIdType>
00129 void
00130 _attridTyped<_AttrIdType>::AddToRegistry()
00131 {
00132 if (0 == attrIdRegistry)
00133 {
00134 attrIdRegistry = n_new(nArray<_attridTyped<_AttrIdType>*>(ID_REGISTRY_SIZE, ID_REGISTRY_SIZE));
00135 }
00136 attrIdRegistry->Append(this);
00137 }
00138
00139
00144 template <class _AttrIdType>
00145 void
00146 _attridTyped<_AttrIdType>::RemoveFromRegistry()
00147 {
00148 n_assert(0 != attrIdRegistry);
00149
00150 typename nArray<_attridTyped<_AttrIdType>*>::iterator iter = attrIdRegistry->Find(this);
00151 n_assert(iter);
00152 attrIdRegistry->Erase(iter);
00153
00154
00155 if (0 == attrIdRegistry->Size())
00156 {
00157 n_delete(attrIdRegistry);
00158 attrIdRegistry = 0;
00159 }
00160 }
00161
00162
00163
00164
00173 template <class _AttrIdType>
00174 _attridTyped<_AttrIdType>*
00175 _attridTyped<_AttrIdType>::Find( const nString& n )
00176 {
00177
00178 if (!attrIdRegistry) return 0;
00179
00180 int i;
00181 int num = attrIdRegistry->Size();
00182 for (i = 0; i < num; i++)
00183 {
00184 if (attrIdRegistry->At(i)->GetName() == n)
00185 {
00186 return attrIdRegistry->At(i);
00187 }
00188 }
00189 return 0;
00190 }
00191
00192
00193 #endif