SL_Enum.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #ifndef __SL_ENUM_H__
00013 #define __SL_ENUM_H__
00014 
00015 #if defined(_WIN32) || defined (_WIN32_WCE) || defined(_XBOX)
00016 // Disable "identifier was truncated to '255' characters in the debug information" warning.
00017 #pragma warning( disable : 4786 )
00018 #endif // defined(_WIN32) || defined (_WIN32_WCE)
00019 
00020 #include "SL_Int.h"         // CSLIntProxy
00021 #include "SL_String.h"      // CSLStringProxy
00022 #include "EnumDictionary.h" // CEnumDictionary
00023 
00025 template <class EnumType, SI_Int MaxValue>
00026 class XSIEXPORT CSLEnumProxy
00027     : public CSLAnimatableType
00028 {
00029 public:
00034     CSLEnumProxy(CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00035 
00040     CSLEnumProxy& operator =(const CSLEnumProxy &in_Value);
00041 
00046     CSLEnumProxy& operator =(const EnumType &in_Value);
00047 
00052     SI_Bool operator ==(const CSLEnumProxy &in_ToCompare);
00053 
00058     SI_Bool operator ==(const EnumType &in_ToCompare);
00059 
00061 
00065     SI_Bool IsValid();
00066 
00068 
00071     operator EnumType();
00072 
00076     virtual EElementType Type();
00077 
00081     virtual SI_Float GetFloatValue();
00082 
00086     virtual SI_Void SetFloatValue(SI_Float in_fValue);
00087 
00093     virtual SI_Error    Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00094 
00098     virtual CdotXSIParam*   ParameterReference();
00099 
00100 private:
00101     CSLEnumProxy( CSLEnumProxy &in_pBasicType ){}
00102     CSLIntProxy m_Value;
00103 };
00104 
00106 template <class EnumType, SI_Int MaxValue>
00107 class CSLStrEnumProxy
00108     : public CSLAnimatableType
00109 {
00110 public:
00115     CSLStrEnumProxy(CdotXSITemplate *in_pTemplate, SI_Int in_nIndex, CEnumDictionary<EnumType, MaxValue> *in_pDictionary);
00116 
00121     CSLStrEnumProxy& operator =(const CSLStrEnumProxy &in_Value);
00122 
00127     CSLStrEnumProxy& operator =(const EnumType &in_Value);
00128 
00134     SI_Bool operator ==(const CSLStrEnumProxy &in_ToCompare);
00135 
00140     SI_Bool operator ==(const EnumType &in_ToCompare);
00141 
00143 
00147     SI_Bool IsValid();
00148 
00150 
00153     operator EnumType();
00154 
00158     virtual EElementType Type();
00159     
00163     virtual SI_Float GetFloatValue();
00164 
00168     virtual SI_Void SetFloatValue(SI_Float in_fValue);
00169 
00175     SI_Error    Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex );
00176 
00177 private:
00178     CSLStrEnumProxy( CSLStrEnumProxy &in_pBasicType ){}
00179 
00180     CEnumDictionary<EnumType, MaxValue> *m_pDictionary;
00181     EnumType m_EnumValue;
00182     CSLStringProxy m_StringValue;
00183 };
00184 
00185 
00187 // template implementation
00189 
00190 template <class EnumType, SI_Int MaxValue>
00191 CSLEnumProxy<EnumType,MaxValue>::CSLEnumProxy
00192 (
00193     CdotXSITemplate *in_pTemplate, 
00194     SI_Int in_nIndex 
00195 ) : m_Value(in_pTemplate, in_nIndex)
00196 {
00197     if ( in_pTemplate )
00198         Connect(in_pTemplate, in_nIndex );
00199 }
00200 template <class EnumType, SI_Int MaxValue>
00201 SI_Error    CSLEnumProxy<EnumType,MaxValue>::Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex )
00202 {
00203     m_Value.Connect(in_pTemplate,in_nIndex);
00204     return 0;
00205 }
00206 
00207 
00208 template <class EnumType, SI_Int MaxValue>
00209 inline CSLEnumProxy<EnumType,MaxValue>& CSLEnumProxy<EnumType,MaxValue>::operator =
00210 (
00211     const CSLEnumProxy &in_Value
00212 )
00213 {
00214     m_Value = in_Value.m_Value;
00215     return *this;
00216 }
00217 
00218 template <class EnumType, SI_Int MaxValue>
00219 inline CSLEnumProxy<EnumType,MaxValue>& CSLEnumProxy<EnumType,MaxValue>::operator =
00220 (
00221     const EnumType &in_Value
00222 )
00223 {
00224     m_Value = in_Value;
00225     return *this;
00226 }
00227 
00228 template <class EnumType, SI_Int MaxValue>
00229 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::operator ==
00230 (
00231     const CSLEnumProxy<EnumType,MaxValue> &in_ToCompare
00232 )
00233 {
00234     return m_Value == in_ToCompare.m_Value;
00235 }
00236 
00237 template <class EnumType, SI_Int MaxValue>
00238 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::operator ==
00239 (
00240     const EnumType &in_nToCompare
00241 )
00242 {
00243     return m_Value == in_nToCompare;
00244 }
00245 
00246 template <class EnumType, SI_Int MaxValue>
00247 inline CSLEnumProxy<EnumType,MaxValue>::operator EnumType()
00248 {
00249     return (EnumType)((SI_Int)m_Value);
00250 }
00251 
00252 template <class EnumType, SI_Int MaxValue>
00253 inline SI_Bool CSLEnumProxy<EnumType,MaxValue>::IsValid
00254 (
00255 )
00256 {
00257     return m_Value <= MaxValue;
00258 }
00259 
00260 template <class EnumType, SI_Int MaxValue>
00261 CSLAnimatableType::EElementType CSLEnumProxy<EnumType,MaxValue>::Type
00262 (
00263 )
00264 {
00265     return SI_ENUM_TYPE;
00266 }
00267 
00268 template <class EnumType, SI_Int MaxValue>
00269 SI_Float CSLEnumProxy<EnumType,MaxValue>::GetFloatValue
00270 (
00271 )
00272 {
00273     return (SI_Float) ( (SI_Int) m_Value);
00274 }
00275 
00276 template <class EnumType, SI_Int MaxValue>
00277 SI_Void CSLEnumProxy<EnumType,MaxValue>::SetFloatValue
00278 (
00279     SI_Float    in_fValue
00280 )
00281 {
00282     if(in_fValue <= MaxValue)
00283     {
00284         m_Value = (SI_Int) in_fValue;
00285     }
00286 }
00287 
00288 template <class EnumType, SI_Int MaxValue>
00289 CdotXSIParam* CSLEnumProxy<EnumType,MaxValue>::ParameterReference()
00290 {
00291     return m_Value.ParameterReference();
00292 }
00293 
00295 
00296 template <class EnumType, SI_Int MaxValue>
00297 CSLStrEnumProxy<EnumType,MaxValue>::CSLStrEnumProxy
00298 (
00299     CdotXSITemplate *in_pTemplate, 
00300     SI_Int in_nIndex, 
00301     CEnumDictionary<EnumType, MaxValue> *in_pDictionary
00302 ) : m_StringValue(in_pTemplate, in_nIndex)
00303   , m_pDictionary(in_pDictionary)
00304 {
00305     // if the string is invalid
00306     if (!m_pDictionary->ToEnum( m_EnumValue, m_StringValue ))
00307     {
00308         // set the enum to an invalid value,
00309         m_EnumValue = (EnumType)(MaxValue + 1);
00310     }
00311 }
00312 template <class EnumType, SI_Int MaxValue>
00313 SI_Error CSLStrEnumProxy<EnumType,MaxValue>::Connect( CdotXSITemplate *in_pTemplate, SI_Int in_nIndex )
00314 {
00315     m_StringValue.Connect(in_pTemplate, in_nIndex);
00316     if (!m_pDictionary->ToEnum( m_EnumValue, m_StringValue ))
00317     {
00318         // set the enum to an invalid value,
00319         m_EnumValue = (EnumType)(MaxValue + 1);
00320     }
00321 
00322     return 0;
00323 }
00324 
00325 
00326 template <class EnumType, SI_Int MaxValue>
00327 inline CSLStrEnumProxy<EnumType,MaxValue>& CSLStrEnumProxy<EnumType,MaxValue>::operator =
00328 (
00329     const CSLStrEnumProxy &in_Value
00330 )
00331 {
00332     m_EnumValue = in_Value.m_EnumValue;
00333     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00334     
00335     return *this;
00336 }
00337 
00338 template <class EnumType, SI_Int MaxValue>
00339 inline CSLStrEnumProxy<EnumType,MaxValue>& CSLStrEnumProxy<EnumType,MaxValue>::operator =
00340 (
00341     const EnumType &in_Value
00342 )
00343 {
00344     m_EnumValue = in_Value;
00345     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00346     
00347     return *this;
00348 }
00349 
00350 template <class EnumType, SI_Int MaxValue>
00351 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::operator ==
00352 (
00353     const CSLStrEnumProxy<EnumType,MaxValue> &in_ToCompare
00354 )
00355 {
00356     return m_EnumValue == in_ToCompare.m_EnumValue;
00357 }
00358 
00359 template <class EnumType, SI_Int MaxValue>
00360 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::operator ==
00361 (
00362     const EnumType &in_nToCompare
00363 )
00364 {
00365     return m_EnumValue == in_nToCompare;
00366 }
00367 
00368 template <class EnumType, SI_Int MaxValue>
00369 inline CSLStrEnumProxy<EnumType,MaxValue>::operator EnumType()
00370 {
00371     return m_EnumValue;
00372 }
00373 
00374 template <class EnumType, SI_Int MaxValue>
00375 inline SI_Bool CSLStrEnumProxy<EnumType,MaxValue>::IsValid
00376 (
00377 )
00378 {
00379     return m_EnumValue <= MaxValue;
00380 }
00381 
00382 template <class EnumType, SI_Int MaxValue>
00383 CSLAnimatableType::EElementType CSLStrEnumProxy<EnumType,MaxValue>::Type
00384 (
00385 )
00386 {
00387     return SI_STRING_ENUM_TYPE;
00388 }
00389 
00390 template <class EnumType, SI_Int MaxValue>
00391 SI_Float CSLStrEnumProxy<EnumType,MaxValue>::GetFloatValue
00392 (
00393 )
00394 {
00395     return (SI_Float) m_EnumValue;
00396 }
00397 
00398 template <class EnumType, SI_Int MaxValue>
00399 SI_Void CSLStrEnumProxy<EnumType,MaxValue>::SetFloatValue
00400 (
00401     SI_Float    in_fValue
00402 )
00403 {
00404     m_EnumValue = (EnumType) ( (SI_Int) in_fValue);
00405     m_StringValue = m_pDictionary->ToString( m_EnumValue );
00406 }
00407 
00408 #endif //__SL_ENUM_H__