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.

106 lines
2.7 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMVAR_H
  7. #define DMVAR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CDmAttribute;
  12. //-----------------------------------------------------------------------------
  13. // Helper template for external attributes
  14. //-----------------------------------------------------------------------------
  15. template< typename T >
  16. class CDmaVar
  17. {
  18. typedef typename CDmAttributeInfo< T >::StorageType_t D;
  19. public:
  20. CDmaVar( );
  21. // Setup to be used in OnConstruction methods of DmElements
  22. void Init( CDmElement *pOwner, const char *pAttributeName, int flags = 0 );
  23. void InitAndSet( CDmElement *pOwner, const char *pAttributeName, const T &value, int flags = 0 );
  24. // Set/get
  25. const T& Set( const T &val );
  26. const T& Get() const;
  27. // Cast operators
  28. operator const T&() const;
  29. const T* operator->() const;
  30. // Assignment operator
  31. const CDmaVar<T>& operator=( const CDmaVar<T>& src );
  32. // Math utility operations
  33. const T& operator=( const T &val );
  34. const T& operator+=( const T &val );
  35. const T& operator-=( const T &val );
  36. const T& operator/=( const T &val );
  37. const T& operator*=( const T &val );
  38. const T& operator^=( const T &val );
  39. const T& operator|=( const T &val );
  40. const T& operator&=( const T &val );
  41. T operator++();
  42. T operator--();
  43. T operator++( int ); // postfix version..
  44. T operator--( int ); // postfix version..
  45. // Returns the attribute associated with the var
  46. CDmAttribute *GetAttribute();
  47. const CDmAttribute *GetAttribute() const;
  48. // Is the attribute dirty?
  49. bool IsDirty() const;
  50. protected:
  51. const T& Value() const;
  52. T& Value();
  53. const D& Storage() const;
  54. D& Storage();
  55. private:
  56. D m_Storage;
  57. protected:
  58. CDmAttribute *m_pAttribute;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // Specialization for string
  62. //-----------------------------------------------------------------------------
  63. class CDmaString : public CDmaVar< CUtlSymbolLarge >
  64. {
  65. public:
  66. const char *GetString() const;
  67. const char *Get( ) const;
  68. operator const char*() const;
  69. void InitAndSet( CDmElement *pOwner, const char *pAttributeName, const char *pValue, int flags = 0 );
  70. void Set( const char *pValue );
  71. CDmaString &operator=( const char *src );
  72. const CDmaString& operator=( const CDmaString& src );
  73. // Returns strlen
  74. int Length() const;
  75. bool IsEmpty() const;
  76. };
  77. //-----------------------------------------------------------------------------
  78. //
  79. // Inline methods for CDmaString
  80. //
  81. //-----------------------------------------------------------------------------
  82. inline const char *CDmaString::GetString() const
  83. {
  84. return this->Value().String();
  85. }
  86. #endif // DMVAR_H