-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathschemaModule.h
More file actions
171 lines (151 loc) · 5.09 KB
/
Copy pathschemaModule.h
File metadata and controls
171 lines (151 loc) · 5.09 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef SCHEMAMODULE_H
#define SCHEMAMODULE_H
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "sc_export.h"
class AttrDescriptor;
class EntityDescriptor;
class Schema;
class TypeDescriptor;
enum SchemaModuleSlotKind {
SchemaModuleSlot_Entity,
SchemaModuleSlot_Type,
SchemaModuleSlot_EnumType,
SchemaModuleSlot_SelectType,
SchemaModuleSlot_AggregateType,
SchemaModuleSlot_ArrayType,
SchemaModuleSlot_ListType,
SchemaModuleSlot_SetType,
SchemaModuleSlot_BagType,
SchemaModuleSlot_Attribute,
SchemaModuleSlot_DerivedAttribute,
SchemaModuleSlot_InverseAttribute
};
struct SC_CORE_EXPORT SchemaModuleSlot {
const void * slot;
SchemaModuleSlotKind kind;
};
enum SchemaModuleImageVersion {
SchemaModuleImageVersion_1 = 1,
SchemaModuleImageVersion_2 = 2
};
enum SchemaModuleImageFlags {
SchemaModuleImage_FullMetadata = 0,
SchemaModuleImage_StructuralMetadata = 1u << 0
};
/**
* Relocation-free generated header for a schema module image.
*
* Version 1 records only stable generated-ID counts. Version 2 describes
* one bounded block of offset-based schemas, descriptors, metadata, and
* strings. Runtime loading validates the complete block before constructing
* descriptors or changing a Registry.
*/
struct SC_CORE_EXPORT SchemaModuleImage {
uint32_t version;
uint32_t entityCount;
uint32_t typeCount;
uint32_t attributeCount;
/* Version 2 fields. Version 1 initializers leave these zero. */
uint32_t byteSize;
uint32_t flags;
uint32_t schemaCount;
uint32_t stringBytes;
uint32_t schemaOffset;
uint32_t entityOffset;
uint32_t typeOffset;
uint32_t attributeOffset;
uint32_t aggregateCount;
uint32_t aggregateOffset;
uint32_t referenceCount;
uint32_t referenceOffset;
uint32_t ruleCount;
uint32_t ruleOffset;
uint32_t schemaTextCount;
uint32_t schemaTextOffset;
uint32_t enumElementCount;
uint32_t enumElementOffset;
uint32_t stringOffset;
uint32_t reserved;
uint64_t fingerprint;
uint32_t renameCount;
uint32_t renameOffset;
};
class SchemaModule;
/**
* Per-load descriptor collection used by packed API v2 schema images.
*
* Keeping this state explicit makes independent schema loads reentrant and
* avoids the process-global capture map retained for version-1 images.
*/
class SC_CORE_EXPORT SchemaLoadContext {
class Impl;
Impl * _impl;
SchemaLoadContext( const SchemaLoadContext & );
SchemaLoadContext & operator=( const SchemaLoadContext & );
friend class SchemaModule;
public:
SchemaLoadContext();
~SchemaLoadContext();
void Begin( Schema & schema );
void RecordEntity( Schema & schema, const EntityDescriptor * entity );
void RecordType( Schema & schema, const TypeDescriptor * type );
void RecordAttribute( Schema & schema, const AttrDescriptor * attribute );
};
SC_CORE_EXPORT void RecordSchemaModuleEntity(
Schema & schema, const EntityDescriptor * entity );
SC_CORE_EXPORT void RecordSchemaModuleType(
Schema & schema, const TypeDescriptor * type );
SC_CORE_EXPORT void RecordSchemaModuleAttribute(
Schema & schema, const AttrDescriptor * attribute );
SC_CORE_EXPORT void BeginSchemaModuleImage( Schema & schema );
/**
* Stable API v2 view of a generated schema.
*
* Generated EntityId, TypeId, and AttributeId enumerations are converted to
* indexes before calling this class. Keeping the public lookup API separate
* from generated descriptor globals allows the underlying representation to
* move from C++ objects to packed schema data without another API break.
*/
class SC_CORE_EXPORT SchemaModule {
Schema * _schema;
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::vector<const EntityDescriptor *> _entities;
std::vector<const TypeDescriptor *> _types;
std::vector<const AttrDescriptor *> _attributes;
uint64_t _fingerprint;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
public:
SchemaModule();
~SchemaModule();
void Initialize(
Schema & schema,
const EntityDescriptor * const * entities, size_t entityCount,
const TypeDescriptor * const * types, size_t typeCount,
const AttrDescriptor * const * attributes, size_t attributeCount );
void InitializeFromSlots(
Schema & schema,
const SchemaModuleSlot * entities, size_t entityCount,
const SchemaModuleSlot * types, size_t typeCount,
const SchemaModuleSlot * attributes, size_t attributeCount );
void InitializeFromImage( Schema & schema,
const SchemaModuleImage & image );
bool InitializeFromContext( Schema & schema, SchemaLoadContext & context,
uint64_t fingerprint );
bool IsInitialized() const;
const Schema & GetSchema() const;
const EntityDescriptor * Entity( size_t id ) const;
const TypeDescriptor * Type( size_t id ) const;
const AttrDescriptor * Attribute( size_t id ) const;
size_t EntityCount() const;
size_t TypeCount() const;
size_t AttributeCount() const;
uint64_t Fingerprint() const;
};
#endif