CorTeX Core ABI 7
ToolTech Software · C++ library reference
Loading...
Searching...
No Matches
ctxGraphPersistence.h
Go to the documentation of this file.
1//*****************************************************************************
2// File : ctxGraphPersistence.h
3// Description : Retained graph documents and pinned adapter formats
4// Author : Anders Moden
5// Product : CorTeX 2.0.0
6//
7// Copyright (c) 2026 Anders Moden, Sweden
8//
9// Revision History...
10//
11// Who Date Description
12//
13// AMO 261016 Added owned suffix-selected SDK URL input without implicit restore (2.0.1)
14// AMO 261016 Declared bounded native XML reads and the built-in adapter profile (2.0.1)
15// AMO 261016 Added bounded native XML document preflight and streaming (2.0.1)
16// AMO 261016 Documented the built-in JSON borrowed-adapter profile (2.0.1)
17// AMO 261016 Specified retained restoration state through external callbacks (2.0.1)
18// AMO 261016 Added explicit model restoration and immutable semantic reports (2.0.1)
19// AMO 261016 Added atomic typed native JSON document decoding (2.0.1)
20// AMO 261016 Added native JSON record preflight and streaming helpers (2.0.1)
21// AMO 261016 Added validated SDK JSON record framing for handlers (2.0.1)
22// AMO 261016 Added pinned format registration and adapter dispatch (2.0.1)
23// AMO 261016 Declared the private shared graph-definition decoder (2.0.1)
24// AMO 261016 Added retained documents and strict compiled-model capture (2.0.1)
25//
26//*****************************************************************************
27#ifndef __CTX_GRAPH_PERSISTENCE_H__
28#define __CTX_GRAPH_PERSISTENCE_H__
29
30#include "ctxGraph.h"
31
32class ctxGraphDocumentState;
34class ctxParameterRestoreReportState;
35class gzDynamicType;
36
43
59
62{
63public:
64
69 CTX_EXPORT gzBool hasSnapshot() const;
70 CTX_EXPORT gzUInt32 getRestoredCount() const;
72 CTX_EXPORT gzUInt32 getDroppedCount() const;
73 CTX_EXPORT gzUInt32 getEntryCount() const;
75 CTX_EXPORT const ctxParameterRestoreEntry* getEntry(gzUInt32 index) const;
76
77private:
78
79 friend class ctxGraphDocument;
80 ctxParameterRestoreReportState* getState() const;
81 gzRefPointer<gzReference> m_state;
82};
83
85typedef gzBool (*ctxGraphDocumentJsonValidator)(const gzDynamicType& records, gzString& error);
86
88class ctxGraphDocumentFormat : public gzReference
89{
90public:
91
93 CTX_EXPORT virtual gzBool useDeepCopy() override;
94 virtual gzBool preflight(const ctxGraphDocument& document, gzBool embedParameters,
95 gzString& error) const = 0;
96 virtual gzBool write(const ctxGraphDocument& document, gzSerializeAdapter* adapter,
97 gzBool embedParameters, gzString& error) = 0;
98 virtual gzBool read(gzSerializeAdapter* adapter, ctxGraphDocument& document,
99 gzString& error) = 0;
100
101protected:
102
112 CTX_EXPORT static gzBool readJsonRecords(gzSerializeAdapter* adapter,
113 ctxGraphDocumentJsonValidator validator, gzDynamicType& records, gzString& error);
114
116 CTX_EXPORT static gzBool preflightJsonRecords(const ctxGraphDocument& document,
117 gzBool embedParameters, gzString& error);
124 CTX_EXPORT static gzBool writeJsonRecords(const ctxGraphDocument& document,
125 gzSerializeAdapter* adapter, gzBool embedParameters, gzString& error);
132 CTX_EXPORT static gzBool readJsonDocument(gzSerializeAdapter* adapter,
133 ctxGraphDocument& document, gzString& error);
134
136 CTX_EXPORT static gzBool preflightXmlRecords(const ctxGraphDocument& document,
137 gzBool embedParameters, gzString& error);
144 CTX_EXPORT static gzBool writeXmlRecords(const ctxGraphDocument& document,
145 gzSerializeAdapter* adapter, gzBool embedParameters, gzString& error);
152 CTX_EXPORT static gzBool readXmlDocument(gzSerializeAdapter* adapter,
153 ctxGraphDocument& document, gzString& error);
154};
155
156GZ_DECLARE_REFPTR(ctxGraphDocumentFormat);
157
167{
168public:
169
174
176 CTX_EXPORT static gzBool fromGraph(const gzGUID& definitionID,
177 const ctxGraph& graph, ctxGraphDocument& result, gzString& error);
181 CTX_EXPORT gzBool hasParameters() const;
182
190 CTX_EXPORT gzBool captureParameters(ctxModel& source, gzString& error);
191
201 const ctxCompileOptions& compile, ctxModelPtr& result,
202 ctxParameterRestoreReport& report, gzString& error) const;
203
205 CTX_EXPORT gzBool save(gzSerializeAdapter* adapter, const gzString& formatID,
206 gzBool embedParameters, gzString& error) const;
208 CTX_EXPORT static gzBool load(gzSerializeAdapter* adapter, const gzString& formatID,
209 ctxGraphDocument& result, gzString& error);
216 CTX_EXPORT static gzBool load(const gzString& url, ctxGraphDocument& result, gzString& error);
218 CTX_EXPORT static gzBool registerFormat(const gzString& formatID, const gzString& suffix,
219 ctxGraphDocumentFormat* handler, gzString* error = NULL);
220 CTX_EXPORT static gzBool unregisterFormat(const gzString& formatID, gzString* error = NULL);
221
222private:
223
224 friend class ctxGraph;
226
227 static gzBool createJsonRecords(const ctxGraphDocument& document,
228 gzBool embedParameters, gzDynamicType& records, gzString& error);
229 static gzBool streamXmlRecords(const ctxGraphDocument& document,
230 gzSerializeAdapter* adapter, gzBool embedParameters, gzString& error);
231 static gzBool validateJsonDocumentRecords(const gzDynamicType& records, gzString& error);
232 static gzBool decodeJsonDocumentRecords(const gzDynamicType& records,
233 ctxGraphDocument& document, gzString& error);
234 static gzBool decodeGraphXmlDefinition(gzXmlElement* root,
235 const gzArray<ctxGraphOperation>& parsedOperations, gzUInt32 operationElementCount,
236 ctxGraph& graph, gzString* error);
237 ctxGraphDocumentState* getState() const;
238 gzBool validateFormatDocument(gzString& error) const;
239 static gzBool readFormat(gzSerializeAdapter* adapter, ctxGraphDocumentFormat* handler,
240 ctxGraphDocument& result, gzString& error);
241 gzRefPointer<gzReference> m_state;
242};
243
244#endif
Immutable request to realize a graph revision or adapt a direct ctxCortex.
Definition ctxGraph.h:1498
Format-specific preflight and SDK-adapter I/O; adapters remain caller-owned.
virtual gzBool useDeepCopy() override
virtual gzBool preflight(const ctxGraphDocument &document, gzBool embedParameters, gzString &error) const =0
virtual gzBool read(gzSerializeAdapter *adapter, ctxGraphDocument &document, gzString &error)=0
static gzBool writeXmlRecords(const ctxGraphDocument &document, gzSerializeAdapter *adapter, gzBool embedParameters, gzString &error)
Streams a native XML document with wrapper-specific lossless text and exact values.
static gzBool readJsonRecords(gzSerializeAdapter *adapter, ctxGraphDocumentJsonValidator validator, gzDynamicType &records, gzString &error)
Reads finite SDK JSON array/string records, then checks their complete wire.
static gzBool writeJsonRecords(const ctxGraphDocument &document, gzSerializeAdapter *adapter, gzBool embedParameters, gzString &error)
Streams native document-v1 records after complete preflight and a counting pass.
static gzBool preflightJsonRecords(const ctxGraphDocument &document, gzBool embedParameters, gzString &error)
Checks the supported native definition/snapshot and exact streamed size without I/O.
static gzBool readXmlDocument(gzSerializeAdapter *adapter, ctxGraphDocument &document, gzString &error)
Reads native XML document-v1 records with SDK syntax and shared semantic validation.
static gzBool readJsonDocument(gzSerializeAdapter *adapter, ctxGraphDocument &document, gzString &error)
Reads the supported complete native JSON document through SDK framing.
virtual ~ctxGraphDocumentFormat()
virtual gzBool write(const ctxGraphDocument &document, gzSerializeAdapter *adapter, gzBool embedParameters, gzString &error)=0
static gzBool preflightXmlRecords(const ctxGraphDocument &document, gzBool embedParameters, gzString &error)
Checks native XML document-v1 support and complete streamed size without target I/O.
Retains one authoritative graph and an optional complete semantic snapshot.
ctxGraph getGraph() const
Returns the same retained graph; editing the returned value uses graph COW.
static gzBool registerFormat(const gzString &formatID, const gzString &suffix, ctxGraphDocumentFormat *handler, gzString *error=NULL)
IDs and lowercase ASCII suffixes are unique; built-in profile names are reserved.
static gzBool unregisterFormat(const gzString &formatID, gzString *error=NULL)
gzBool restoreModel(const ctxBuildRequest &build, const ctxCompileOptions &compile, ctxModelPtr &result, ctxParameterRestoreReport &report, gzString &error) const
Explicitly builds/compiles an owned Evaluation candidate for this exact graph.
ctxGraphDocument(const ctxGraphDocument &document)
static gzBool fromGraph(const gzGUID &definitionID, const ctxGraph &graph, ctxGraphDocument &result, gzString &error)
A non-null, caller-assigned persistent definition identity is required.
gzBool captureParameters(ctxModel &source, gzString &error)
Captures a quiescent compiled model bound to this exact retained graph.
gzGUID getDefinitionID() const
static gzBool load(const gzString &url, ctxGraphDocument &result, gzString &error)
Loads through an owned SDK URL input using its registered filename suffix.
static gzBool load(gzSerializeAdapter *adapter, const gzString &formatID, ctxGraphDocument &result, gzString &error)
Publishes only a valid successful candidate; failed reads preserve result.
gzBool save(gzSerializeAdapter *adapter, const gzString &formatID, gzBool embedParameters, gzString &error) const
Pins the handler before callbacks; does not flush, close or rewind the adapter.
friend class ctxGraphDocumentFormat
ctxGraphDocument & operator=(const ctxGraphDocument &document)
gzBool hasParameters() const
Immutable complete result; copies retain the same report and entries.
const ctxParameterRestoreEntry * getEntry(gzUInt32 index) const
Returned entries live as long as a copy of this report remains retained.
gzUInt32 getDroppedCount() const
ctxParameterRestoreReport(const ctxParameterRestoreReport &report)
ctxParameterRestoreReport & operator=(const ctxParameterRestoreReport &report)
gzBool hasSnapshot() const
gzUInt32 getInitializedCount() const
gzUInt32 getEntryCount() const
gzUInt32 getRestoredCount() const
#define CTX_EXPORT
Definition ctxBase.h:68
ctxParameterKind
Definition ctxGraph.h:343
ctxParameterRestoreAction
@ CTX_PARAMETER_INITIALIZED
@ CTX_PARAMETER_RESTORED
@ CTX_PARAMETER_DROPPED
gzBool(*) ctxGraphDocumentJsonValidator(const gzDynamicType &records, gzString &error)
Validates every original named record and typed value without rebuilding it.
One semantic scalar action; path is diagnostic, never matching identity.
gzUInt32 connectionID
gzUInt32 ownerOccurrenceID
gzString path
ctxParameterRestoreAction action
gzUInt32 destinationIndex
gzUInt32 sourceOccurrenceID
gzUInt32 sourceIndex
ctxParameterRestoreEntry()
gzGUID definitionID
ctxParameterKind kind