00001
00011
00012
00013 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00014 #pragma once
00015 #endif
00016
00017 #ifndef __XSIDATAARRAY_H__
00018 #define __XSIDATAARRAY_H__
00019
00020 #include <sicppsdk.h>
00021 #include <xsi_icenodecontext.h>
00022 #include <xsi_indexset.h>
00023
00024 #include <xsi_vector2f.h>
00025 #include <xsi_vector3f.h>
00026 #include <xsi_vector4f.h>
00027 #include <xsi_quaternionf.h>
00028 #include <xsi_rotationf.h>
00029 #include <xsi_matrix3f.h>
00030 #include <xsi_matrix4f.h>
00031 #include <xsi_color4f.h>
00032 #include <xsi_shape.h>
00033
00034 namespace XSI {
00035
00036 class CBaseDataArray
00037 {
00038 public:
00039 friend class ICENodeContext;
00040
00041 CBaseDataArray() :
00042 m_nHandle(UINT_MAX),
00043 m_pData(NULL),
00044 m_bIsConstant(true),
00045 m_nCount(1)
00046 {}
00047
00048 protected:
00049 SICPPSDK_INLINE ICENodeContext& GetContextRef();
00050 SICPPSDK_INLINE ULONG& GetHandleRef();
00051 SICPPSDK_INLINE void*& GetDataRef();
00052 SICPPSDK_INLINE bool& GetConstantRef();
00053 SICPPSDK_INLINE ULONG& GetCountRef();
00054
00055 virtual SICPPSDK_INLINE CStatus AcquireInputDataArray( XSI::siICENodeDataType in_arrayDataType, ULONG in_nInputPortID, ULONG in_nInstanceIndex );
00056 virtual SICPPSDK_INLINE CStatus AcquireOutputDataArray( XSI::siICENodeDataType in_arrayDataType );
00057 virtual SICPPSDK_INLINE CStatus ReleaseDataArray( );
00058
00059 ICENodeContext m_ctxt;
00060 ULONG m_nHandle;
00061 void* m_pData;
00062 bool m_bIsConstant;
00063 ULONG m_nCount;
00064
00065 private:
00066 CBaseDataArray( const CBaseDataArray& );
00067 };
00068
00069 SICPPSDK_INLINE CStatus CBaseDataArray::AcquireInputDataArray( XSI::siICENodeDataType in_arrayDataType, ULONG in_nInputPortID, ULONG in_nInstanceIndex )
00070 {
00071 return m_ctxt.AcquireInputDataArray( *this, in_arrayDataType, in_nInputPortID, in_nInstanceIndex );
00072 }
00073
00074 SICPPSDK_INLINE CStatus CBaseDataArray::AcquireOutputDataArray( XSI::siICENodeDataType in_arrayDataType )
00075 {
00076 return m_ctxt.AcquireOutputDataArray( *this, in_arrayDataType );
00077 }
00078
00079 SICPPSDK_INLINE CStatus CBaseDataArray::ReleaseDataArray( )
00080 {
00081 return m_ctxt.ReleaseDataArray( *this );
00082 }
00083
00084 SICPPSDK_INLINE ICENodeContext& CBaseDataArray::GetContextRef()
00085 {
00086 return m_ctxt;
00087 }
00088
00089 SICPPSDK_INLINE ULONG& CBaseDataArray::GetHandleRef()
00090 {
00091 return m_nHandle;
00092 }
00093
00094 SICPPSDK_INLINE void*& CBaseDataArray::GetDataRef()
00095 {
00096 return m_pData;
00097 }
00098
00099 SICPPSDK_INLINE bool& CBaseDataArray::GetConstantRef()
00100 {
00101 return m_bIsConstant;
00102 }
00103
00104 SICPPSDK_INLINE ULONG& CBaseDataArray::GetCountRef()
00105 {
00106 return m_nCount;
00107 }
00108
00109
00154
00155
00156 template <class T>
00157 class CDataArray : public CBaseDataArray
00158 {
00159 public:
00176 typedef T TData;
00177
00183 SICPPSDK_INLINE CDataArray( ICENodeContext& in_ctxt, ULONG in_nInputPortID, ULONG in_nInstanceIndex=0 ) ;
00184
00188 SICPPSDK_INLINE CDataArray( ICENodeContext& in_ctxt ) ;
00189
00192 SICPPSDK_INLINE ~CDataArray( );
00193
00199 SICPPSDK_INLINE const TData& operator[]( ULONG in_index ) const;
00200
00207 SICPPSDK_INLINE TData& operator[]( ULONG in_index ) ;
00208
00212 SICPPSDK_INLINE ULONG GetCount() const;
00213
00217 SICPPSDK_INLINE bool IsConstant() const;
00218
00219 private:
00220 SICPPSDK_INLINE void Clear();
00221 static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( );
00222
00223 #ifdef _DEBUG
00224 TData* m_pDebugData;
00225 #endif
00226
00227 };
00228
00229 template< class T >
00230 SICPPSDK_INLINE CDataArray<T>::CDataArray( ICENodeContext& in_ctxt, ULONG in_nInputPortID, ULONG in_nInstanceIndex )
00231 {
00232 m_ctxt = in_ctxt;
00233
00234 AcquireInputDataArray( GetDefaultType(), in_nInputPortID, in_nInstanceIndex );
00235
00236 #ifdef _DEBUG
00237 m_pDebugData = (T*)GetDataRef();
00238 #endif
00239 }
00240
00241 template< class T >
00242 SICPPSDK_INLINE CDataArray<T>::CDataArray( ICENodeContext& in_ctxt )
00243 {
00244 m_ctxt = in_ctxt;
00245
00246 AcquireOutputDataArray( GetDefaultType() );
00247
00248 #ifdef _DEBUG
00249 m_pDebugData = (T*)GetDataRef();
00250 #endif
00251 }
00252
00253 template< class T >
00254 SICPPSDK_INLINE CDataArray<T>::~CDataArray( )
00255 {
00256 ReleaseDataArray( );
00257 }
00258
00259 template< class T >
00260 SICPPSDK_INLINE const T& CDataArray<T>::operator[]( ULONG i ) const
00261 {
00262 assert( !m_bIsConstant ? i < m_nCount : true );
00263 T* pData = (T*)GetDataRef();
00264 assert( pData != NULL );
00265
00266 static T defVal;
00267 return pData ? ( m_bIsConstant ? *pData : pData[i] ) : defVal;
00268 }
00269
00270 template< class T >
00271 SICPPSDK_INLINE T& CDataArray<T>::operator[]( ULONG i )
00272 {
00273 assert( !m_bIsConstant ? i < m_nCount : true );
00274 T* pData = (T*)GetDataRef();
00275 assert( pData != NULL );
00276
00277 static T defVal;
00278 return pData ? ( m_bIsConstant ? *pData : pData[i] ) : defVal;
00279 }
00280
00281 template< class T >
00282 SICPPSDK_INLINE void CDataArray<T>::Clear()
00283 {
00284 ReleaseDataArray( );
00285 m_nHandle = UINT_MAX;
00286 m_nCount = 0;
00287 m_bIsConstant = false;
00288 }
00289
00290 template< class T >
00291 SICPPSDK_INLINE ULONG CDataArray<T>::GetCount() const
00292 {
00293 return m_nCount;
00294 }
00295
00296 template< class T >
00297 SICPPSDK_INLINE bool CDataArray<T>::IsConstant() const
00298 {
00299 return m_bIsConstant;
00300 }
00301
00302
00303
00310
00311 template<>
00312 class CDataArray< bool > : public CBaseDataArray
00313 {
00314 public:
00315
00321 SICPPSDK_INLINE CDataArray< bool >( ICENodeContext& in_ctxt, ULONG in_nInputPortID, ULONG in_nInstanceIndex=0 ) ;
00322
00326 SICPPSDK_INLINE CDataArray< bool >( ICENodeContext& in_ctxt ) ;
00327
00330 SICPPSDK_INLINE ~CDataArray< bool >( );
00331
00337 SICPPSDK_INLINE const bool operator[]( ULONG in_index ) const;
00338
00345 SICPPSDK_INLINE CStatus Set( ULONG in_index, bool in_bVal ) ;
00346
00350 SICPPSDK_INLINE ULONG GetCount() const;
00351
00355 SICPPSDK_INLINE bool IsConstant() const;
00356
00357 private:
00358 SICPPSDK_INLINE void Clear();
00359 static SICPPSDK_INLINE XSI::siICENodeDataType GetDefaultType( );
00360
00361 CBitsetHelper m_bitset;
00362 };
00363
00364 SICPPSDK_INLINE CDataArray<bool>::CDataArray( ICENodeContext& in_ctxt, ULONG in_nInputPortID, ULONG in_nInstanceIndex )
00365 {
00366 m_ctxt = in_ctxt;
00367
00368 AcquireInputDataArray( GetDefaultType(), in_nInputPortID, in_nInstanceIndex );
00369
00370 m_bitset.GetCountRef() = GetCountRef();
00371 m_bitset.GetArrayRef() = (ULONG*)GetDataRef();
00372 }
00373
00374 SICPPSDK_INLINE CDataArray<bool>::CDataArray( ICENodeContext& in_ctxt )
00375 {
00376 m_ctxt = in_ctxt;
00377 m_bIsConstant = true;
00378 m_nCount = 1;
00379
00380 AcquireOutputDataArray( GetDefaultType() );
00381
00382 m_bitset.GetCountRef() = m_nCount;
00383 m_bitset.GetArrayRef() = (ULONG*)GetDataRef();
00384 }
00385
00386 SICPPSDK_INLINE CDataArray<bool>::~CDataArray( )
00387 {
00388 ReleaseDataArray( );
00389 }
00390
00391 SICPPSDK_INLINE CStatus CDataArray<bool>::Set( ULONG in_index, bool in_bVal )
00392 {
00393 return m_bitset.SetBit( in_index, in_bVal );
00394 }
00395
00396 SICPPSDK_INLINE const bool CDataArray<bool>::operator[] ( ULONG in_index ) const
00397 {
00398 ULONG nIndex = m_bIsConstant ? 0 : in_index;
00399 return m_bitset.GetBit( nIndex );
00400 }
00401
00402 SICPPSDK_INLINE void CDataArray<bool>::Clear()
00403 {
00404 ReleaseDataArray( );
00405 m_nHandle = UINT_MAX;
00406 m_bIsConstant = true;
00407 m_nCount = 1;
00408 m_bitset.Clear();
00409 }
00410
00411 SICPPSDK_INLINE XSI::siICENodeDataType CDataArray<bool>::GetDefaultType()
00412 {
00413 return siICENodeDataBool;
00414 }
00415
00416 SICPPSDK_INLINE ULONG CDataArray<bool>::GetCount() const
00417 {
00418 return m_nCount;
00419 }
00420
00421 SICPPSDK_INLINE bool CDataArray<bool>::IsConstant() const
00422 {
00423 return m_bIsConstant;
00424 }
00425
00502 typedef XSI::CDataArray< float > CDataArrayFloat;
00503 typedef XSI::CDataArray< LONG > CDataArrayLong;
00504 typedef XSI::CDataArray< bool > CDataArrayBool;
00505 typedef XSI::CDataArray< XSI::MATH::CVector2f > CDataArrayVector2f;
00506 typedef XSI::CDataArray< XSI::MATH::CVector3f > CDataArrayVector3f;
00507 typedef XSI::CDataArray< XSI::MATH::CVector4f > CDataArrayVector4f;
00508 typedef XSI::CDataArray< XSI::MATH::CQuaternionf > CDataArrayQuaternionf;
00509 typedef XSI::CDataArray< XSI::MATH::CRotationf > CDataArrayRotationf;
00510 typedef XSI::CDataArray< XSI::MATH::CMatrix3f > CDataArrayMatrix3f;
00511 typedef XSI::CDataArray< XSI::MATH::CMatrix4f > CDataArrayMatrix4f;
00512 typedef XSI::CDataArray< XSI::MATH::CColor4f > CDataArrayColor4f;
00513 typedef XSI::CDataArray< XSI::MATH::CShape> CDataArrayShape;
00514
00515 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayFloat::GetDefaultType( ){return siICENodeDataFloat;}
00516 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayLong::GetDefaultType( ){return siICENodeDataLong;}
00517 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayVector2f::GetDefaultType( ){return siICENodeDataVector2;}
00518 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayVector3f::GetDefaultType( ){return siICENodeDataVector3;}
00519 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayVector4f::GetDefaultType( ){return siICENodeDataVector4;}
00520 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayQuaternionf::GetDefaultType( ){return siICENodeDataQuaternion;}
00521 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayMatrix3f::GetDefaultType( ){return siICENodeDataMatrix33;}
00522 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayMatrix4f::GetDefaultType( ){return siICENodeDataMatrix44;}
00523 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayColor4f::GetDefaultType( ){return siICENodeDataColor4;}
00524 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayRotationf::GetDefaultType( ){return siICENodeDataRotation;}
00525 template<> SICPPSDK_INLINE XSI::siICENodeDataType CDataArrayShape::GetDefaultType( ){return siICENodeDataShape;}
00526 };
00527
00528 #endif // __XSIDATAARRAY_H__