HDK
|
Provide a JSON interface to a primitive. More...
#include <GA_PrimitiveJSON.h>
Public Member Functions | |
GA_PrimitiveJSON () | |
virtual | ~GA_PrimitiveJSON () |
virtual int | getEntries () const =0 |
Return the number of data fields in the primitive private schema. More... | |
virtual bool | shouldSaveField (const GA_Primitive *prim, int i, const GA_SaveMap &save) const |
virtual const UT_StringHolder & | getKeyword (int i) const =0 |
virtual bool | saveField (const GA_Primitive *prim, int i, UT_JSONWriter &w, const GA_SaveMap &save) const =0 |
virtual bool | saveField (const GA_Primitive *prim, int i, UT_JSONValue &value, const GA_SaveMap &save) const |
virtual bool | loadField (GA_Primitive *prim, int i, UT_JSONParser &p, const GA_LoadMap &load) const =0 |
virtual bool | loadField (GA_Primitive *prim, int i, UT_JSONParser &p, const UT_JSONValue &value, const GA_LoadMap &load) const |
virtual bool | isEqual (int i, const GA_Primitive *prim1, const GA_Primitive *prim2) const =0 |
virtual bool | save (const GA_Primitive *prim, UT_JSONWriter &w, const GA_SaveMap &map) const |
virtual bool | save (const GA_Primitive *prim, UT_JSONValue &v, const GA_SaveMap &map) const |
Save a single primitive to a UT_JSONValue. More... | |
virtual bool | load (GA_Primitive *prim, UT_JSONParser &p, const GA_LoadMap &map) const |
virtual bool | load (GA_Primitive *prim, UT_JSONParser &p, const UT_JSONValue &value, const GA_LoadMap &map) const |
Load a single primitive from a UT_JSONValue. More... | |
Protected Member Functions | |
virtual bool | getRunFields (const GA_Primitive **list, int list_size, const GA_SaveMap &save, UT_StringArray &varying, UT_JSONValue &uniform, uint &user_flags) const |
virtual bool | matchRun (const GA_Primitive *prim0, const GA_Primitive *prim1, const UT_StringArray &varying, const UT_JSONValue &uniform, uint user_flags) const |
virtual bool | saveRunFields (const GA_Primitive *prim, const GA_SaveMap &save, const UT_StringArray &varying, UT_JSONWriter &w, uint user_flags) const |
virtual bool | load (GA_Primitive *prim, UT_JSONParser &p, const GA_LoadMap &load, const UT_StringArray &varying, const GA_JSONUniformBlock &uniform) const |
virtual bool | loadUniform (GA_Primitive *prim, UT_JSONParser &p, const GA_LoadMap &map, const GA_JSONUniformBlock &uniform) const |
virtual bool | loadUnknownToken (GA_Primitive *prim, const char *token, UT_JSONParser &p, const GA_LoadMap &load) const |
void | init () |
Protected Attributes | |
UT_FSA * | myTokens |
int | myEntries |
Friends | |
class | GA_PrimitiveList |
class | GA_PrimitiveRun |
Provide a JSON interface to a primitive.
This class is used in saving and loading of geometry.
When sequences of primitives appear in order in the geometry, it's possible to compact the storage by saving the primitive instance data in a "run". This is done by storing the "fields" which appear for each primitive. The run data is an array with each item in the array representing the data fields for the individual primitive.
This eliminates the repetition of the JSON keys for each primitive. For example, the following two objects represent the same data:
A primitive is stored as an array with two entries. The first entry stores the definition of the primitive. The second entry stores the private data for the primitive.
The private data is handled by the GA_PrimitiveJSON associated with the primitive type.
The primitive definition may be the definition for a single primitive, or it may store run data. The run fields are optional, but if one is defined, all should be defined. See also: JSON Schema: GA_Primitive
This section stores the private data for a run of primitives. The data is processed by the GA_PrimitiveJSON class associated with the primitive. The data is stored in an
This section describes how to write load/save methods for a primitive.
The high-level interface to primitive save/load is provided by the methods
getEntries()
getKeyword(int i)
saveField(const GA_Primitive*, int, UT_JSONWriter&, const GA_SaveMap&)
saveField(const GA_Primitive*, int, UT_JSONValue&, const GA_SaveMap&)
load(const GA_Primitive*, int, UT_JSONParser&, const GA_LoadMap&)
load(const GA_Primitive*, int, UT_JSONParser&, UT_JSONValue&, const GA_LoadMap&)
isEqual(int i, const GA_Primitive*, const GA_Primitive *)
The private schema is defined by a number of fields in a dictionary/map. For example, a polygon might have two fields in its private schema:
which would have an interface which looked like:
Definition at line 225 of file GA_PrimitiveJSON.h.
GA_PrimitiveJSON::GA_PrimitiveJSON | ( | ) |
|
virtual |
|
pure virtual |
Return the number of data fields in the primitive private schema.
Implemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
pure virtual |
Return the keyword associated with the i'th entry of the schema. Keywords are case insensitive, but must be specified as lower case by this method.
Implemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
protectedvirtual |
The GA library may optimize by saving multiple primitives of the same type in a "run". This can be done if the primitive is represented by a simple map where all primitives share common fields. For example, spheres will all have:
getRunFields() is called only if there is a run of multiple primitives. The string array returned should be the list of all fields that the primitive needs to save. For the sphere example, it would return: [ "center", "transform" ].
list | List of primitives to check for uniform values. |
list_size | Size of the list of primitives in the run (see GA_SaveMap, geo:primrunqueue). |
varying | The list of fields which are different for each primitive |
uniform | This will be a UT_JSONValue::JSON_MAP value. Values which are common to every primitive can be placed in this list (instead of the varying list. Only objects which can be easily loaded from a UT_JSONValue object should be put into the uniform list, since the uniform list is pre-loaded when loading runs of primitives. |
user_flags | This is an integer which can be set to any value. It is passed verbatim to matchRun() and saveRunFields(). This can be used to pass information about the run fields. |
The base class returns a NULL pointer (indicating saving runs is impossible).
The user_flags is an unsigned integer value which you can modify how you wish. It's passed to the matchRun() and saveRunFields() verbatim.
The default method returns false
(no run is possible)
|
protected |
|
pure virtual |
Determine if the i'th entry of a primitive's private schema is equal to the value in another primitive. This determines whether the data can be created as "uniform" data a run of sequential primitives. Note uniform data appears BEFORE varying data. So if you require a ordering on your keys, you need to make all keys that require to be loaded after another key never equal to each other.
Implemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
virtual |
Load a single primitive from the UT_JSONParser. By default, this method loads the primitive from an ordered dictionary (as output by the save method).
|
virtual |
Load a single primitive from a UT_JSONValue.
|
protectedvirtual |
Load a single primitive from a run of primitives. Returns false if an error occurred, else true.
|
pure virtual |
Load the i'th entry of the primitive's private schema from a JSON stream.
Implemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
virtual |
Load the i'th entry of the primitive's private schema from a JSON value. The parser is passed in so that errors/warnings can be added.
The default implementation just calls:
Reimplemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
protectedvirtual |
Load, and optionally cache, the uniform data for a run of primitives. Returns false if an error occurred, else true.
|
protectedvirtual |
When the primitive loader hits an unknown map token, it will call this method to let the primitive process it. The default behaviour is to add a warning to the parser and skip the next object.
If the method returns false, parsing will stop and the load will fail.
|
protectedvirtual |
When saving a list of primitives, the library attempts to create "runs" of like primitives. The library will create an initial run of primitives (the length of which is determined by geo:primrununique in the GA_SaveMap). This initial list determines the data elements which are uniform and varying in the run of primitives.
After this initial run, additional primitives can be added to the run if they match. This method is called to test whether the primitive matches the current run (prim0 is the first primitive in the run, prim1 is the primitive to test).
The user_flags
are the flags set in getRunFields()
.
|
virtual |
Save a single primitve to the UT_JSONWriter By default, this simply saves an ordered dictionary (list) with the private schema. That is:
|
virtual |
Save a single primitive to a UT_JSONValue.
|
pure virtual |
Save the i'th entry of the primitive's schema to the JSON stream. You can assume that the GA_Primitive is the correct type (i.e. a static cast is ok).
Implemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
virtual |
Save the i'th entry of the primitive's schema to a JSON Value. This method should only be called when saving uniform data, which only happens if the equality checking returned true for the i'th entry. If the comparison fails, then this method will never be called.
The default method just calls:
Reimplemented in HDK_Sample::geo_PrimTetraJSON, and GA_PrimitiveJSONExtend.
|
protectedvirtual |
saveRunFields() should save a JSON array of values, one for each field in the varying list of fields. The default method returns false
.
|
virtual |
Return whether the i'th field should be saved to the JSON stream. By default, all fields are saved. However, this allows the object to "skip" some fields which don't make sense in some circumstances.
|
friend |
Definition at line 430 of file GA_PrimitiveJSON.h.
|
friend |
Definition at line 431 of file GA_PrimitiveJSON.h.
|
protected |
Definition at line 428 of file GA_PrimitiveJSON.h.
|
protected |
Definition at line 427 of file GA_PrimitiveJSON.h.