Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1518 lines
40 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMATTRIBUTEVAR_H
  7. #define DMATTRIBUTEVAR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmattribute.h"
  12. #include "tier1/utlvector.h"
  13. #include "Color.h"
  14. #include "mathlib/vector2d.h"
  15. #include "mathlib/vector.h"
  16. #include "mathlib/vector4d.h"
  17. #include "mathlib/vmatrix.h"
  18. #include "datamodel/dmelement.h"
  19. #include "datamodel/dmehandle.h"
  20. //-----------------------------------------------------------------------------
  21. // Specialization for color
  22. //-----------------------------------------------------------------------------
  23. class CDmaColor : public CDmaVar< Color >
  24. {
  25. public:
  26. // Set methods
  27. void SetColor( int r, int g, int b, int a = 0 );
  28. void SetRed( int r );
  29. void SetGreen( int g );
  30. void SetBlue( int b );
  31. void SetAlpha( int a );
  32. // Sets the color as a 32-bit integer
  33. void SetRawColor( int color );
  34. // Get methods
  35. unsigned char r() const;
  36. unsigned char g() const;
  37. unsigned char b() const;
  38. unsigned char a() const;
  39. const unsigned char &operator[]( int index ) const;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Specialization for DmeTime_t
  43. //-----------------------------------------------------------------------------
  44. class CDmaTime : public CDmaVar< DmeTime_t >
  45. {
  46. public:
  47. // Cast operators
  48. operator const DmeTime_t&() const { return this->Value(); }
  49. const DmeTime_t* operator->() const { return &this->Value(); }
  50. // Math utility operations
  51. const DmeTime_t& operator= ( const DmeTime_t &val ) { return Set( val ); }
  52. const DmeTime_t& operator+=( const DmeTime_t &val ) { return Set( this->Value() + val ); }
  53. const DmeTime_t& operator-=( const DmeTime_t &val ) { return Set( this->Value() - val ); }
  54. const DmeTime_t& operator/=( float f ) { return Set( this->Value() / f ); }
  55. const DmeTime_t& operator*=( float f ) { return Set( this->Value() * f ); }
  56. DmeTime_t operator++() { return Set( this->Value() + DMETIME_MINDELTA ); }
  57. DmeTime_t operator--() { return Set( this->Value() - DMETIME_MINDELTA ); }
  58. DmeTime_t operator++( int ) { DmeTime_t t = this->Value(); Set( t + DMETIME_MINDELTA ); return t; } // postfix version..
  59. DmeTime_t operator--( int ) { DmeTime_t t = this->Value(); Set( t - DMETIME_MINDELTA ); return t; } // postfix version..
  60. void SetTenthsOfMS( int tms );
  61. void SetSeconds( float seconds );
  62. int GetTenthsOfMS() const;
  63. float GetSeconds() const;
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Specialization for binary block
  67. //-----------------------------------------------------------------------------
  68. class CDmaBinaryBlock : public CDmaVar< CUtlBinaryBlock >
  69. {
  70. public:
  71. void Get( void *pValue, int nMaxLen ) const;
  72. void Set( const void *pValue, int nLen );
  73. const void *Get() const;
  74. const unsigned char& operator[]( int i ) const;
  75. // Returns buffer length
  76. int Length() const;
  77. };
  78. //-----------------------------------------------------------------------------
  79. // Specialization for elements
  80. //-----------------------------------------------------------------------------
  81. template <class T>
  82. class CDmaElement : public CDmaVar< DmElementHandle_t >
  83. {
  84. typedef CDmaVar< DmElementHandle_t > BaseClass;
  85. public:
  86. // Used to initialize the attribute in an element's OnConstruction method
  87. void InitAndCreate( CDmElement *pOwner, const char *pAttributeName, const char *pElementName = NULL, int flags = 0 );
  88. void Init( CDmElement *pOwner, const char *pAttributeName, int flags = 0 );
  89. // Returns the type of elements allowed into this attribute. UTL_INVAL_SYMBOL allows everything.
  90. CUtlSymbolLarge GetElementType() const;
  91. // Get/set
  92. void Set( T* pElement );
  93. T* GetElement() const;
  94. const DmElementHandle_t& GetHandle() const
  95. {
  96. return this->Value();
  97. }
  98. // Cast
  99. T* operator->() const;
  100. operator T*() const;
  101. // NULL check
  102. bool operator!() const;
  103. // Assignment.. wish I knew how to un-inline these methods
  104. template <class S> CDmaElement<T> &operator=( S* pElement )
  105. {
  106. Set( static_cast<T*>( pElement ) );
  107. return *this;
  108. }
  109. template <class S> CDmaElement<T> &operator=( const CDmaElement<S>& src )
  110. {
  111. Set( static_cast<T*>( src.Get() ) );
  112. return *this;
  113. }
  114. template <class S> bool operator==( const CDmaElement<S>& src ) const
  115. {
  116. return this->Value() == src.Value();
  117. }
  118. template <class S> bool operator!=( const CDmaElement<S>& src ) const
  119. {
  120. return this->Value() != src.Value();
  121. }
  122. protected:
  123. // hide this to avoid accidental use in code like this:
  124. // if ( m_var.Get() )
  125. // which returns a DmElementHandle_t, which is true for most handles, including the invalid one
  126. const DmElementHandle_t& Get() const
  127. {
  128. return this->Value();
  129. }
  130. };
  131. //-----------------------------------------------------------------------------
  132. // Can access any array attribute, regardless of type
  133. // See below for type-specific array accessors which have more features
  134. //-----------------------------------------------------------------------------
  135. class CDmrGenericArrayConst
  136. {
  137. public:
  138. CDmrGenericArrayConst( const CDmAttribute* pAttribute );
  139. CDmrGenericArrayConst( const CDmElement *pElement, const char *pAttributeName );
  140. // Array count
  141. int Count() const;
  142. // Gets
  143. const void* GetUntyped( int i ) const;
  144. // String conversion
  145. const char* GetAsString( int i, char *pBuffer, size_t nBufLen ) const;
  146. const CDmAttribute *GetAttribute() const;
  147. bool IsValid() const;
  148. protected:
  149. CDmrGenericArrayConst();
  150. void Init( const CDmAttribute *pAttribute );
  151. void Init( const CDmElement *pElement, const char *pAttributeName );
  152. CDmAttribute *m_pAttribute;
  153. };
  154. class CDmrGenericArray : public CDmrGenericArrayConst
  155. {
  156. public:
  157. CDmrGenericArray( CDmAttribute* pAttribute );
  158. CDmrGenericArray( CDmElement *pElement, const char *pAttributeName );
  159. void EnsureCount( int num );
  160. // Sets multiple elements at the same time
  161. int AddToTail();
  162. void Remove( int elem ); // preserves order, shifts elements
  163. void RemoveAll(); // doesn't deallocate memory
  164. void SetMultiple( int i, int nCount, DmAttributeType_t valueType, const void *pValue );
  165. void Set( int i, DmAttributeType_t valueType, const void *pValue );
  166. // String conversion
  167. void SetFromString( int i, const char *pValue );
  168. CDmAttribute *GetAttribute();
  169. const CDmAttribute *GetAttribute() const;
  170. };
  171. //-----------------------------------------------------------------------------
  172. // Helper template for external array attribute vars
  173. // NOTE: To use this class, don't use CDmaArrayBase directly. Instead, use
  174. // CDmaArray<T> var; <- Instantiate an array attribute var as a member of a element class
  175. // CDmrArray<T> var; <- Used to reference an existing array attribute + read/modify it
  176. // CDmrArrayConst<T> var; <- Used to reference an existing array attribute + read it (no modify)
  177. //
  178. // Also, there is a CDmaStringArray/CDmrStringArray/CDmrStringArrayConst for strings
  179. // and a CDmaElementArray/CDmrElementArray/CDmrElementArrayConst for elements
  180. //-----------------------------------------------------------------------------
  181. template< class T, class B >
  182. class CDmaArrayConstBase : public B
  183. {
  184. public:
  185. // Accessors
  186. const CUtlVector<T> &Get() const;
  187. const T *Base() const;
  188. // Iteration
  189. int Count() const;
  190. const T& operator[]( int i ) const;
  191. const T& Element( int i ) const;
  192. const T& Get( int i ) const;
  193. const void* GetUntyped( int i ) const;
  194. bool IsValidIndex( int i ) const;
  195. int InvalidIndex( void ) const;
  196. // Search
  197. int Find( const T &value ) const;
  198. // Attribute-related methods
  199. const CDmAttribute *GetAttribute() const;
  200. CDmElement *GetOwner();
  201. bool IsDirty() const;
  202. protected:
  203. CDmaArrayConstBase( );
  204. CDmAttribute *m_pAttribute;
  205. };
  206. template< class T, class B >
  207. class CDmaArrayBase : public CDmaArrayConstBase< T, B >
  208. {
  209. public:
  210. // Insertion
  211. int AddToTail();
  212. int InsertBefore( int elem );
  213. int AddToTail( const T& src );
  214. int InsertBefore( int elem, const T& src );
  215. int AddMultipleToTail( int num );
  216. int InsertMultipleBefore( int elem, int num );
  217. void EnsureCount( int num );
  218. // Element Modification
  219. void Set( int i, const T& value );
  220. void SetMultiple( int i, int nCount, const T* pValue );
  221. void Swap( int i, int j );
  222. // Copy related methods
  223. void CopyArray( const T *pArray, int size );
  224. // this is basically just a faster version of CopyArray which uses pointer swap
  225. // NOTE: This doesn't work for element arrays
  226. void SwapArray( CUtlVector< T > &array );
  227. // Removal
  228. void FastRemove( int elem );
  229. void Remove( int elem );
  230. void RemoveMultiple( int elem, int num );
  231. void RemoveAll();
  232. // Memory management
  233. void EnsureCapacity( int num );
  234. void Purge();
  235. // Attribute-related methods
  236. CDmAttribute *GetAttribute();
  237. const CDmAttribute *GetAttribute() const;
  238. };
  239. //-----------------------------------------------------------------------------
  240. // Specialization for string arrays
  241. // NOTE: To use this class, don't use CDmaStringArrayBase directly. Instead, use
  242. // CDmaStringArray var; <- Instantiate an array attribute var as a member of a element class
  243. // CDmrStringArray var; <- Used to reference an existing array attribute + read/modify it
  244. // CDmrStringArrayConst var; <- Used to reference an existing array attribute + read it (no modify)
  245. //-----------------------------------------------------------------------------
  246. template< class BaseClass >
  247. class CDmaStringArrayConstBase : public BaseClass
  248. {
  249. public:
  250. const char *operator[]( int i ) const;
  251. const char *Element( int i ) const;
  252. const char *Get( int i ) const;
  253. const CUtlVector< CUtlSymbolLarge > &Get() const;
  254. // Returns strlen of element i
  255. int Length( int i ) const;
  256. };
  257. template< class B >
  258. class CDmaStringArrayBase : public CDmaStringArrayConstBase< CDmaArrayBase< CUtlSymbolLarge, B > >
  259. {
  260. typedef CDmaStringArrayConstBase< CDmaArrayBase< CUtlSymbolLarge, B > > BaseClass;
  261. public:
  262. // Sets an element in the array
  263. void Set( int i, const char * pValue );
  264. // Adds an element, uses copy constructor
  265. int AddToTail( const char *pValue );
  266. int InsertBefore( int elem, const char *pValue );
  267. };
  268. //-----------------------------------------------------------------------------
  269. // Specialization for elements
  270. // NOTE: To use this class, don't use CDmaElementArrayBase directly. Instead, use
  271. // CDmaElementArray< element_type > var; <- Instantiate an array attribute var as a member of a element class
  272. // CDmrElementArray< element_type > var; <- Used to reference an existing array attribute + read/modify it
  273. // CDmrElementArrayConst< element_type > var; <- Used to reference an existing array attribute + read it (no modify)
  274. //-----------------------------------------------------------------------------
  275. template< class E, class BaseClass >
  276. class CDmaElementArrayConstBase : public BaseClass
  277. {
  278. public:
  279. // Returns the element type
  280. CUtlSymbolLarge GetElementType() const;
  281. // Array access
  282. E *operator[]( int i ) const;
  283. E *Element( int i ) const;
  284. E *Get( int i ) const;
  285. const DmElementHandle_t& GetHandle( int i ) const;
  286. const CUtlVector< DmElementHandle_t > &Get() const;
  287. // Search
  288. int Find( const E *pValue ) const;
  289. int Find( DmElementHandle_t h ) const;
  290. };
  291. template < class E, class B >
  292. class CDmaElementArrayBase : public CDmaElementArrayConstBase< E, CDmaArrayBase< DmElementHandle_t, B > >
  293. {
  294. typedef CDmaElementArrayConstBase< E, CDmaArrayBase< DmElementHandle_t, B > > BaseClass;
  295. public:
  296. void SetHandle( int i, DmElementHandle_t h );
  297. void Set( int i, E *pElement );
  298. // Insertion
  299. int AddToTail( );
  300. int AddToTail( DmElementHandle_t src );
  301. int AddToTail( E *pValue );
  302. int InsertBefore( int elem );
  303. int InsertBefore( int elem, DmElementHandle_t src );
  304. int InsertBefore( int elem, E *pValue );
  305. template< class C, HandleType_t HT > int AddToTail( const CDmeHandle<C,HT>& value )
  306. {
  307. return BaseClass::AddToTail( value.GetHandle() );
  308. }
  309. template< class C, HandleType_t HT > int InsertBefore( int elem, const CDmeHandle<C,HT>& value )
  310. {
  311. return BaseClass::InsertBefore( elem, value.GetHandle() );
  312. }
  313. };
  314. // NOTE: The next couple classes are implementation details used to create CDmrAray/CDmaArray
  315. //-----------------------------------------------------------------------------
  316. // Base classes that contain data or refer to it; used for array accessor classes
  317. //-----------------------------------------------------------------------------
  318. template< typename T >
  319. class CDmaDataInternal
  320. {
  321. protected:
  322. typedef typename CDmAttributeInfo< T >::StorageType_t D;
  323. const T& Value() const { return m_Storage; }
  324. T& Value( ) { return m_Storage; }
  325. const D& Data() const { return m_Storage; }
  326. D& Data( ) { return m_Storage; }
  327. private:
  328. D m_Storage;
  329. };
  330. template< typename T >
  331. class CDmaDataExternal
  332. {
  333. protected:
  334. typedef typename CDmAttributeInfo< T >::StorageType_t D;
  335. CDmaDataExternal() : m_pStorage(0) {}
  336. void Attach( void *pData ) { m_pStorage = (D*)pData; }
  337. const T& Value() const { return *m_pStorage; }
  338. T& Value( ) { return *m_pStorage; }
  339. const D& Data() const { return *m_pStorage; }
  340. D& Data( ) { return *m_pStorage; }
  341. private:
  342. D* m_pStorage;
  343. };
  344. //-----------------------------------------------------------------------------
  345. // Versions for access, or for attribute vars
  346. //-----------------------------------------------------------------------------
  347. template< class T, class B >
  348. class CDmaDecorator : public B
  349. {
  350. public:
  351. void Init( CDmElement *pOwner, const char *pAttributeName, int flags = 0 );
  352. };
  353. template< class T, class BaseClass >
  354. class CDmrDecoratorConst : public BaseClass
  355. {
  356. public:
  357. void Init( const CDmAttribute* pAttribute );
  358. void Init( const CDmElement *pElement, const char *pAttributeName );
  359. bool IsValid() const;
  360. };
  361. template< class T, class BaseClass >
  362. class CDmrDecorator : public BaseClass
  363. {
  364. public:
  365. void Init( CDmAttribute* pAttribute );
  366. void Init( CDmElement *pElement, const char *pAttributeName, bool bAddAttribute = false );
  367. bool IsValid() const;
  368. };
  369. #define DECLARE_ATTRIBUTE_ARRAY_VARIABLE( _className, _elementType ) \
  370. public: \
  371. _className() {}
  372. #define DECLARE_ATTRIBUTE_ARRAY_REFERENCE( _className, _elementType ) \
  373. public: \
  374. _className() {} \
  375. _className( CDmAttribute* pAttribute ) { this->Init( pAttribute ); } \
  376. _className( CDmElement *pElement, const char *pAttributeName, bool bAddAttribute = false ) { this->Init( pElement, pAttributeName, bAddAttribute ); } \
  377. _className( CDmaArray<_elementType>& var ) { this->Init( var.GetAttribute() ); } \
  378. _className( CDmrArray<_elementType>& var ) { this->Init( var.GetAttribute() ); }
  379. #define DECLARE_ATTRIBUTE_ARRAY_CONST_REFERENCE( _className, _elementType ) \
  380. public: \
  381. _className() {} \
  382. _className( const CDmAttribute* pAttribute ) { this->Init( pAttribute ); } \
  383. _className( const CDmElement *pElement, const char *pAttributeName ) { this->Init( pElement, pAttributeName ); } \
  384. _className( const CDmaArray<_elementType>& var ) { this->Init( var.GetAttribute() ); } \
  385. _className( const CDmrArrayConst<_elementType>& var ) { this->Init( var.GetAttribute() ); } \
  386. _className( const CDmrArray<_elementType>& var ) { this->Init( var.GetAttribute() ); }
  387. template<class T> class CDmrArray;
  388. template<class T> class CDmrArrayConst;
  389. template<class T> class CDmaArray;
  390. //-----------------------------------------------------------------------------
  391. // Versions for access, or for attribute vars
  392. //-----------------------------------------------------------------------------
  393. template<class T>
  394. class CDmaArray : public CDmaDecorator< T, CDmaArrayBase< T, CDmaDataInternal< CUtlVector< T > > > >
  395. {
  396. DECLARE_ATTRIBUTE_ARRAY_VARIABLE( CDmaArray, T );
  397. public:
  398. const CDmaArray<T>& operator=( const CDmaArray<T> &val )
  399. {
  400. CopyArray( val.Base(), val.Count() );
  401. return *this;
  402. }
  403. template< class C > const CDmaArray<T>& operator=( const C &val )
  404. {
  405. CopyArray( val.Base(), val.Count() );
  406. return *this;
  407. }
  408. private:
  409. CDmaArray( const CDmaArray& array ) {}
  410. };
  411. template<class T>
  412. class CDmrArrayConst : public CDmrDecoratorConst< T, CDmaArrayConstBase< T, CDmaDataExternal< CUtlVector< T > > > >
  413. {
  414. typedef CDmrDecoratorConst< T, CDmaArrayConstBase< T, CDmaDataExternal< CUtlVector< T > > > > BaseClass;
  415. DECLARE_ATTRIBUTE_ARRAY_CONST_REFERENCE( CDmrArrayConst, T );
  416. };
  417. template<class T>
  418. class CDmrArray : public CDmrDecorator< T, CDmaArrayBase< T, CDmaDataExternal< CUtlVector< T > > > >
  419. {
  420. typedef CDmrDecorator< T, CDmaArrayBase< T, CDmaDataExternal< CUtlVector< T > > > > BaseClass;
  421. DECLARE_ATTRIBUTE_ARRAY_REFERENCE( CDmrArray, T );
  422. public:
  423. const CDmrArray<T>& operator=( const CDmrArray<T> &val )
  424. {
  425. CopyArray( val.Base(), val.Count() );
  426. return *this;
  427. }
  428. template< class C > const CDmrArray<T>& operator=( const C &val )
  429. {
  430. CopyArray( val.Base(), val.Count() );
  431. return *this;
  432. }
  433. };
  434. class CDmrStringArray;
  435. class CDmaStringArray : public CDmaDecorator< CUtlSymbolLarge, CDmaStringArrayBase< CDmaDataInternal< CUtlVector< CUtlSymbolLarge > > > >
  436. {
  437. DECLARE_ATTRIBUTE_ARRAY_VARIABLE( CDmaStringArray, CUtlSymbolLarge );
  438. public:
  439. const CDmaStringArray& operator=( const CDmaStringArray &val )
  440. {
  441. CopyArray( val.Base(), val.Count() );
  442. return *this;
  443. }
  444. template< class C > const CDmaStringArray& operator=( const C &val )
  445. {
  446. CopyArray( val.Base(), val.Count() );
  447. return *this;
  448. }
  449. private:
  450. CDmaStringArray( const CDmaStringArray& array ) {}
  451. };
  452. class CDmrStringArray : public CDmrDecorator< CUtlSymbolLarge, CDmaStringArrayBase< CDmaDataExternal< CUtlVector< CUtlSymbolLarge > > > >
  453. {
  454. typedef CDmrDecorator< CUtlSymbolLarge, CDmaStringArrayBase< CDmaDataExternal< CUtlVector< CUtlSymbolLarge > > > > BaseClass;
  455. DECLARE_ATTRIBUTE_ARRAY_REFERENCE( CDmrStringArray, CUtlSymbolLarge );
  456. public:
  457. CDmrStringArray( CDmaStringArray& var ) { this->Init( var.GetAttribute() ); }
  458. CDmrStringArray( CDmrStringArray& var ) { this->Init( var.GetAttribute() ); }
  459. const CDmrStringArray& operator=( const CDmrStringArray &val )
  460. {
  461. this->CopyArray( val.Base(), val.Count() );
  462. return *this;
  463. }
  464. template< class C > const CDmrStringArray& operator=( const C &val )
  465. {
  466. CopyArray( val.Base(), val.Count() );
  467. return *this;
  468. }
  469. };
  470. class CDmrStringArrayConst : public CDmrDecoratorConst< CUtlSymbolLarge, CDmaStringArrayConstBase< CDmaArrayConstBase< CUtlSymbolLarge, CDmaDataExternal< CUtlVector< CUtlSymbolLarge > > > > >
  471. {
  472. typedef CDmrDecoratorConst< CUtlSymbolLarge, CDmaStringArrayConstBase< CDmaArrayConstBase< CUtlSymbolLarge, CDmaDataExternal< CUtlVector< CUtlSymbolLarge > > > > > BaseClass;
  473. DECLARE_ATTRIBUTE_ARRAY_CONST_REFERENCE( CDmrStringArrayConst, CUtlSymbolLarge );
  474. public:
  475. CDmrStringArrayConst( const CDmaStringArray& var ) { this->Init( var.GetAttribute() ); }
  476. CDmrStringArrayConst( const CDmrStringArray& var ) { this->Init( var.GetAttribute() ); }
  477. CDmrStringArrayConst( const CDmrStringArrayConst& var ) { this->Init( var.GetAttribute() ); }
  478. };
  479. //-----------------------------------------------------------------------------
  480. // Prevent CDmaArray for DmElementHandle_t
  481. //-----------------------------------------------------------------------------
  482. template<> class CDmaArray<DmElementHandle_t> { private: CDmaArray(); };
  483. template< class E > class CDmrElementArray;
  484. template< class E = CDmElement >
  485. class CDmaElementArray : public CDmaElementArrayBase< E, CDmaDataInternal< CUtlVector< DmElementHandle_t > > >
  486. {
  487. DECLARE_ATTRIBUTE_ARRAY_VARIABLE( CDmaElementArray, DmElementHandle_t );
  488. public:
  489. void Init( CDmElement *pOwner, const char *pAttributeName, int flags = 0 )
  490. {
  491. Assert( pOwner );
  492. this->m_pAttribute = pOwner->AddExternalAttribute( pAttributeName, AT_ELEMENT_ARRAY, &this->Value() );
  493. this->m_pAttribute->SetElementTypeSymbol( E::GetStaticTypeSymbol() );
  494. if ( flags )
  495. {
  496. this->m_pAttribute->AddFlag( flags );
  497. }
  498. }
  499. template< typename C > CDmaElementArray<E>& operator=( const C &val )
  500. {
  501. CopyArray( val.Base(), val.Count() );
  502. return *this;
  503. }
  504. // NOTE: The copy operator= must be defined in addition to the generic one
  505. const CDmaElementArray<E>& operator=( const CDmaElementArray<E> &val )
  506. {
  507. CopyArray( val.Base(), val.Count() );
  508. return *this;
  509. }
  510. private:
  511. template< class C > CDmaElementArray( const CDmaElementArray<C>& var );
  512. };
  513. template< class E = CDmElement >
  514. class CDmrElementArrayConst : public CDmaElementArrayConstBase< E, CDmaArrayConstBase< DmElementHandle_t, CDmaDataExternal< CUtlVector< DmElementHandle_t > > > >
  515. {
  516. public:
  517. CDmrElementArrayConst()
  518. {
  519. this->m_pAttribute = NULL;
  520. }
  521. CDmrElementArrayConst( const CDmAttribute* pAttribute )
  522. {
  523. this->Init( pAttribute );
  524. }
  525. CDmrElementArrayConst( const CDmElement *pElement, const char *pAttributeName )
  526. {
  527. this->Init( pElement, pAttributeName );
  528. }
  529. template< typename C > CDmrElementArrayConst( const CDmaElementArray<C>& var )
  530. {
  531. this->Init( var.GetAttribute() );
  532. }
  533. template< typename C > CDmrElementArrayConst( const CDmrElementArray<C>& var )
  534. {
  535. this->Init( var.GetAttribute() );
  536. }
  537. template< typename C > CDmrElementArrayConst( const CDmrElementArrayConst<C>& var )
  538. {
  539. this->Init( var.GetAttribute() );
  540. }
  541. void Init( const CDmAttribute* pAttribute )
  542. {
  543. if ( pAttribute && pAttribute->GetType() == AT_ELEMENT_ARRAY )
  544. {
  545. this->m_pAttribute = const_cast<CDmAttribute*>( pAttribute );
  546. this->Attach( this->m_pAttribute->GetAttributeData() );
  547. }
  548. else
  549. {
  550. this->m_pAttribute = NULL;
  551. this->Attach( NULL );
  552. }
  553. }
  554. void Init( const CDmElement *pElement, const char *pAttributeName )
  555. {
  556. const CDmAttribute *pAttribute = NULL;
  557. if ( pElement && pAttributeName && pAttributeName[0] )
  558. {
  559. pAttribute = pElement->GetAttribute( pAttributeName );
  560. }
  561. this->Init( pAttribute );
  562. }
  563. int Count() const
  564. {
  565. return this->IsValid() ? this->Value().Count() : 0;
  566. }
  567. bool IsValid() const
  568. {
  569. return this->m_pAttribute != NULL;
  570. }
  571. };
  572. template< class T = CDmElement >
  573. class CDmrElementArray : public CDmaElementArrayBase< T, CDmaDataExternal< CUtlVector< DmElementHandle_t > > >
  574. {
  575. public:
  576. CDmrElementArray()
  577. {
  578. this->m_pAttribute = NULL;
  579. }
  580. CDmrElementArray( CDmAttribute* pAttribute )
  581. {
  582. this->Init( pAttribute );
  583. }
  584. CDmrElementArray( CDmElement *pElement, const char *pAttributeName, bool bAddAttribute = false )
  585. {
  586. this->Init( pElement, pAttributeName, bAddAttribute );
  587. }
  588. template< typename C > CDmrElementArray( CDmaElementArray<C>& var )
  589. {
  590. this->Init( var.GetAttribute() );
  591. }
  592. template< typename C > CDmrElementArray( CDmrElementArray<C>& var )
  593. {
  594. this->Init( var.GetAttribute() );
  595. }
  596. void Init( CDmAttribute* pAttribute )
  597. {
  598. if ( pAttribute && pAttribute->GetType() == AT_ELEMENT_ARRAY )
  599. {
  600. this->m_pAttribute = pAttribute;
  601. this->Attach( this->m_pAttribute->GetAttributeData() );
  602. }
  603. else
  604. {
  605. this->m_pAttribute = NULL;
  606. this->Attach( NULL );
  607. }
  608. }
  609. void Init( CDmElement *pElement, const char *pAttributeName, bool bAddAttribute = false )
  610. {
  611. CDmAttribute *pAttribute = NULL;
  612. if ( pElement && pAttributeName && pAttributeName[0] )
  613. {
  614. pAttribute = pElement->GetAttribute( pAttributeName );
  615. if ( bAddAttribute && !pAttribute )
  616. {
  617. pAttribute = pElement->CreateAttribute( pAttributeName, AT_ELEMENT_ARRAY );
  618. // FIXME: Should we do this?
  619. pAttribute->SetElementTypeSymbol( T::GetStaticTypeSymbol() );
  620. }
  621. }
  622. this->Init( pAttribute );
  623. }
  624. int Count() const
  625. {
  626. return IsValid() ? this->Value().Count() : 0;
  627. }
  628. bool IsValid() const
  629. {
  630. return this->m_pAttribute != NULL;
  631. }
  632. template< typename C > CDmrElementArray<T>& operator=( const C &val )
  633. {
  634. CopyArray( val.Base(), val.Count() );
  635. return *this;
  636. }
  637. // NOTE: The copy operator= must be defined in addition to the generic one
  638. const CDmrElementArray<T>& operator=( const CDmrElementArray<T> &val )
  639. {
  640. CopyArray( val.Base(), val.Count() );
  641. return *this;
  642. }
  643. };
  644. //-----------------------------------------------------------------------------
  645. //
  646. // Inline methods for CDmaVar
  647. //
  648. //-----------------------------------------------------------------------------
  649. template< class T > inline CDmaVar<T>::CDmaVar( )
  650. {
  651. m_pAttribute = NULL;
  652. CDmAttributeInfo<T>::SetDefaultValue( m_Storage );
  653. }
  654. template< class T > inline void CDmaVar<T>::Init( CDmElement *pOwner, const char *pAttributeName, int flags )
  655. {
  656. Assert( pOwner );
  657. m_pAttribute = pOwner->AddExternalAttribute( pAttributeName, CDmAttributeInfo<T>::AttributeType(), &m_Storage );
  658. Assert( m_pAttribute );
  659. if ( flags )
  660. {
  661. m_pAttribute->AddFlag( flags );
  662. }
  663. }
  664. template< class T > inline void CDmaVar<T>::InitAndSet( CDmElement *pOwner, const char *pAttributeName, const T &value, int flags )
  665. {
  666. this->Init( pOwner, pAttributeName );
  667. this->Set( value );
  668. // this has to happen AFTER set so the set happens before FATTRIB_READONLY
  669. if ( flags )
  670. {
  671. m_pAttribute->AddFlag( flags );
  672. }
  673. }
  674. template< class T > inline const T& CDmaVar<T>::Set( const T &val )
  675. {
  676. Assert( m_pAttribute );
  677. m_pAttribute->SetValue( val );
  678. return m_Storage;
  679. }
  680. template< class T > inline const T& CDmaVar<T>::operator=( const T &val )
  681. {
  682. return this->Set( val );
  683. }
  684. template< class T > inline const CDmaVar<T>& CDmaVar<T>::operator=( const CDmaVar<T>& src )
  685. {
  686. this->Set( src.Get() );
  687. return *this;
  688. }
  689. template< class T > inline const T& CDmaVar<T>::operator+=( const T &val )
  690. {
  691. return this->Set( this->Value() + val );
  692. }
  693. template< class T > inline const T& CDmaVar<T>::operator-=( const T &val )
  694. {
  695. return this->Set( this->Value() - val );
  696. }
  697. template< class T > inline const T& CDmaVar<T>::operator/=( const T &val )
  698. {
  699. return this->Set( this->Value() / val );
  700. }
  701. template< class T > inline const T& CDmaVar<T>::operator*=( const T &val )
  702. {
  703. return this->Set( this->Value() * val );
  704. }
  705. template< class T > inline const T& CDmaVar<T>::operator^=( const T &val )
  706. {
  707. return this->Set( this->Value() ^ val );
  708. }
  709. template< class T > inline const T& CDmaVar<T>::operator|=( const T &val )
  710. {
  711. return this->Set( this->Value() | val );
  712. }
  713. template< class T > inline const T& CDmaVar<T>::operator&=( const T &val )
  714. {
  715. return this->Set( this->Value() & val );
  716. }
  717. template< class T > inline T CDmaVar<T>::operator++()
  718. {
  719. return this->Set( this->Value() + 1 );
  720. }
  721. template< class T > inline T CDmaVar<T>::operator--()
  722. {
  723. return this->Set( this->Value() - 1 );
  724. }
  725. template< class T > inline T CDmaVar<T>::operator++( int ) // postfix version..
  726. {
  727. T oldValue = this->Value();
  728. this->Set( this->Value() + 1 );
  729. return oldValue;
  730. }
  731. template< class T > inline T CDmaVar<T>::operator--( int ) // postfix version..
  732. {
  733. T oldValue = this->Value();
  734. this->Set( this->Value() - 1 );
  735. return oldValue;
  736. }
  737. template< class T > inline CDmaVar<T>::operator const T&() const
  738. {
  739. return this->Value();
  740. }
  741. template< class T > inline const T& CDmaVar<T>::Get() const
  742. {
  743. return this->Value();
  744. }
  745. template< class T > inline const T* CDmaVar<T>::operator->() const
  746. {
  747. return &this->Value();
  748. }
  749. template< class T > inline CDmAttribute *CDmaVar<T>::GetAttribute()
  750. {
  751. Assert( m_pAttribute );
  752. return m_pAttribute;
  753. }
  754. template< class T > inline const CDmAttribute *CDmaVar<T>::GetAttribute() const
  755. {
  756. Assert( m_pAttribute );
  757. return m_pAttribute;
  758. }
  759. template< class T > inline bool CDmaVar<T>::IsDirty() const
  760. {
  761. Assert( m_pAttribute );
  762. return m_pAttribute->IsFlagSet( FATTRIB_DIRTY );
  763. }
  764. template< class T > inline const T& CDmaVar<T>::Value() const
  765. {
  766. return m_Storage;
  767. }
  768. template< class T > inline T& CDmaVar<T>::Value()
  769. {
  770. return m_Storage;
  771. }
  772. template<> inline const DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value() const
  773. {
  774. return m_Storage.m_Handle;
  775. }
  776. template<> inline DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value()
  777. {
  778. return m_Storage.m_Handle;
  779. }
  780. template< class T > inline const typename CDmaVar<T>::D& CDmaVar<T>::Storage() const
  781. {
  782. return m_Storage;
  783. }
  784. template< class T > inline typename CDmaVar<T>::D& CDmaVar<T>::Storage()
  785. {
  786. return m_Storage;
  787. }
  788. //-----------------------------------------------------------------------------
  789. //
  790. // Inline methods for CDmaColor
  791. //
  792. //-----------------------------------------------------------------------------
  793. inline void CDmaColor::SetColor( int r, int g, int b, int a )
  794. {
  795. Color clr( r, g, b, a );
  796. m_pAttribute->SetValue( clr );
  797. }
  798. inline void CDmaColor::SetRed( int r )
  799. {
  800. Color org = this->Value();
  801. org[ 0 ] = r;
  802. m_pAttribute->SetValue( org );
  803. }
  804. inline void CDmaColor::SetGreen( int g )
  805. {
  806. Color org = this->Value();
  807. org[ 1 ] = g;
  808. m_pAttribute->SetValue( org );
  809. }
  810. inline void CDmaColor::SetBlue( int b )
  811. {
  812. Color org = this->Value();
  813. org[ 2 ] = b;
  814. m_pAttribute->SetValue( org );
  815. }
  816. inline void CDmaColor::SetAlpha( int a )
  817. {
  818. Color org = this->Value();
  819. org[ 3 ] = a;
  820. m_pAttribute->SetValue( org );
  821. }
  822. inline unsigned char CDmaColor::r() const
  823. {
  824. return (unsigned char)this->Value().r();
  825. }
  826. inline unsigned char CDmaColor::g() const
  827. {
  828. return (unsigned char)this->Value().g();
  829. }
  830. inline unsigned char CDmaColor::b() const
  831. {
  832. return (unsigned char)this->Value().b();
  833. }
  834. inline unsigned char CDmaColor::a() const
  835. {
  836. return (unsigned char)this->Value().a();
  837. }
  838. inline const unsigned char &CDmaColor::operator[](int index) const
  839. {
  840. return this->Value()[index];
  841. }
  842. inline void CDmaColor::SetRawColor( int color )
  843. {
  844. Color clr;
  845. clr.SetRawColor( color );
  846. m_pAttribute->SetValue( clr );
  847. }
  848. //-----------------------------------------------------------------------------
  849. //
  850. // Inline methods for CDmaTime
  851. //
  852. //-----------------------------------------------------------------------------
  853. inline void CDmaTime::SetTenthsOfMS( int tms )
  854. {
  855. Set( DmeTime_t( tms ) );
  856. }
  857. inline void CDmaTime::SetSeconds( float seconds )
  858. {
  859. Set( DmeTime_t( seconds ) );
  860. }
  861. inline int CDmaTime::GetTenthsOfMS() const
  862. {
  863. return this->Value().GetTenthsOfMS();
  864. }
  865. inline float CDmaTime::GetSeconds() const
  866. {
  867. return this->Value().GetSeconds();
  868. }
  869. //-----------------------------------------------------------------------------
  870. //
  871. // Inline methods for CDmaString
  872. //
  873. //-----------------------------------------------------------------------------
  874. inline const char *CDmaString::Get( ) const
  875. {
  876. return this->Value().String();
  877. }
  878. inline CDmaString::operator const char*() const
  879. {
  880. return this->Value().String();
  881. }
  882. inline void CDmaString::InitAndSet( CDmElement *pOwner, const char *pAttributeName, const char *pValue, int flags )
  883. {
  884. CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pValue );
  885. CDmaVar< CUtlSymbolLarge >::InitAndSet( pOwner, pAttributeName, symbol, flags );
  886. }
  887. inline void CDmaString::Set( const char *pValue )
  888. {
  889. CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pValue );
  890. m_pAttribute->SetValue( symbol );
  891. }
  892. // Returns strlen
  893. inline int CDmaString::Length() const
  894. {
  895. return V_strlen( this->Value().String() );
  896. }
  897. inline bool CDmaString::IsEmpty() const
  898. {
  899. if ( this->Value() == UTL_INVAL_SYMBOL_LARGE )
  900. return true;
  901. const char *pString = this->Value().String();
  902. if ( pString == NULL )
  903. return true;
  904. if ( *pString == 0 )
  905. return true;
  906. return false;
  907. }
  908. inline CDmaString &CDmaString::operator=( const char *src )
  909. {
  910. Set( src );
  911. return *this;
  912. }
  913. inline const CDmaString& CDmaString::operator=( const CDmaString& src )
  914. {
  915. Set( src.Get() );
  916. return *this;
  917. }
  918. //-----------------------------------------------------------------------------
  919. //
  920. // Inline methods for CDmaBinaryBlock
  921. //
  922. //-----------------------------------------------------------------------------
  923. inline void CDmaBinaryBlock::Get( void *pValue, int nMaxLen ) const
  924. {
  925. this->Value().Get( pValue, nMaxLen );
  926. }
  927. inline void CDmaBinaryBlock::Set( const void *pValue, int nLen )
  928. {
  929. CUtlBinaryBlock block( pValue, nLen );
  930. m_pAttribute->SetValue( block );
  931. }
  932. inline const void *CDmaBinaryBlock::Get() const
  933. {
  934. return this->Value().Get();
  935. }
  936. inline const unsigned char& CDmaBinaryBlock::operator[]( int i ) const
  937. {
  938. return this->Value()[i];
  939. }
  940. inline int CDmaBinaryBlock::Length() const
  941. {
  942. return this->Value().Length();
  943. }
  944. //-----------------------------------------------------------------------------
  945. //
  946. // Inline methods for CDmaElement
  947. //
  948. //-----------------------------------------------------------------------------
  949. template <class T>
  950. inline void CDmaElement<T>::InitAndCreate( CDmElement *pOwner, const char *pAttributeName, const char *pElementName, int flags )
  951. {
  952. Init( pOwner, pAttributeName );
  953. DmElementHandle_t hElement = DMELEMENT_HANDLE_INVALID;
  954. if ( !g_pDataModel->IsUnserializing() )
  955. {
  956. hElement = g_pDataModel->CreateElement( T::GetStaticTypeSymbol(), pElementName, pOwner->GetFileId() );
  957. }
  958. Assert( this->m_pAttribute );
  959. this->m_pAttribute->SetValue( hElement );
  960. // this has to happen AFTER set so the set happens before FATTRIB_READONLY
  961. this->m_pAttribute->AddFlag( flags | FATTRIB_MUSTCOPY );
  962. }
  963. template <class T>
  964. inline void CDmaElement<T>::Init( CDmElement *pOwner, const char *pAttributeName, int flags )
  965. {
  966. BaseClass::Init( pOwner, pAttributeName );
  967. Assert( this->m_pAttribute );
  968. this->m_pAttribute->SetElementTypeSymbol( T::GetStaticTypeSymbol() );
  969. if ( flags )
  970. {
  971. this->m_pAttribute->AddFlag( flags );
  972. }
  973. }
  974. template <class T>
  975. inline CUtlSymbolLarge CDmaElement<T>::GetElementType() const
  976. {
  977. return this->Data().m_ElementType;
  978. }
  979. template <class T>
  980. inline T* CDmaElement<T>::GetElement() const
  981. {
  982. CDmElement *pElement = g_pDataModel->GetElement( this->Value() );
  983. Assert( !pElement || pElement->IsA( T::GetStaticTypeSymbol() ) );
  984. return static_cast< T* >( pElement );
  985. }
  986. template <class T>
  987. inline T* CDmaElement<T>::operator->() const
  988. {
  989. return GetElement();
  990. }
  991. template <class T>
  992. inline CDmaElement<T>::operator T*() const
  993. {
  994. return GetElement();
  995. }
  996. template <class T>
  997. inline void CDmaElement<T>::Set( T* pElement )
  998. {
  999. Assert( m_pAttribute );
  1000. m_pAttribute->SetValue( pElement ? pElement->GetHandle() : DMELEMENT_HANDLE_INVALID );
  1001. }
  1002. template <class T>
  1003. inline bool CDmaElement<T>::operator!() const
  1004. {
  1005. return ( GetElement() == NULL );
  1006. }
  1007. //-----------------------------------------------------------------------------
  1008. //
  1009. // Inline methods for CDmaArrayBase
  1010. //
  1011. //-----------------------------------------------------------------------------
  1012. template< class T, class B >
  1013. inline const CUtlVector<T>& CDmaArrayConstBase<T,B>::Get() const
  1014. {
  1015. return this->Value();
  1016. }
  1017. template< class T, class B >
  1018. inline const T *CDmaArrayConstBase<T,B>::Base() const
  1019. {
  1020. return this->Value().Base();
  1021. }
  1022. template< class T, class B >
  1023. inline const T& CDmaArrayConstBase<T,B>::operator[]( int i ) const
  1024. {
  1025. return this->Value()[ i ];
  1026. }
  1027. template< class T, class B >
  1028. const T& CDmaArrayConstBase<T,B>::Element( int i ) const
  1029. {
  1030. return this->Value()[ i ];
  1031. }
  1032. template< class T, class B >
  1033. inline const T& CDmaArrayConstBase<T,B>::Get( int i ) const
  1034. {
  1035. return this->Value()[ i ];
  1036. }
  1037. template< class T, class B >
  1038. const void* CDmaArrayConstBase<T,B>::GetUntyped( int i ) const
  1039. {
  1040. return &( this->Value()[ i ] );
  1041. }
  1042. template< class T, class B >
  1043. inline int CDmaArrayConstBase<T,B>::Count() const
  1044. {
  1045. return this->Value().Count();
  1046. }
  1047. template< class T, class B >
  1048. inline bool CDmaArrayConstBase<T,B>::IsValidIndex( int i ) const
  1049. {
  1050. return this->Value().IsValidIndex( i );
  1051. }
  1052. template< class T, class B >
  1053. inline int CDmaArrayConstBase<T,B>::InvalidIndex( void ) const
  1054. {
  1055. return this->Value().InvalidIndex();
  1056. }
  1057. template< class T, class B >
  1058. inline const CDmAttribute *CDmaArrayConstBase<T,B>::GetAttribute() const
  1059. {
  1060. Assert( m_pAttribute );
  1061. return m_pAttribute;
  1062. }
  1063. template< class T, class B >
  1064. inline CDmElement *CDmaArrayConstBase<T,B>::GetOwner()
  1065. {
  1066. return m_pAttribute->GetOwner();
  1067. }
  1068. template< class T, class B >
  1069. inline bool CDmaArrayConstBase<T,B>::IsDirty() const
  1070. {
  1071. return m_pAttribute->IsFlagSet( FATTRIB_DIRTY );
  1072. }
  1073. template< class T, class B >
  1074. inline CDmAttribute *CDmaArrayBase<T,B>::GetAttribute()
  1075. {
  1076. Assert( this->m_pAttribute );
  1077. return this->m_pAttribute;
  1078. }
  1079. template< class T, class B >
  1080. inline const CDmAttribute *CDmaArrayBase<T,B>::GetAttribute() const
  1081. {
  1082. Assert( this->m_pAttribute );
  1083. return this->m_pAttribute;
  1084. }
  1085. //-----------------------------------------------------------------------------
  1086. //
  1087. // Inline methods for CDmaStringArrayBase
  1088. //
  1089. //-----------------------------------------------------------------------------
  1090. template< class B >
  1091. inline const char *CDmaStringArrayConstBase<B>::operator[]( int i ) const
  1092. {
  1093. return this->Value()[ i ].String();
  1094. }
  1095. template< class B >
  1096. inline const char *CDmaStringArrayConstBase<B>::Element( int i ) const
  1097. {
  1098. return this->Value()[ i ].String();
  1099. }
  1100. template< class B >
  1101. inline const char *CDmaStringArrayConstBase<B>::Get( int i ) const
  1102. {
  1103. return this->Value()[ i ].String();
  1104. }
  1105. template< class B >
  1106. inline const CUtlVector< CUtlSymbolLarge > &CDmaStringArrayConstBase<B>::Get() const
  1107. {
  1108. return this->Value();
  1109. }
  1110. // Returns strlen of element i
  1111. template< class B >
  1112. inline int CDmaStringArrayConstBase<B>::Length( int i ) const
  1113. {
  1114. return this->Value()[i].Length();
  1115. }
  1116. template< class B >
  1117. inline void CDmaStringArrayBase<B>::Set( int i, const char * pValue )
  1118. {
  1119. CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pValue );
  1120. BaseClass::Set( i, symbol );
  1121. }
  1122. // Adds an element, uses copy constructor
  1123. template< class B >
  1124. inline int CDmaStringArrayBase<B>::AddToTail( const char *pValue )
  1125. {
  1126. CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pValue );
  1127. return BaseClass::AddToTail( symbol );
  1128. }
  1129. template< class B >
  1130. inline int CDmaStringArrayBase<B>::InsertBefore( int elem, const char *pValue )
  1131. {
  1132. CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pValue );
  1133. return BaseClass::InsertBefore( elem, symbol );
  1134. }
  1135. //-----------------------------------------------------------------------------
  1136. //
  1137. // Inline methods for CDmaElementArrayBase
  1138. //
  1139. //-----------------------------------------------------------------------------
  1140. template< class E, class B >
  1141. inline CUtlSymbolLarge CDmaElementArrayConstBase<E,B>::GetElementType() const
  1142. {
  1143. return this->Data().m_ElementType;
  1144. }
  1145. template< class E, class B >
  1146. inline E *CDmaElementArrayConstBase<E,B>::operator[]( int i ) const
  1147. {
  1148. return GetElement<E>( this->Value()[i] );
  1149. }
  1150. template< class E, class B >
  1151. inline E *CDmaElementArrayConstBase<E,B>::Element( int i ) const
  1152. {
  1153. return GetElement<E>( this->Value()[i] );
  1154. }
  1155. template< class E, class B >
  1156. inline E *CDmaElementArrayConstBase<E,B>::Get( int i ) const
  1157. {
  1158. return GetElement<E>( this->Value()[i] );
  1159. }
  1160. template< class E, class B >
  1161. inline const DmElementHandle_t& CDmaElementArrayConstBase<E,B>::GetHandle( int i ) const
  1162. {
  1163. return this->Value()[i];
  1164. }
  1165. template< class E, class B >
  1166. inline const CUtlVector< DmElementHandle_t > &CDmaElementArrayConstBase<E,B>::Get() const
  1167. {
  1168. return this->Value();
  1169. }
  1170. // Search
  1171. template< class E, class B >
  1172. inline int CDmaElementArrayConstBase<E,B>::Find( const E *pValue ) const
  1173. {
  1174. if ( !pValue )
  1175. return -1;
  1176. return B::Find( pValue->GetHandle() );
  1177. }
  1178. template< class E, class B >
  1179. inline int CDmaElementArrayConstBase<E,B>::Find( DmElementHandle_t h ) const
  1180. {
  1181. return B::Find( h );
  1182. }
  1183. template< class E, class B >
  1184. inline void CDmaElementArrayBase<E,B>::SetHandle( int i, DmElementHandle_t h )
  1185. {
  1186. BaseClass::Set( i, h );
  1187. }
  1188. template< class E, class B >
  1189. inline void CDmaElementArrayBase<E,B>::Set( int i, E *pElement )
  1190. {
  1191. BaseClass::Set( i, pElement ? pElement->GetHandle() : DMELEMENT_HANDLE_INVALID );
  1192. }
  1193. // Adds an element, uses copy constructor
  1194. template< class E, class B >
  1195. inline int CDmaElementArrayBase<E,B>::AddToTail( )
  1196. {
  1197. return BaseClass::AddToTail( );
  1198. }
  1199. template< class E, class B >
  1200. inline int CDmaElementArrayBase<E,B>::AddToTail( E *pValue )
  1201. {
  1202. return BaseClass::AddToTail( pValue ? pValue->GetHandle() : DMELEMENT_HANDLE_INVALID );
  1203. }
  1204. template< class E, class B >
  1205. inline int CDmaElementArrayBase<E,B>::AddToTail( DmElementHandle_t src )
  1206. {
  1207. return BaseClass::AddToTail( src );
  1208. }
  1209. template< class E, class B >
  1210. inline int CDmaElementArrayBase<E,B>::InsertBefore( int elem )
  1211. {
  1212. return BaseClass::InsertBefore( elem );
  1213. }
  1214. template< class E, class B >
  1215. inline int CDmaElementArrayBase<E,B>::InsertBefore( int elem, E *pValue )
  1216. {
  1217. return BaseClass::InsertBefore( elem, pValue ? pValue->GetHandle() : DMELEMENT_HANDLE_INVALID );
  1218. }
  1219. template< class E, class B >
  1220. inline int CDmaElementArrayBase<E,B>::InsertBefore( int elem, DmElementHandle_t src )
  1221. {
  1222. return BaseClass::InsertBefore( elem, src );
  1223. }
  1224. //-----------------------------------------------------------------------------
  1225. //
  1226. // Inline methods for CDmrGenericArray
  1227. //
  1228. //-----------------------------------------------------------------------------
  1229. inline const CDmAttribute *CDmrGenericArrayConst::GetAttribute() const
  1230. {
  1231. Assert( m_pAttribute );
  1232. return m_pAttribute;
  1233. }
  1234. inline bool CDmrGenericArrayConst::IsValid() const
  1235. {
  1236. return m_pAttribute != NULL;
  1237. }
  1238. inline CDmAttribute *CDmrGenericArray::GetAttribute()
  1239. {
  1240. Assert( m_pAttribute );
  1241. return m_pAttribute;
  1242. }
  1243. inline const CDmAttribute *CDmrGenericArray::GetAttribute() const
  1244. {
  1245. Assert( m_pAttribute );
  1246. return m_pAttribute;
  1247. }
  1248. #endif // DMATTRIBUTEVAR_H