xsi_iceattributedataarray.h
Go to the documentation of this file.
00001 //*****************************************************************************
00011 //*****************************************************************************
00012 
00013 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00014 #pragma once
00015 #endif
00016 
00017 #ifndef __XSIICEATTRIBUTEDATAARRAY_H__
00018 #define __XSIICEATTRIBUTEDATAARRAY_H__
00019 
00020 #include <sicppsdk.h>
00021 #include <xsi_iceattribute.h>
00022 #include <xsi_vector2f.h>
00023 #include <xsi_vector3f.h>
00024 #include <xsi_vector4f.h>
00025 #include <xsi_quaternionf.h>
00026 #include <xsi_rotationf.h>
00027 #include <xsi_matrix3f.h>
00028 #include <xsi_matrix4f.h>
00029 #include <xsi_color4f.h>
00030 #include <xsi_shape.h>
00031 #include <xsi_indexset.h>
00032 
00033 namespace XSI {
00034 
00035 //*****************************************************************************
00068 //*****************************************************************************
00069 
00070 class CBaseICEAttributeDataArray
00071 {
00072 public:
00073     friend class ICEAttribute;
00074 
00075     CBaseICEAttributeDataArray( XSI::siICENodeDataType in_dataType, XSI::siICENodeStructureType in_structType )
00076         :   m_nCount(0),
00077             m_bIsConstant(false),
00078             m_nAccessIndex(UINT_MAX),
00079             m_nHandle(0),
00080             m_pData(NULL),
00081             m_structType( in_structType ),
00082             m_dataType( in_dataType ),
00083             m_pParent(NULL)
00084     {}
00085 
00089     ULONG GetCount() const
00090     {
00091         return m_nCount;
00092     }
00093 
00097     bool IsConstant() const
00098     {
00099         return m_bIsConstant;
00100     }
00101 
00105     XSI::siICENodeDataType GetDataType() const
00106     {
00107         return m_dataType;
00108     }
00109 
00113     XSI::siICENodeStructureType GetStructureType() const
00114     {
00115         return m_pParent ? m_pParent->GetStructureType( ) : m_structType;
00116     }
00117 
00118     virtual ~CBaseICEAttributeDataArray()
00119     {
00120         m_attrib.ReleaseDataArray( *this );
00121     }
00122 
00123 protected:
00124     const void* GetDataPtr( ) const
00125     {
00126         return (const void*)m_pData;
00127     }
00128 
00129     ULONG GetHandle() const
00130     {
00131         return m_pParent ? m_pParent->GetHandle( ) : m_nHandle;
00132     }
00133 
00134     ULONG GetAccessIndex() const
00135     {
00136         return m_pParent ? m_pParent->GetAccessIndex( ) : m_nAccessIndex;
00137     }
00138 
00139     void*& GetDataRef( )
00140     {
00141         return m_pData;
00142     }
00143 
00144     ULONG& GetHandleRef()
00145     {
00146         return m_nHandle;
00147     }
00148 
00149     ULONG& GetCountRef()
00150     {
00151         return m_nCount;
00152     }
00153 
00154     ICEAttribute& GetICEAttributeRef()
00155     {
00156         return m_attrib;
00157     }
00158 
00159     CBitsetHelper& GetBitsetRef()
00160     {
00161         return m_bitset;
00162     }
00163 
00164     bool& GetConstantRef()
00165     {
00166         return m_bIsConstant;
00167     }
00168 
00169     void SetParent( CBaseICEAttributeDataArray* in_pParent )
00170     {
00171         m_pParent = in_pParent;
00172     }
00173 
00174     ULONG& GetAccessIndexRef()
00175     {
00176         return m_nAccessIndex;
00177     }
00178 
00179 protected:
00180     CStatus GetSubDataArray( ULONG in_index, CBaseICEAttributeDataArray& out_dataArray ) const
00181     {
00182         CStatus st = m_attrib.GetSubDataArray( (CBaseICEAttributeDataArray&)*this, in_index, out_dataArray );
00183         assert( st == CStatus::OK );
00184         return st;
00185     }
00186 
00187     CStatus GetCustomTypeData( ULONG in_nIndex, const unsigned char** out_ppData, ULONG& out_nSize ) const
00188     {
00189         if ( GetStructureType() == XSI::siICENodeStructureSingle )
00190         {
00191             return m_attrib.GetCustomTypeData( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
00192         }
00193         return m_attrib.GetCustomTypeData2D( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
00194     }
00195 
00196     CStatus GetStringData( ULONG in_nIndex, const wchar_t** out_ppData, ULONG& out_nSize ) const
00197     {
00198         if ( GetStructureType() == XSI::siICENodeStructureSingle )
00199         {
00200             return m_attrib.GetStringData( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
00201         }
00202         return m_attrib.GetStringData2D( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
00203     }
00204 
00205     ULONG           m_nCount;
00206     CBitsetHelper   m_bitset;
00207     bool            m_bIsConstant;
00208 
00209 private:
00210     ULONG                       m_nAccessIndex;
00211     ULONG                       m_nHandle;
00212     void*                       m_pData;
00213     XSI::siICENodeStructureType m_structType;
00214     XSI::siICENodeDataType      m_dataType;
00215     ICEAttribute                m_attrib;
00216     CBaseICEAttributeDataArray* m_pParent;
00217 };
00218 
00219 //*****************************************************************************
00280 //*****************************************************************************
00281 template<class T>
00282 class CICEAttributeDataArray : public CBaseICEAttributeDataArray
00283 {
00284 public:
00285 
00287     CICEAttributeDataArray( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle ) {}
00288 
00290     ~CICEAttributeDataArray( ) {}
00291 
00297     const T& operator[]( ULONG in_index ) const
00298     {
00299         const T* pData = (const T*)GetDataPtr();
00300         assert( pData != NULL || in_index < GetCount() );
00301 
00302         if (!pData) 
00303         {
00304             assert( pData != NULL );
00305             static T defVal;
00306             return defVal;
00307         }
00308         
00309         if (m_bIsConstant) 
00310         {
00311             return *pData;
00312         }
00313         
00314         return pData[in_index];     
00315     }
00316 
00317 private:
00318     static XSI::siICENodeDataType GetDefaultType( );
00319 
00320 };
00321 
00322 //*****************************************************************************
00323 // NB: Do not use the Doxygen \class tag for this template!!!
00328 //*****************************************************************************
00329 template<>
00330 class CICEAttributeDataArray<bool> : public CBaseICEAttributeDataArray
00331 {
00332 public:
00334     CICEAttributeDataArray<bool>( ) :
00335         CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00336     {}
00337 
00339     ~CICEAttributeDataArray<bool>( ) {}
00340 
00346     const bool operator[]( ULONG in_index ) const
00347     {
00348         return m_bitset.GetBit( in_index );
00349     }
00350 
00351 private:
00352     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
00353     {
00354         return siICENodeDataBool;
00355     }
00356 };
00357 
00358 //*****************************************************************************
00393 //*****************************************************************************
00394 
00395 class CICEAttributeDataArrayCustomType : public CBaseICEAttributeDataArray
00396 {
00397     public:
00398     typedef unsigned char TData;
00399 
00402     SICPPSDK_INLINE CICEAttributeDataArrayCustomType( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00403     {}
00404 
00407     SICPPSDK_INLINE ~CICEAttributeDataArrayCustomType( )
00408     {}
00409 
00419     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, const TData** out_ppData, ULONG& out_nSize  ) const;
00420 
00421 private:
00422     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
00423     {
00424         return siICENodeDataCustomType;
00425     }
00426 };
00427 
00428 CStatus CICEAttributeDataArrayCustomType::GetData( ULONG in_nIndex, const TData** out_ppData, ULONG& out_nSize  ) const
00429 {
00430     return GetCustomTypeData( in_nIndex, out_ppData, out_nSize );
00431 }
00432 
00433 //*****************************************************************************
00467 //*****************************************************************************
00468 
00469 class CICEAttributeDataArrayString : public CBaseICEAttributeDataArray
00470 {
00471     public:
00472     typedef wchar_t TData;
00473 
00476     SICPPSDK_INLINE CICEAttributeDataArrayString( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00477     {}
00478 
00481     SICPPSDK_INLINE ~CICEAttributeDataArrayString( )
00482     {}
00483 
00496     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, const TData** out_ppStr, ULONG& out_nCount ) const;
00497 
00503     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, CString& out_str ) const;
00504 
00510     SICPPSDK_INLINE CString operator[]( ULONG in_nIndex ) const;
00511 
00512 private:
00513     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
00514     {
00515         return siICENodeDataString;
00516     }
00517 };
00518 
00519 CStatus CICEAttributeDataArrayString::GetData( ULONG in_nIndex, const TData** out_ppStr, ULONG& out_nCount ) const
00520 {
00521     return GetStringData( in_nIndex, out_ppStr, out_nCount );
00522 }
00523 
00524 SICPPSDK_INLINE CStatus CICEAttributeDataArrayString::GetData( ULONG in_nIndex, CString& out_str ) const
00525 {
00526     const wchar_t* pzStr;
00527     ULONG nSize;
00528     CStatus st = GetStringData( in_nIndex, &pzStr, nSize );
00529     out_str = CString( pzStr, nSize );
00530     return st;
00531 }
00532 
00533 SICPPSDK_INLINE CString CICEAttributeDataArrayString::operator[]( ULONG i ) const
00534 {
00535     CString str;
00536     GetData( i, str );
00537     return str;
00538 }
00539 
00617 typedef XSI::CICEAttributeDataArray< float > CICEAttributeDataArrayFloat;
00618 typedef XSI::CICEAttributeDataArray< LONG > CICEAttributeDataArrayLong;
00619 typedef XSI::CICEAttributeDataArray< bool > CICEAttributeDataArrayBool;
00620 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector2f > CICEAttributeDataArrayVector2f;
00621 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector3f > CICEAttributeDataArrayVector3f;
00622 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector4f > CICEAttributeDataArrayVector4f;
00623 typedef XSI::CICEAttributeDataArray< XSI::MATH::CQuaternionf > CICEAttributeDataArrayQuaternionf;
00624 typedef XSI::CICEAttributeDataArray< XSI::MATH::CRotationf > CICEAttributeDataArrayRotationf;
00625 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix3f > CICEAttributeDataArrayMatrix3f;
00626 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix4f > CICEAttributeDataArrayMatrix4f;
00627 typedef XSI::CICEAttributeDataArray< XSI::MATH::CColor4f > CICEAttributeDataArrayColor4f;
00628 typedef XSI::CICEAttributeDataArray< XSI::MATH::CShape> CICEAttributeDataArrayShape;
00629 
00630 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayFloat::GetDefaultType( ){return siICENodeDataFloat;}
00631 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayLong::GetDefaultType( ){return siICENodeDataLong;}
00632 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector2f::GetDefaultType( ){return siICENodeDataVector2;}
00633 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector3f::GetDefaultType( ){return siICENodeDataVector3;}
00634 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector4f::GetDefaultType( ){return siICENodeDataVector4;}
00635 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayQuaternionf::GetDefaultType( ){return siICENodeDataQuaternion;}
00636 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix3f::GetDefaultType( ){return siICENodeDataMatrix33;}
00637 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix4f::GetDefaultType( ){return siICENodeDataMatrix44;}
00638 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayColor4f::GetDefaultType( ){return siICENodeDataColor4;}
00639 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayRotationf::GetDefaultType( ){return siICENodeDataRotation;}
00640 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayShape::GetDefaultType( ){return siICENodeDataShape;}
00641 
00642 };
00643 
00644 #endif // __XSIICEATTRIBUTEDATAARRAY_H__