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.

58 lines
2.1 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Declaration of the CDmeAttributeReference class, a simple DmElement
  4. // used to store references to attributes within other DmElements.
  5. //
  6. //=============================================================================
  7. #ifndef DMEATTRIBUTEREFERENCE_H
  8. #define DMEATTRIBUTEREFERENCE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "datamodel/dmattributevar.h"
  13. //-------------------------------------------------------------------------------------------------
  14. // The CDmeAttributeReference class provides storage of the information needed to access an
  15. // attribute in any element. It also provides an interface for accessing the attribute which
  16. // automatically looks up the attribute and caches the handle.
  17. //-------------------------------------------------------------------------------------------------
  18. class CDmeAttributeReference : public CDmElement
  19. {
  20. DEFINE_ELEMENT( CDmeAttributeReference, CDmElement );
  21. public:
  22. // Process notifications of changed attributes and update the attribute handles if needed.
  23. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  24. // Set the attribute by specifying the element, name of the attribute and optionally the array index of the attribute.
  25. bool SetAttribute( CDmElement* pElement, const char* pchAttributeName, int index = 0 );
  26. // Get the attribute using the cached handle or looking up the handle if needed.
  27. CDmAttribute* GetReferencedAttribute() const;
  28. // Get the value of the referenced attribute
  29. const void *GetAttributeValue( DmAttributeType_t &type ) const;
  30. // Set the value of the referenced attribute
  31. void SetAttributeValue( const void *pValue, DmAttributeType_t type ) const;
  32. // Determine if the attribute reference points to a valid attribute
  33. bool IsValid() const;
  34. private:
  35. // Lookup and cache the attribute handle
  36. CDmAttribute* LookupAttributeHandle() const;
  37. CDmaElement< CDmElement > m_Element;
  38. CDmaString m_AttributeName;
  39. CDmaVar< int > m_AttributeIndex;
  40. mutable DmAttributeHandle_t m_AttributeHandle;
  41. };
  42. #endif // DMEATTRIBUTEREFERENCE_H