Team Fortress 2 Source Code as on 22/4/2020
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.

1481 lines
38 KiB

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