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.

130 lines
4.8 KiB

  1. //====== Copyright �, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Shared object based on a CBaseRecord subclass
  4. //
  5. //=============================================================================
  6. #ifndef SCHEMASHAREDOBJECT_H
  7. #define SCHEMASHAREDOBJECT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #ifndef GC
  12. #error "CSchemaSharedObject is only intended for use on GC-only shared objects. It shouldn't be included on the client"
  13. #endif
  14. #if defined( DEBUG )
  15. #include "gcbase.h"
  16. #endif
  17. namespace GCSDK
  18. {
  19. //----------------------------------------------------------------------------
  20. // Purpose: Contains helper functions to deal with passed in CRecordInfo,
  21. // so that a CRecordInfo can be built on the fly
  22. //----------------------------------------------------------------------------
  23. class CSchemaSharedObjectHelper
  24. {
  25. public:
  26. static bool BYieldingAddInsertToTransaction( CSQLAccess & sqlAccess, CRecordBase *pRecordBase );
  27. static bool BYieldingAddWriteToTransaction( CSQLAccess & sqlAccess, CRecordBase *pRecordBase, const CColumnSet & csDatabaseDirty );
  28. static bool BYieldingAddRemoveToTransaction( CSQLAccess & sqlAccess, CRecordBase *pRecordBase );
  29. static bool BYieldingAddToDatabase( CRecordBase *pRecordBase );
  30. static bool BYieldingReadFromDatabase( CRecordBase *pRecordBase );
  31. static void Dump( const CRecordBase *pRecordBase );
  32. };
  33. //----------------------------------------------------------------------------
  34. // Purpose: Base class for CSchemaSharedObject. This is where all the actual
  35. // code lives.
  36. //----------------------------------------------------------------------------
  37. class CSchemaSharedObjectBase : public CSharedObject
  38. {
  39. public:
  40. typedef CSharedObject BaseClass;
  41. CSchemaSharedObjectBase( CRecordInfo *pRecordInfo ) : BaseClass() {}
  42. virtual bool BYieldingAddInsertToTransaction( CSQLAccess & sqlAccess );
  43. virtual bool BYieldingAddWriteToTransaction( CSQLAccess & sqlAccess, const CUtlVector< int > &fields );
  44. virtual bool BYieldingAddRemoveToTransaction( CSQLAccess & sqlAccess );
  45. virtual bool BYieldingAddToDatabase();
  46. virtual bool BYieldingReadFromDatabase() ;
  47. // schema shared objects are GC-only and are never sent to clients.
  48. virtual bool BIsNetworked() const { return false; }
  49. virtual bool BAddCreateToMessage( CUtlBuffer & bufCreate ) const { return false; }
  50. virtual bool BAddFullCreateToMessage( CUtlBuffer & bufCreate ) const { return false; }
  51. virtual bool BAddUpdateToMessage( CUtlBuffer & bufUpdate, const CUtlVector< int > &fields ) const { return false; }
  52. virtual bool BAddDestroyToMessage( CUtlBuffer & bufDestroy ) const { return false; }
  53. virtual bool BParseCreateFromMessage( const CUtlBuffer & bufCreate ) { return false; }
  54. virtual bool BUpdateFromNetwork( const CSharedObject & objUpdate, const CUtlBuffer & bufUpdate ) { return false; }
  55. virtual bool BIsKeyLess( const CSharedObject & soRHS ) const ;
  56. virtual void Copy( const CSharedObject & soRHS );
  57. virtual void Dump() const;
  58. // virtual bool BIsNetworkDirty() const { return false; }
  59. // virtual void MakeNetworkClean() {}
  60. const CRecordInfo * GetRecordInfo() const;
  61. #ifdef DBGFLAG_VALIDATE
  62. virtual void Validate( CValidator &validator, const char *pchName );
  63. #endif
  64. protected:
  65. virtual CRecordBase *GetPObject() = 0;
  66. const CRecordBase *GetPObject() const { return const_cast<CSchemaSharedObjectBase *>(this)->GetPObject(); }
  67. bool BParseFieldsFromMessage( CGCMsgBase *pMsg, const CColumnSet & csFields );
  68. CColumnSet GetDatabaseDirtyColumnSet( const CUtlVector< int > &fields ) const;
  69. // virtual bool BIsFieldDatabaseDirty( int nField ) const = 0;
  70. // virtual CColumnSet GetDirtyColumnSet( ) const = 0;
  71. private:
  72. };
  73. //----------------------------------------------------------------------------
  74. // Purpose: Template for making a shared object that uses a specific Schema
  75. // class for its data store.
  76. //----------------------------------------------------------------------------
  77. template< typename SchObject_t, int nTypeID >
  78. class CSchemaSharedObject : public CSchemaSharedObjectBase
  79. {
  80. public:
  81. CSchemaSharedObject()
  82. : CSchemaSharedObjectBase( GCSDK::GSchemaFull().GetSchema( SchObject_t::k_iTable ).GetRecordInfo() )
  83. {
  84. }
  85. ~CSchemaSharedObject()
  86. {
  87. #ifdef DEBUG
  88. // Ensure this SO is not in any cache, or we have an error.
  89. Assert( !GGCBase()->IsSOCached( this, nTypeID ) );
  90. #endif
  91. }
  92. virtual int GetTypeID() const { return nTypeID; }
  93. SchObject_t & Obj() { return m_schObject; }
  94. const SchObject_t & Obj() const { return m_schObject; }
  95. typedef SchObject_t SchObjectType_t;
  96. public:
  97. const static int k_nTypeID = nTypeID;
  98. const static int k_iFieldMax = SchObject_t::k_iFieldMax;
  99. protected:
  100. CRecordBase *GetPObject() { return &m_schObject; }
  101. private:
  102. SchObject_t m_schObject;
  103. };
  104. } // namespace GCSDK
  105. #endif //SCHEMASHAREDOBJECT_H