SL_Enum.h

Go to the documentation of this file.
00001 //***************************************************************************************
00002 // File supervisor: Crosswalk team
00012 //***************************************************************************************
00013 
00014 #ifndef __SL_ENUM_H__
00015 #define __SL_ENUM_H__
00016 
00017 #if defined(_WIN32) || defined (_WIN32_WCE) || defined(_XBOX)
00018 // Disable "identifier was truncated to '255' characters in the debug information" warning.
00019 #pragma warning( disable : 4786 )
00020 #endif // defined(_WIN32) || defined (_WIN32_WCE)
00021 
00022 #include "SL_Int.h"         // CSLIntProxy
00023 #include "SL_String.h"      // CSLStringProxy
00024 #include "EnumDictionary.h" // CEnumDictionary
00025 
00028 template <class EnumType, SI_Int MaxValue>
00029 class XSIEXPORT CSLEnumProxy
00030     : public CSLAnimatableType
00031 {
00032 public:
00037     CSLEnumProxy(CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00038 
00043     CSLEnumProxy& operator =(const CSLEnumProxy &in_Value);
00044 
00049     CSLEnumProxy& operator =(const EnumType &in_Value);
00050 
00055     SI_Bool operator ==(const CSLEnumProxy &in_ToCompare);
00056 
00061     SI_Bool operator ==(const EnumType &in_ToCompare);
00062 
00067     SI_Bool IsValid();
00068 
00072     operator EnumType();
00073 
00077     virtual EElementType Type();
00078 
00082     virtual SI_Float GetFloatValue();
00083 
00087     virtual SI_Void SetFloatValue(SI_Float in_fValue);
00088 
00094     virtual SI_Error    Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00095 
00099     virtual CdotXSIParam*   ParameterReference();
00100 
00101 private:
00102     CSLEnumProxy( CSLEnumProxy &in_pBasicType ){}
00103     CSLIntProxy m_Value;
00104 };
00105 
00108 template <class EnumType, SI_Int MaxValue>
00109 class CSLStrEnumProxy
00110     : public CSLAnimatableType
00111 {
00112 public:
00119     CSLStrEnumProxy(CdotXSITemplate *in_pTemplate, SI_Int in_nIndex, CEnumDictionary<EnumType, MaxValue> *in_pDictionary);
00120 
00125     CSLStrEnumProxy& operator =(const CSLStrEnumProxy &in_Value);
00126 
00131     CSLStrEnumProxy& operator =(const EnumType &in_Value);
00132 
00138     SI_Bool operator ==(const CSLStrEnumProxy &in_ToCompare);
00139 
00144     SI_Bool operator ==(const EnumType &in_ToCompare);
00145 
00150     SI_Bool IsValid();
00151 
00155     operator EnumType();
00156 
00160     virtual EElementType Type();
00161 
00165     virtual SI_Float GetFloatValue();
00166 
00170     virtual SI_Void SetFloatValue(SI_Float in_fValue);
00171 
00177     SI_Error    Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00178 
00179 private:
00180     CSLStrEnumProxy( CSLStrEnumProxy &in_pBasicType ){}
00181 
00182     CEnumDictionary<EnumType, MaxValue> *m_pDictionary;
00183     EnumType m_EnumValue;
00184     CSLStringProxy m_StringValue;
00185 };
00186 
00187 
00189 // template implementation
00191 
00192 template <class EnumType, SI_Int MaxValue>
00193 CSLEnumProxy<EnumType,MaxValue>::CSLEnumProxy
00194 (
00195     CdotXSITemplate *in_pTemplate,
00196     SI_Int in_nIndex
00197 ) : m_Value(in_pTemplate, in_nIndex)
00198 {
00199     if ( in_pTemplate )
00200         Connect(in_pTemplate, in_nIndex );
00201 }
00202 template <class EnumType, SI_Int MaxValue>
00203 SI_Error    CSLEnumProxy<EnumType,MaxValue>::Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex )
00204 {
00205     m_Value.Connect(in_pTemplate,in_nIndex);
00206     return 0;
00207 }
00208 
00209 
00210 template <class EnumType, SI_Int MaxValue>
00211 inline CSLEnumProxy<EnumType,MaxValue>& CSLEnumProxy<EnumType,MaxValue>::operator =
00212 (
00213     const CSLEnumProxy &in_Value
00214 )
00215 {
00216     m_Value = in_Value.m_Value;
00217     return *this;
00218 }
00219 
00220 template <class EnumType, SI_Int MaxValue>
00221 inline CSLEnumProxy<EnumType,MaxValue>& CSLEnumProxy<EnumType,MaxValue>::operator =
00222 (
00223     const EnumType &in_Value
00224 )
00225 {
00226     m_Value = in_Value;
00227     return *this;
00228 }
00229 
00230 template <class EnumType, SI_Int MaxValue>
00231 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::operator ==
00232 (
00233     const CSLEnumProxy<EnumType,MaxValue> &in_ToCompare
00234 )
00235 {
00236     return m_Value == in_ToCompare.m_Value;
00237 }
00238 
00239 template <class EnumType, SI_Int MaxValue>
00240 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::operator ==
00241 (
00242     const EnumType &in_nToCompare
00243 )
00244 {
00245     return m_Value == in_nToCompare;
00246 }
00247 
00248 template <class EnumType, SI_Int MaxValue>
00249 inline CSLEnumProxy<EnumType,MaxValue>::operator EnumType()
00250 {
00251     return (EnumType)((SI_Int)m_Value);
00252 }
00253 
00254 template <class EnumType, SI_Int MaxValue>
00255 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::IsValid
00256 (
00257 )
00258 {
00259     return m_Value <= MaxValue;
00260 }
00261 
00262 template <class EnumType, SI_Int MaxValue>
00263 CSLAnimatableType::EElementType CSLEnumProxy<EnumType,MaxValue>::Type
00264 (
00265 )
00266 {
00267     return SI_ENUM_TYPE;
00268 }
00269 
00270 template <class EnumType, SI_Int MaxValue>
00271 SI_Float CSLEnumProxy<EnumType,MaxValue>::GetFloatValue
00272 (
00273 )
00274 {
00275     return (SI_Float) ( (SI_Int) m_Value);
00276 }
00277 
00278 template <class EnumType, SI_Int MaxValue>
00279 SI_Void CSLEnumProxy<EnumType,MaxValue>::SetFloatValue
00280 (
00281     SI_Float    in_fValue
00282 )
00283 {
00284     if(in_fValue <= MaxValue)
00285     {
00286         m_Value = (SI_Int) in_fValue;
00287     }
00288 }
00289 
00290 template <class EnumType, SI_Int MaxValue>
00291 CdotXSIParam* CSLEnumProxy<EnumType,MaxValue>::ParameterReference()
00292 {
00293     return m_Value.ParameterReference();
00294 }
00295 
00297 
00298 template <class EnumType, SI_Int MaxValue>
00299 CSLStrEnumProxy<EnumType,MaxValue>::CSLStrEnumProxy
00300 (
00301     CdotXSITemplate *in_pTemplate,
00302     SI_Int in_nIndex,
00303     CEnumDictionary<EnumType, MaxValue> *in_pDictionary
00304 ) : m_StringValue(in_pTemplate, in_nIndex)
00305   , m_pDictionary(in_pDictionary)
00306 {
00307     // if the string is invalid
00308     if (!m_pDictionary->ToEnum( m_EnumValue, m_StringValue ))
00309     {
00310         // set the enum to an invalid value,
00311         m_EnumValue = (EnumType)(MaxValue + 1);
00312     }
00313 }
00314 template <class EnumType, SI_Int MaxValue>
00315 SI_Error CSLStrEnumProxy<EnumType,MaxValue>::Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex )
00316 {
00317     m_StringValue.Connect(in_pTemplate, in_nIndex);
00318     if (!m_pDictionary->ToEnum( m_EnumValue, m_StringValue ))
00319     {
00320         // set the enum to an invalid value,
00321         m_EnumValue = (EnumType)(MaxValue + 1);
00322     }
00323 
00324     return 0;
00325 }
00326 
00327 
00328 template <class EnumType, SI_Int MaxValue>
00329 inline CSLStrEnumProxy<EnumType,MaxValue>& CSLStrEnumProxy<EnumType,MaxValue>::operator =
00330 (
00331     const CSLStrEnumProxy &in_Value
00332 )
00333 {
00334     m_EnumValue = in_Value.m_EnumValue;
00335     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00336 
00337     return *this;
00338 }
00339 
00340 template <class EnumType, SI_Int MaxValue>
00341 inline CSLStrEnumProxy<EnumType,MaxValue>& CSLStrEnumProxy<EnumType,MaxValue>::operator =
00342 (
00343     const EnumType &in_Value
00344 )
00345 {
00346     m_EnumValue = in_Value;
00347     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00348 
00349     return *this;
00350 }
00351 
00352 template <class EnumType, SI_Int MaxValue>
00353 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::operator ==
00354 (
00355     const CSLStrEnumProxy<EnumType,MaxValue> &in_ToCompare
00356 )
00357 {
00358     return m_EnumValue == in_ToCompare.m_EnumValue;
00359 }
00360 
00361 template <class EnumType, SI_Int MaxValue>
00362 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::operator ==
00363 (
00364     const EnumType &in_nToCompare
00365 )
00366 {
00367     return m_EnumValue == in_nToCompare;
00368 }
00369 
00370 template <class EnumType, SI_Int MaxValue>
00371 inline CSLStrEnumProxy<EnumType,MaxValue>::operator EnumType()
00372 {
00373     return m_EnumValue;
00374 }
00375 
00376 template <class EnumType, SI_Int MaxValue>
00377 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::IsValid
00378 (
00379 )
00380 {
00381     return m_EnumValue <= MaxValue;
00382 }
00383 
00384 template <class EnumType, SI_Int MaxValue>
00385 CSLAnimatableType::EElementType CSLStrEnumProxy<EnumType,MaxValue>::Type
00386 (
00387 )
00388 {
00389     return SI_STRING_ENUM_TYPE;
00390 }
00391 
00392 template <class EnumType, SI_Int MaxValue>
00393 SI_Float CSLStrEnumProxy<EnumType,MaxValue>::GetFloatValue
00394 (
00395 )
00396 {
00397     return (SI_Float) m_EnumValue;
00398 }
00399 
00400 template <class EnumType, SI_Int MaxValue>
00401 SI_Void CSLStrEnumProxy<EnumType,MaxValue>::SetFloatValue
00402 (
00403     SI_Float    in_fValue
00404 )
00405 {
00406     m_EnumValue = (EnumType) ( (SI_Int) in_fValue);
00407     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00408 }
00409 
00410 #endif //__SL_ENUM_H__