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 ResizeSubDataArray( ULONG in_index, ULONG in_ulSize, CBaseICEAttributeDataArray& out_dataArray )
    00188     {
    00189         if( m_attrib.IsReadonly() )
    00190             return CStatus::AccessDenied;
    00191
    00192         CStatus st = m_attrib.ResizeSubDataArray((CBaseICEAttributeDataArray&)*this, in_index, in_ulSize, out_dataArray );
    00193         assert( st == CStatus::OK );
    00194         return st;
    00195     }
    00196
    00197     CStatus GetCustomTypeData( ULONG in_nIndex, const unsigned char** out_ppData, ULONG& out_nSize ) const
    00198     {
    00199         if ( GetStructureType() == XSI::siICENodeStructureSingle )
    00200         {
    00201             return m_attrib.GetCustomTypeData( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
    00202         }
    00203         return m_attrib.GetCustomTypeData2D( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
    00204     }
    00205
    00206     CStatus GetStringData( ULONG in_nIndex, const wchar_t** out_ppData, ULONG& out_nSize ) const
    00207     {
    00208         if ( GetStructureType() == XSI::siICENodeStructureSingle )
    00209         {
    00210             return m_attrib.GetStringData( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
    00211         }
    00212         return m_attrib.GetStringData2D( (CBaseICEAttributeDataArray&)*this, in_nIndex, out_ppData, out_nSize );
    00213     }
    00214
    00215     CStatus SetStringData( ULONG in_nIndex, const wchar_t* in_pData, ULONG in_nSize )
    00216     {
    00217         return m_attrib.SetStringData( (CBaseICEAttributeDataArray&)*this, in_nIndex, in_pData, in_nSize );
    00218     }
    00219
    00220     ULONG           m_nCount;
    00221     CBitsetHelper   m_bitset;
    00222     bool            m_bIsConstant;
    00223
    00224 private:
    00225     ULONG                       m_nAccessIndex;
    00226     ULONG                       m_nHandle;
    00227     void*                       m_pData;
    00228     XSI::siICENodeStructureType m_structType;
    00229     XSI::siICENodeDataType      m_dataType;
    00230     ICEAttribute                m_attrib;
    00231     CBaseICEAttributeDataArray* m_pParent;
    00232 };
    00233
    00234 //*****************************************************************************
    00295 //*****************************************************************************
    00296 template<class T>
    00297 class CICEAttributeDataArray : public CBaseICEAttributeDataArray
    00298 {
    00299 public:
    00300
    00302     CICEAttributeDataArray( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle ) {}
    00303
    00305     ~CICEAttributeDataArray( ) {}
    00306
    00312     const T& operator[]( ULONG in_index ) const
    00313     {
    00314         const T* pData = (const T*)GetDataPtr();
    00315         assert( pData != NULL || in_index < GetCount() );
    00316
    00317         if (!pData)
    00318         {
    00319             static T defVal;
    00320             return defVal;
    00321         }
    00322
    00323         if (m_bIsConstant)
    00324         {
    00325             return *pData;
    00326         }
    00327
    00328         return pData[in_index];
    00329     }
    00330
    00337     T& operator[]( ULONG in_index )
    00338     {
    00339         T* pData = (T*) GetDataPtr();
    00340         assert( pData != NULL || in_index < GetCount() );
    00341
    00342         if (!pData || in_index >=  GetCount() || GetICEAttributeRef().IsReadonly() )
    00343         {
    00344             static T defVal;
    00345             return defVal;
    00346         }
    00347
    00348         if (m_bIsConstant)
    00349         {
    00350             return  pData[0];
    00351         }
    00352
    00353         return pData[in_index];
    00354     }
    00355
    00356
    00357 private:
    00358     static XSI::siICENodeDataType GetDefaultType( );
    00359
    00360 };
    00361
    00362 //*****************************************************************************
    00363 // NB: Do not use the Doxygen \class tag for this template!!!
    00368 //*****************************************************************************
    00369 template<>
    00370 class CICEAttributeDataArray<bool> : public CBaseICEAttributeDataArray
    00371 {
    00372 public:
    00374     CICEAttributeDataArray<bool>( ) :
    00375         CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
    00376     {}
    00377
    00379     ~CICEAttributeDataArray<bool>( ) {}
    00380
    00386     const bool operator[]( ULONG in_index ) const
    00387     {
    00388         return m_bitset.GetBit( in_index );
    00389     }
    00390
    00399     CStatus SetData( ULONG in_nIndex, bool in_bVal )
    00400     {
    00401         if( in_nIndex >=  GetCount() )
    00402             return CStatus::InvalidArgument;
    00403
    00404         if( GetICEAttributeRef().IsReadonly() )
    00405             return CStatus::AccessDenied;
    00406
    00407         return m_bitset.SetBit( in_nIndex, in_bVal );
    00408     }
    00409
    00410 private:
    00411     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
    00412     {
    00413         return siICENodeDataBool;
    00414     }
    00415 };
    00416
    00417 //*****************************************************************************
    00452 //*****************************************************************************
    00453
    00454 class CICEAttributeDataArrayCustomType : public CBaseICEAttributeDataArray
    00455 {
    00456     public:
    00457     typedef unsigned char TData;
    00458
    00461     SICPPSDK_INLINE CICEAttributeDataArrayCustomType( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
    00462     {}
    00463
    00466     SICPPSDK_INLINE ~CICEAttributeDataArrayCustomType( )
    00467     {}
    00468
    00478     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, const TData** out_ppData, ULONG& out_nSize  ) const;
    00479
    00480 private:
    00481     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
    00482     {
    00483         return siICENodeDataCustomType;
    00484     }
    00485 };
    00486
    00487 CStatus CICEAttributeDataArrayCustomType::GetData( ULONG in_nIndex, const TData** out_ppData, ULONG& out_nSize  ) const
    00488 {
    00489     return GetCustomTypeData( in_nIndex, out_ppData, out_nSize );
    00490 }
    00491
    00492 //*****************************************************************************
    00526 //*****************************************************************************
    00527
    00528 class CICEAttributeDataArrayString : public CBaseICEAttributeDataArray
    00529 {
    00530     public:
    00531     typedef wchar_t TData;
    00532
    00535     SICPPSDK_INLINE CICEAttributeDataArrayString( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
    00536     {}
    00537
    00540     SICPPSDK_INLINE ~CICEAttributeDataArrayString( )
    00541     {}
    00542
    00555     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, const TData** out_ppStr, ULONG& out_nCount ) const;
    00556
    00562     SICPPSDK_INLINE CStatus GetData( ULONG in_nIndex, CString& out_str ) const;
    00563     SICPPSDK_INLINE CStatus SetData( ULONG in_nIndex, const CString& in_str );
    00564
    00570     SICPPSDK_INLINE CString operator[]( ULONG in_nIndex ) const;
    00571
    00572 private:
    00573     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
    00574     {
    00575         return siICENodeDataString;
    00576     }
    00577 };
    00578
    00579 CStatus CICEAttributeDataArrayString::GetData( ULONG in_nIndex, const TData** out_ppStr, ULONG& out_nCount ) const
    00580 {
    00581     return GetStringData( in_nIndex, out_ppStr, out_nCount );
    00582 }
    00583
    00584 SICPPSDK_INLINE CStatus CICEAttributeDataArrayString::GetData( ULONG in_nIndex, CString& out_str ) const
    00585 {
    00586     const wchar_t* pzStr;
    00587     ULONG nSize;
    00588     CStatus st = GetStringData( in_nIndex, &pzStr, nSize );
    00589     out_str = CString( pzStr, nSize );
    00590     return st;
    00591 }
    00592
    00593 SICPPSDK_INLINE CStatus CICEAttributeDataArrayString::SetData( ULONG in_nIndex, const CString& in_str )
    00594 {
    00595     if( in_nIndex >=  GetCount() )
    00596         return CStatus::InvalidArgument;
    00597
    00598     if( GetICEAttributeRef().IsReadonly() )
    00599         return CStatus::AccessDenied;
    00600
    00601     return SetStringData( in_nIndex, in_str.GetWideString(), in_str.Length() );
    00602 }
    00603
    00604 SICPPSDK_INLINE CString CICEAttributeDataArrayString::operator[]( ULONG i ) const
    00605 {
    00606     CString str;
    00607     GetData( i, str );
    00608     return str;
    00609 }
    00610
    00688 typedef XSI::CICEAttributeDataArray< float > CICEAttributeDataArrayFloat;
    00689 typedef XSI::CICEAttributeDataArray< LONG > CICEAttributeDataArrayLong;
    00690 typedef XSI::CICEAttributeDataArray< bool > CICEAttributeDataArrayBool;
    00691 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector2f > CICEAttributeDataArrayVector2f;
    00692 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector3f > CICEAttributeDataArrayVector3f;
    00693 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector4f > CICEAttributeDataArrayVector4f;
    00694 typedef XSI::CICEAttributeDataArray< XSI::MATH::CQuaternionf > CICEAttributeDataArrayQuaternionf;
    00695 typedef XSI::CICEAttributeDataArray< XSI::MATH::CRotationf > CICEAttributeDataArrayRotationf;
    00696 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix3f > CICEAttributeDataArrayMatrix3f;
    00697 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix4f > CICEAttributeDataArrayMatrix4f;
    00698 typedef XSI::CICEAttributeDataArray< XSI::MATH::CColor4f > CICEAttributeDataArrayColor4f;
    00699 typedef XSI::CICEAttributeDataArray< XSI::MATH::CShape> CICEAttributeDataArrayShape;
    00700
    00701 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayFloat::GetDefaultType( ){return siICENodeDataFloat;}
    00702 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayLong::GetDefaultType( ){return siICENodeDataLong;}
    00703 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector2f::GetDefaultType( ){return siICENodeDataVector2;}
    00704 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector3f::GetDefaultType( ){return siICENodeDataVector3;}
    00705 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector4f::GetDefaultType( ){return siICENodeDataVector4;}
    00706 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayQuaternionf::GetDefaultType( ){return siICENodeDataQuaternion;}
    00707 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix3f::GetDefaultType( ){return siICENodeDataMatrix33;}
    00708 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix4f::GetDefaultType( ){return siICENodeDataMatrix44;}
    00709 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayColor4f::GetDefaultType( ){return siICENodeDataColor4;}
    00710 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayRotationf::GetDefaultType( ){return siICENodeDataRotation;}
    00711 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayShape::GetDefaultType( ){return siICENodeDataShape;}
    00712
    00713 };
    00714
    00715 #endif // __XSIICEATTRIBUTEDATAARRAY_H__