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