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 #include <xsi_bitarray.h>
00033 
00034 namespace XSI {
00035 
00036 //*****************************************************************************
00069 //*****************************************************************************
00070 
00071 class SICPPSDKDECL CBaseICEAttributeDataArray
00072 {
00073 public:
00074     friend class ICEAttribute;
00075 
00076     CBaseICEAttributeDataArray( XSI::siICENodeDataType in_dataType, XSI::siICENodeStructureType in_structType )
00077         :   m_nCount(0),
00078             m_bIsConstant(false),
00079             m_nAccessIndex(UINT_MAX),
00080             m_nHandle(ULONG_MAX),
00081             m_pData(NULL),
00082             m_structType( in_structType ),
00083             m_dataType( in_dataType ),
00084             m_pParent(NULL)
00085     {}
00086 
00090     ULONG GetCount() const
00091     {
00092         return m_nCount;
00093     }
00094 
00098     bool IsConstant() const
00099     {
00100         return m_bIsConstant;
00101     }
00102 
00106     XSI::siICENodeDataType GetDataType() const
00107     {
00108         return m_dataType;
00109     }
00110 
00114     XSI::siICENodeStructureType GetStructureType() const
00115     {
00116         return m_pParent ? m_pParent->GetStructureType( ) : m_structType;
00117     }
00118 
00119     virtual ~CBaseICEAttributeDataArray()
00120     {
00121         m_attrib.ReleaseDataArray( *this );
00122     }
00123 
00124 protected:
00125     const void* GetDataPtr( ) const
00126     {
00127         return (const void*)m_pData;
00128     }
00129 
00130     ULONG GetHandle() const
00131     {
00132         return m_pParent ? m_pParent->GetHandle( ) : m_nHandle;
00133     }
00134 
00135     ULONG GetAccessIndex() const
00136     {
00137         return m_pParent ? m_pParent->GetAccessIndex( ) : m_nAccessIndex;
00138     }
00139 
00140     void*& GetDataRef( )
00141     {
00142         return m_pData;
00143     }
00144 
00145     ULONG& GetHandleRef()
00146     {
00147         return m_nHandle;
00148     }
00149 
00150     ULONG& GetCountRef()
00151     {
00152         return m_nCount;
00153     }
00154 
00155     ICEAttribute& GetICEAttributeRef()
00156     {
00157         return m_attrib;
00158     }
00159 
00160     const ICEAttribute& GetICEAttributeRef() const
00161     {
00162         return m_attrib;
00163     }
00164 
00165     CBitsetHelper& GetBitsetRef()
00166     {
00167         return m_bitset;
00168     }
00169 
00170     bool& GetConstantRef()
00171     {
00172         return m_bIsConstant;
00173     }
00174 
00175     void SetParent( CBaseICEAttributeDataArray* in_pParent )
00176     {
00177         m_pParent = in_pParent;
00178     }
00179 
00180     const CBaseICEAttributeDataArray* GetParent() const
00181     {
00182         return m_pParent;
00183     }
00184 
00185     CBaseICEAttributeDataArray* GetParent()
00186     {
00187         return m_pParent;
00188     }
00189 
00190     ULONG& GetAccessIndexRef()
00191     {
00192         return m_nAccessIndex;
00193     }
00194 
00195     const ULONG& GetAccessIndexRef() const
00196     {
00197         return m_nAccessIndex;
00198     }
00199 
00200 
00201 protected:
00202     CStatus SetSubArrayElement( CBaseICEAttributeDataArray& in_dataArray2D, ULONG in_arrayIndex, ULONG in_subArrayIndex, void* in_value, ULONG in_size )
00203     {
00204         return m_attrib.SetArrayElementInternal( in_dataArray2D, in_arrayIndex, in_subArrayIndex, in_value, in_size );
00205     }
00206 
00207     CStatus GetSubArrayElement( const CBaseICEAttributeDataArray& in_dataArray2D, ULONG in_arrayIndex, ULONG in_subArrayIndex, void** out_value, ULONG& out_nSize ) const
00208     {
00209         return m_attrib.GetArrayElementInternal(  in_dataArray2D, in_arrayIndex, in_subArrayIndex, out_value, out_nSize );
00210     }
00211 
00212     CStatus GetSubDataArray( ULONG in_index, CBaseICEAttributeDataArray& out_dataArray ) const
00213     {
00214         CStatus st = m_attrib.GetSubDataArray( *(CBaseICEAttributeDataArray*)this, in_index, out_dataArray );
00215         assert( st == CStatus::OK );
00216         return st;
00217     }
00218 
00219     CStatus SetSubDataArray( CBaseICEAttributeDataArray& io_dataArray2D, CBaseICEAttributeDataArray* io_pSubDataArray, ULONG in_index, void* in_pData, ULONG in_count )
00220     {
00221         return m_attrib.SetSubDataArray(io_dataArray2D, io_pSubDataArray, in_index, in_pData, in_count);
00222     }
00223 
00224     CStatus SetStringSubDataArray( CBaseICEAttributeDataArray& io_dataArray2D, CBaseICEAttributeDataArray* io_pSubDataArray, ULONG in_index, const wchar_t** in_ppData, ULONG in_count )
00225     {
00226         CStatus st = m_attrib.SetStringSubDataArray(io_dataArray2D, io_pSubDataArray, in_index, in_ppData, in_count);
00227         assert( st == CStatus::OK );
00228         return st;
00229     }
00230 
00231     CStatus SetCustomTypeSubDataArray( CBaseICEAttributeDataArray& in_dataArray2D, CBaseICEAttributeDataArray* io_pSubDataArray, ULONG in_index, const unsigned char** in_ppData, ULONG in_count, ULONG in_fixedElemSize )
00232     {
00233         CStatus st = m_attrib.SetCustomTypeSubDataArray( in_dataArray2D, io_pSubDataArray, in_index, in_ppData, in_count, in_fixedElemSize);
00234         assert( st == CStatus::OK );
00235         return st;
00236     }
00237 
00238     CStatus SetCustomTypeSubDataArray( CBaseICEAttributeDataArray& in_dataArray2D, CBaseICEAttributeDataArray* io_pSubDataArray, ULONG in_index, const unsigned char** in_ppData, ULONG in_count, ULONG* in_pElemSizes )
00239     {
00240         CStatus st = m_attrib.SetCustomTypeSubDataArray(in_dataArray2D, io_pSubDataArray, in_index, in_ppData, in_count, in_pElemSizes);
00241         assert( st == CStatus::OK );
00242         return st;
00243     }
00244 
00245 
00246     CStatus SetBoolSubDataArray( CBaseICEAttributeDataArray& io_dataArray2D, CBaseICEAttributeDataArray* io_pSubDataArray, ULONG in_offset, const XSI::CBitArray& in_bitArray )
00247     {
00248         return m_attrib.SetBoolSubDataArray(io_dataArray2D, io_pSubDataArray, in_offset, in_bitArray );
00249     }
00250 
00251     CStatus ResizeSubDataArray( CBaseICEAttributeDataArray& in_dataArray2D, ULONG in_index, ULONG in_size, CBaseICEAttributeDataArray& out_dataArray )
00252     {
00253         if( m_attrib.IsReadonly() )
00254             return CStatus::AccessDenied; 
00255 
00256         CStatus st = m_attrib.ResizeSubDataArray(in_dataArray2D, in_index, in_size, out_dataArray );
00257         assert( st == CStatus::OK );
00258         return st;
00259     }
00260 
00261     CStatus SetDataArray2D( ULONG in_offset, void* in_pData, ULONG in_nbSubArrays, ULONG* in_pSubArraySizes )
00262     {
00263         return m_attrib.SetDataArrayInternal( *(CBaseICEAttributeDataArray*)this, NULL, in_offset, in_pData, in_nbSubArrays, in_pSubArraySizes, true );
00264     }
00265 
00266 
00267     CStatus SetStringDataArray2D( ULONG in_offset, const wchar_t*** in_pppData, ULONG in_count, ULONG* in_pSubArraySizes )
00268     {
00269         return m_attrib.SetCharDataArrayInternal( *(CBaseICEAttributeDataArray*)this, NULL, in_offset, in_pppData, in_count, in_pSubArraySizes, NULL, 0, true );
00270     }
00271 
00272     CStatus SetCustomTypeDataArray2D( ULONG in_offset, const unsigned char*** in_pppData, ULONG in_count, ULONG* in_pSubArraySizes, ULONG** in_ppElemSizes )
00273     {
00274         return m_attrib.SetCharDataArrayInternal( *(CBaseICEAttributeDataArray*)this, NULL, in_offset, in_pppData, in_count, in_pSubArraySizes, in_ppElemSizes, 0, true );
00275     }
00276 
00277     CStatus SetCustomTypeDataArray2D( ULONG in_offset, const unsigned char*** in_pppData, ULONG in_count, ULONG* in_pSubArraySizes, ULONG in_fixedElemSize )
00278     {
00279         return m_attrib.SetCharDataArrayInternal( *(CBaseICEAttributeDataArray*)this, NULL, in_offset, in_pppData, in_count, in_pSubArraySizes, NULL, in_fixedElemSize, true );
00280     }
00281 
00282     CStatus GetCustomTypeData( ULONG in_index, const unsigned char** out_ppData, ULONG& out_nSize ) const
00283     {
00284         if ( GetStructureType() == XSI::siICENodeStructureSingle )
00285         {
00286             return m_attrib.GetCustomTypeData( (CBaseICEAttributeDataArray&)*this, in_index, out_ppData, out_nSize );
00287         }
00288         return m_attrib.GetCustomTypeData2D( *(CBaseICEAttributeDataArray*)GetParent(), GetAccessIndexRef(), in_index, out_ppData, out_nSize );
00289     }
00290 
00291     CStatus GetStringData( ULONG in_index, const wchar_t** out_ppData, ULONG& out_nSize ) const
00292     {
00293         if ( GetStructureType() == XSI::siICENodeStructureSingle )
00294         {
00295             return m_attrib.GetStringData( (CBaseICEAttributeDataArray&)*this, in_index, out_ppData, out_nSize );
00296         }
00297         return m_attrib.GetStringData2D( *(CBaseICEAttributeDataArray*)GetParent(), GetAccessIndexRef(), in_index, out_ppData, out_nSize );
00298     }
00299 
00300     CStatus SetStringData( ULONG in_index, const wchar_t* in_pData, ULONG in_size )
00301     {
00302         if ( GetStructureType() == XSI::siICENodeStructureSingle )
00303         {
00304             return m_attrib.SetStringData( (CBaseICEAttributeDataArray&)*this, in_index, in_pData, in_size );
00305         }
00306         return m_attrib.SetStringData2D( *(CBaseICEAttributeDataArray*)GetParent(), GetAccessIndexRef(), in_index, in_pData, in_size );
00307     }
00308 
00309     CStatus SetArrayElement( ULONG in_index, void* in_value, ULONG in_size )
00310     {
00311         return m_attrib.SetArrayElementInternal(  (CBaseICEAttributeDataArray&)*this, in_index, ULONG_MAX, in_value, in_size );
00312     }
00313 
00314     CStatus GetArrayElement( ULONG in_index, void** out_value, ULONG& out_nSize ) const
00315     {
00316         return m_attrib.GetArrayElementInternal(  (CBaseICEAttributeDataArray&)*this, in_index, ULONG_MAX, out_value, out_nSize );
00317     }
00318 
00319     CStatus SetDataArray( ULONG in_offset, void* in_pData, ULONG in_count )
00320     {
00321         return m_attrib.SetDataArrayInternal( (CBaseICEAttributeDataArray&)*this, NULL, in_offset, in_pData, in_count, NULL, false );
00322     }
00323 
00324     CStatus SetStringDataArray( ULONG in_offset, const wchar_t** in_ppData, ULONG in_count )
00325     {
00326         return m_attrib.SetCharDataArrayInternal( (CBaseICEAttributeDataArray&)*this, NULL, in_offset, in_ppData, in_count, NULL, NULL, 0, false );
00327     }
00328 
00329 
00330     CStatus SetCustomTypeDataArray( ULONG in_offset, const unsigned char** in_ppData, ULONG in_count, ULONG in_fixedElemSize )
00331     {
00332         return m_attrib.SetCharDataArrayInternal( (CBaseICEAttributeDataArray&)*this, NULL, in_offset, in_ppData, in_count, NULL, NULL, in_fixedElemSize, false );
00333     }
00334 
00335     CStatus SetCustomTypeDataArray( ULONG in_offset, const unsigned char** in_ppData, ULONG in_count, ULONG* in_pElementSizes )
00336     {
00337         return m_attrib.SetCharDataArrayInternal( (CBaseICEAttributeDataArray&)*this, NULL, in_offset, in_ppData, in_count, NULL, in_pElementSizes, 0, false );
00338     }
00339 
00340 
00341     CStatus SetBoolDataArray( ULONG in_offset, const XSI::CBitArray& in_bitArray )
00342     {
00343         return m_attrib.SetBoolDataArray( (CBaseICEAttributeDataArray&)*this, in_offset, in_bitArray );
00344     }
00345 
00346 
00347     ULONG           m_nCount;
00348     CBitsetHelper   m_bitset;
00349     bool            m_bIsConstant;
00350 
00351 private:
00352     ULONG                       m_nAccessIndex;
00353     ULONG                       m_nHandle;
00354     void*                       m_pData;
00355     XSI::siICENodeStructureType m_structType;
00356     XSI::siICENodeDataType      m_dataType;
00357     ICEAttribute                m_attrib;
00358     CBaseICEAttributeDataArray* m_pParent;
00359 };
00360 
00361 //*****************************************************************************
00422 //*****************************************************************************
00423 template<class T>
00424 class CICEAttributeDataArray : public CBaseICEAttributeDataArray
00425 {
00426 public:
00427 
00429     CICEAttributeDataArray( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle ) {}
00430 
00432     ~CICEAttributeDataArray( ) {}
00433 
00439     const T& operator[]( ULONG in_index ) const
00440     {
00441         if (in_index >=  GetCount() ) 
00442         {
00443             static T defVal;
00444             return defVal;
00445         }
00446 
00447         const T* pData = GetDataAccessor(in_index);
00448         return *pData;
00449     }
00450 
00457     T& operator[]( ULONG in_index )
00458     {
00459         if (in_index >=  GetCount() || GetICEAttributeRef().IsReadonly() ) 
00460         {
00461             static T defVal;
00462             return defVal;
00463         }
00464 
00465         T* pData = (T*)GetDataAccessor(in_index);
00466         return *pData;
00467     }
00468 
00478     CStatus SetData( ULONG in_index, const T& in_value );
00479 
00532     CStatus SetArray( const T* in_pArray, ULONG in_count );
00533 
00534 private:
00535     static XSI::siICENodeDataType GetDefaultType( );
00536     const T* GetDataAccessor(ULONG in_index) const;
00537 
00538 };
00539 
00540 //*****************************************************************************
00541 // NB: Do not use the Doxygen \class tag for this template!!!
00546 //*****************************************************************************
00547 template<>
00548 class SICPPSDKDECL CICEAttributeDataArray<bool> : public CBaseICEAttributeDataArray
00549 {
00550 public:
00552     CICEAttributeDataArray<bool>( ) :
00553         CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00554     {}
00555 
00557     ~CICEAttributeDataArray<bool>( ) {}
00558 
00564     const bool operator[]( ULONG in_index ) const;
00565 
00566 
00575     CStatus SetData( ULONG in_index, bool in_bVal );
00576 
00586     CStatus SetArray( const bool* in_pArray, ULONG in_count );
00587 
00588 private:
00589     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
00590     {
00591         return siICENodeDataBool;
00592     }
00593 };
00594 
00595 //*****************************************************************************
00630 //*****************************************************************************
00631 
00632 class SICPPSDKDECL CICEAttributeDataArrayCustomType : public CBaseICEAttributeDataArray
00633 {
00634     public:
00635     typedef unsigned char TData;
00636 
00639     SICPPSDK_INLINE CICEAttributeDataArrayCustomType( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00640     {}
00641 
00644     SICPPSDK_INLINE ~CICEAttributeDataArrayCustomType( )
00645     {}
00646 
00656     SICPPSDK_INLINE CStatus GetData( ULONG in_index, const TData** out_ppData, ULONG& out_nSize  ) const;
00657 
00854     CStatus SetArray( const TData** in_ppData, ULONG in_count, ULONG in_fixedElemSize );
00855 
00866     CStatus SetArray( const TData** in_ppData, ULONG in_count, ULONG* in_pElementSizes );
00867 
00868 private:
00869     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
00870     {
00871         return siICENodeDataCustomType;
00872     }
00873 };
00874 
00875 CStatus CICEAttributeDataArrayCustomType::GetData( ULONG in_index, const TData** out_ppData, ULONG& out_nSize  ) const
00876 {
00877     return GetCustomTypeData( in_index, out_ppData, out_nSize );
00878 }
00879 
00880 //*****************************************************************************
00914 //*****************************************************************************
00915 
00916 class SICPPSDKDECL CICEAttributeDataArrayString : public CBaseICEAttributeDataArray
00917 {
00918     public:
00919     typedef wchar_t TData;
00920 
00923     SICPPSDK_INLINE CICEAttributeDataArrayString( ) : CBaseICEAttributeDataArray( GetDefaultType( ), XSI::siICENodeStructureSingle )
00924     {}
00925 
00928     SICPPSDK_INLINE ~CICEAttributeDataArrayString( )
00929     {}
00930 
00943     SICPPSDK_INLINE CStatus GetData( ULONG in_index, const TData** out_ppStr, ULONG& out_nCount ) const;
00944 
00950     SICPPSDK_INLINE CStatus GetData( ULONG in_index, CString& out_str ) const;
00951 
00960     SICPPSDK_INLINE CStatus SetData( ULONG in_index, const CString& in_str );
00961 
00967     SICPPSDK_INLINE CString operator[]( ULONG in_index ) const;
00968 
01029     CStatus SetArray( const TData** in_ppData, ULONG in_count );
01030 
01031 private:
01032     static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( )
01033     {
01034         return siICENodeDataString;
01035     }
01036 };
01037 
01038 CStatus CICEAttributeDataArrayString::GetData( ULONG in_index, const TData** out_ppStr, ULONG& out_nCount ) const
01039 {
01040     if( in_index >=  GetCount() )
01041         return CStatus::InvalidArgument; 
01042 
01043     const ICEAttribute& attr = GetICEAttributeRef();
01044 
01045     return GetStringData( in_index, out_ppStr, out_nCount );
01046 }
01047 
01048 SICPPSDK_INLINE CStatus CICEAttributeDataArrayString::GetData( ULONG in_index, CString& out_str ) const
01049 {
01050     const wchar_t* pzStr;
01051     ULONG nSize;
01052     CStatus st = GetStringData( in_index, &pzStr, nSize );
01053     if (st == CStatus::OK)
01054         out_str = CString( pzStr, nSize );
01055     return st;
01056 }
01057 
01058 SICPPSDK_INLINE CStatus CICEAttributeDataArrayString::SetData( ULONG in_index, const CString& in_str )
01059 {
01060     if( in_index >=  GetCount() )
01061         return CStatus::InvalidArgument; 
01062 
01063     const ICEAttribute& attr = GetICEAttributeRef();
01064     if( attr.IsReadonly() )
01065         return CStatus::AccessDenied; 
01066 
01067     return CBaseICEAttributeDataArray::SetStringData( in_index, in_str.GetWideString(), in_str.Length() );
01068 }
01069 
01070 SICPPSDK_INLINE CString CICEAttributeDataArrayString::operator[]( ULONG i ) const
01071 {
01072     CString str;
01073     CStatus st = GetData( i, str );
01074     assert( st == CStatus::OK );
01075     return str;
01076 }
01077 
01155 typedef XSI::CICEAttributeDataArray< float > CICEAttributeDataArrayFloat;
01156 typedef XSI::CICEAttributeDataArray< LONG > CICEAttributeDataArrayLong;
01157 typedef XSI::CICEAttributeDataArray< bool > CICEAttributeDataArrayBool;
01158 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector2f > CICEAttributeDataArrayVector2f;
01159 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector3f > CICEAttributeDataArrayVector3f;
01160 typedef XSI::CICEAttributeDataArray< XSI::MATH::CVector4f > CICEAttributeDataArrayVector4f;
01161 typedef XSI::CICEAttributeDataArray< XSI::MATH::CQuaternionf > CICEAttributeDataArrayQuaternionf;
01162 typedef XSI::CICEAttributeDataArray< XSI::MATH::CRotationf > CICEAttributeDataArrayRotationf;
01163 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix3f > CICEAttributeDataArrayMatrix3f;
01164 typedef XSI::CICEAttributeDataArray< XSI::MATH::CMatrix4f > CICEAttributeDataArrayMatrix4f;
01165 typedef XSI::CICEAttributeDataArray< XSI::MATH::CColor4f > CICEAttributeDataArrayColor4f;
01166 typedef XSI::CICEAttributeDataArray< XSI::MATH::CShape> CICEAttributeDataArrayShape;
01167 
01168 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayFloat::GetDefaultType( ){return siICENodeDataFloat;}
01169 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayLong::GetDefaultType( ){return siICENodeDataLong;}
01170 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector2f::GetDefaultType( ){return siICENodeDataVector2;}
01171 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector3f::GetDefaultType( ){return siICENodeDataVector3;}
01172 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayVector4f::GetDefaultType( ){return siICENodeDataVector4;}
01173 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayQuaternionf::GetDefaultType( ){return siICENodeDataQuaternion;}
01174 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix3f::GetDefaultType( ){return siICENodeDataMatrix33;}
01175 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayMatrix4f::GetDefaultType( ){return siICENodeDataMatrix44;}
01176 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayColor4f::GetDefaultType( ){return siICENodeDataColor4;}
01177 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayRotationf::GetDefaultType( ){return siICENodeDataRotation;}
01178 template<> SICPPSDK_INLINE XSI::siICENodeDataType CICEAttributeDataArrayShape::GetDefaultType( ){return siICENodeDataShape;}
01179 
01180 };
01181 
01182 #endif // __XSIICEATTRIBUTEDATAARRAY_H__