|
wavelength 1.0.0
|
Reference-counted array of script data nodes. More...
#include <dataarray.h>
Classes | |
| union | Node |
| A node's value, read as the member its NodeType selects. More... | |
| union | DataNode |
| One node. More... | |
Public Types | |
| enum | NodeType { kNodeInt = 0 , kNodeSymbol = 1 , kNodeFloat = 2 , kNodeArray = 3 } |
| Kinds of node Type() reports, two bits each. More... | |
| enum | DataType { kDataInt = 0 , kDataSymbol = 1 , kDataFloat = 2 , kDataArray = 3 } |
| The type of a node. More... | |
Public Member Functions | |
| DataArray (int nSize) | |
| Construct an array of cleared integer nodes with one reference. | |
| DataArray (BinStream &stream, const std::vector< const char * > &files) | |
| Read an array the compiler wrote, with one reference. | |
| ~DataArray () | |
| Release the child arrays and the node storage. | |
| void | Merge (const DataArray *pOther) |
| Add the child arrays of another array whose tags this array lacks, and merge the children whose tags both have. | |
| void | SetFileLine (const char *pszFile, int nLine) |
| Record the file and the line the array was read from. | |
| void | SortByKey () |
| Sort the child arrays by the value of their first nodes, and mark the array as sorted. | |
| void | Resize (int nSize) |
| Change the number of nodes, releasing the child arrays of the nodes removed. | |
| Node | Value (int nIndex) const |
| Report a node's value without regard to its kind. | |
| void | AddRef () |
| Take one more reference. | |
| int | Size () const |
| Report the number of nodes. | |
| int | Type (int nIndex) const |
| Report the kind of a node. | |
| bool | FindVector (const char *pszName, Vector3 *pValue, bool bFail) const |
| Find the three numbers that follow a tag. | |
| bool | FindVector (const char *pszName, Vector2 *pValue, bool bFail) const |
| Find the two numbers that follow a tag. | |
| void | Release () |
| Drop one reference and destroy the array when none remains. | |
| DataArray * | FindArray (const char *pszTag, bool bFail) const |
| Find the child array whose first node is a tag. | |
| DataArray * | FindArray (int nTag) const |
| Find the child array whose first node is an integer tag. | |
| bool | FindString (const char *pszName, String *pValue, bool bFail) const |
| Find the symbol that follows a tag and copy it into a string. | |
| bool | FindColor (const char *pszName, Color *pValue, bool bFail) const |
| Find the colour that follows a tag. | |
| bool | FindSymbol (const char *pszName, const char **ppszValue, bool bFail) const |
| Find the symbol that follows a tag. | |
| bool | FindInt (const char *pszName, int *pnValue, bool bFail) const |
| Find the integer that follows a tag. | |
| bool | FindFloat (const char *pszName, float *pfValue, bool bFail) const |
| Find the floating-point number that follows a tag. | |
| bool | FindBool (const char *pszName, int *pnValue, bool bFail) const |
| Find the truth value that follows a tag. | |
| const char * | Sym (int nIndex) const |
| Report a node as a symbol. | |
| int | Int (int nIndex) const |
| Report a node as an integer. | |
| float | Float (int nIndex) const |
| Report a node as a float. | |
| DataArray * | Array (int nIndex) const |
| Report a node as an array. | |
| void | SetNode (int nIndex, Node value, int nType) |
| Replace a node with a value of a kind. | |
| void | Print (PrnStream &stream) const |
| Write the array as script text. | |
| const char * | GetFile () const |
| short | GetLine () const |
| DataArray (int size) | |
| Create an array of integer zeroes, with one reference. | |
| DataArray (BinStream &bs, std::vector< const char * > &filenames) | |
| Read an array, with one reference, as a compiled script stores it. | |
| ~DataArray () | |
| Release the child arrays and free the nodes. | |
| void * | operator new (size_t size) |
| Allocate from the pool allocator under the name DataArray. | |
| void | operator delete (void *mem) |
| Return memory to the pool allocator. | |
| void | Print (PrnStream &s) |
| Write the array in script syntax. | |
| void | Resize (int size) |
| Change the number of nodes. | |
| void | AddRef () |
| Take a reference. | |
| void | Release () |
| Drop a reference, deleting the array with its last one. | |
| DataArray * | FindArray (int tag) |
| Find the nested array whose first node equals a value. | |
| DataArray * | FindArray (const char *tag, bool fail) |
| Find the nested array whose first node is a symbol. | |
| bool | FindSymbol (const char *tag, const char **value, bool fail) |
| Read the symbol after a tag. | |
| bool | FindInt (const char *tag, int *value, bool fail) |
| Read the integer after a tag. | |
| bool | FindFloat (const char *tag, float *value, bool fail) |
| Read the real number after a tag. | |
| bool | FindBool (const char *tag, bool *value, bool fail) |
| Read the integer after a tag as a truth value. | |
| int | Type (int i) |
| Report the type of a node. | |
| const char * | Sym (int i) |
| Read a symbol node. | |
| DataNode | Node (int i) |
| Read a node of any type. | |
| int | Int (int i) |
| Read an integer node. | |
| float | Float (int i) |
| Read a real number node. | |
| DataArray * | Array (int i) |
| Read an array node. | |
| void | SetNode (int i, DataNode value, int type) |
| Replace a node. | |
| void | SetFileLine (const char *file, int line) |
| Record where the array was defined. | |
| int | Size () const |
Static Public Member Functions | |
| static void * | operator new (size_t) |
| Allocate an array from the pool of 16-byte blocks. | |
| static void | operator delete (void *pBlock) |
| Return an array to the pool of 16-byte blocks. | |
| static DataArray * | Concat (const std::vector< DataArray * > &arrays, bool bRelease) |
| Join the nodes of several arrays into a new array. | |
| static DataArray * | Read (const char *pszPath, BinStream *pStream) |
| Parse script text into an array. | |
| static DataArray * | ReadText (const char *pszPath, BinStream *pStream) |
| Parse script text into an array, never the compiled form Read() prefers on the disc. | |
| static void | MakeCompiledPath (char *pszOut, const char *pszPath, bool bCompiled) |
| Build the path of the compiled copy of a data file. | |
| static DataArray * | New (int nSize) |
| Create an array of nodes with one reference. | |
| static void | DefineMacro (const char *pszName, DataArray *pValue) |
| Define a script macro, taking a reference on its value. | |
| static DataArray * | FindMacro (const char *pszName) |
| Find the value of a script macro. | |
Reference-counted array of script data nodes.
Array of script data: integers, real numbers, symbols, and nested arrays.
The configuration file and every script command arrive as one of these. The class is not polymorphic. The name is inferred from the allocation tag "DataArray".
The RTTI records the class. The object is 0x10 bytes. The nodes and a table of their 2-bit types share one pool allocation, the types packed 16 to a word after the last node. An array is reference counted and deletes itself when its last reference is released. The name of the member that marks an array sorted is inferred.
| enum DataArray::NodeType |
Kinds of node Type() reports, two bits each.
| Enumerator | |
|---|---|
| kNodeInt | An integer. |
| kNodeSymbol | A symbol. |
| kNodeFloat | A floating-point number. |
| kNodeArray | A child array. |
| enum DataArray::DataType |
|
explicit |
Construct an array of cleared integer nodes with one reference.
| nSize | The number of nodes. |
| DataArray::DataArray | ( | BinStream & | stream, |
| const std::vector< const char * > & | files ) |
Read an array the compiler wrote, with one reference.
| stream | The stream. |
| files | The files the array and its children name by index. |
| DataArray::~DataArray | ( | ) |
Release the child arrays and the node storage.
| DataArray::DataArray | ( | int | size | ) |
Create an array of integer zeroes, with one reference.
| size | The number of nodes. |
| DataArray::DataArray | ( | BinStream & | bs, |
| std::vector< const char * > & | filenames ) |
Read an array, with one reference, as a compiled script stores it.
| bs | The stream. |
| filenames | The script file names, which the stored file index selects from. |
| DataArray::~DataArray | ( | ) |
Release the child arrays and free the nodes.
|
inlinestatic |
Allocate an array from the pool of 16-byte blocks.
|
inlinestatic |
Return an array to the pool of 16-byte blocks.
| pBlock | The block. |
Join the nodes of several arrays into a new array.
| arrays | The arrays, in order. |
| bRelease | Whether each array loses a reference once its nodes are copied. |
| void DataArray::Merge | ( | const DataArray * | pOther | ) |
Add the child arrays of another array whose tags this array lacks, and merge the children whose tags both have.
| pOther | The other array, or null. |
| void DataArray::SetFileLine | ( | const char * | pszFile, |
| int | nLine ) |
Record the file and the line the array was read from.
| pszFile | The file, interned as a symbol. |
| nLine | The line. |
| void DataArray::SortByKey | ( | ) |
Sort the child arrays by the value of their first nodes, and mark the array as sorted.
FindArray() then searches the array by halves.
| void DataArray::Resize | ( | int | nSize | ) |
Change the number of nodes, releasing the child arrays of the nodes removed.
New nodes are cleared integers.
| nSize | The number of nodes. |
| Node DataArray::Value | ( | int | nIndex | ) | const |
Report a node's value without regard to its kind.
| nIndex | The node. |
| void DataArray::AddRef | ( | ) |
Take one more reference.
|
inline |
Report the number of nodes.
| int DataArray::Type | ( | int | nIndex | ) | const |
Report the kind of a node.
| nIndex | The node. |
| bool DataArray::FindVector | ( | const char * | pszName, |
| Vector3 * | pValue, | ||
| bool | bFail ) const |
Find the three numbers that follow a tag.
The fourth word of the vector is left as it was.
| pszName | The symbol that starts the child array. |
| pValue | Receives the numbers at indices 1 to 3 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindVector | ( | const char * | pszName, |
| Vector2 * | pValue, | ||
| bool | bFail ) const |
Find the two numbers that follow a tag.
| pszName | The symbol that starts the child array. |
| pValue | Receives the numbers at indices 1 and 2 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| void DataArray::Release | ( | ) |
Drop one reference and destroy the array when none remains.
Parse script text into an array.
| pszPath | The file to read when pStream is null, and the name errors give. |
| pStream | The stream to read, or null to read the file. |
Parse script text into an array, never the compiled form Read() prefers on the disc.
The name is inferred.
| pszPath | The file to read when pStream is null, and the name errors give. |
| pStream | The stream to read, or null to read the file. |
| DataArray * DataArray::FindArray | ( | const char * | pszTag, |
| bool | bFail ) const |
Find the child array whose first node is a tag.
| pszTag | The tag. |
| bFail | Treat a missing child as an error. |
| DataArray * DataArray::FindArray | ( | int | nTag | ) | const |
Find the child array whose first node is an integer tag.
An array marked as sorted is searched by halves.
| nTag | The tag. |
| bool DataArray::FindString | ( | const char * | pszName, |
| String * | pValue, | ||
| bool | bFail ) const |
Find the symbol that follows a tag and copy it into a string.
| pszName | The symbol that starts the child array. |
| pValue | Receives the symbol at index 1 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindColor | ( | const char * | pszName, |
| Color * | pValue, | ||
| bool | bFail ) const |
Find the colour that follows a tag.
The alpha is read only when the child array has a fourth component.
| pszName | The symbol that starts the child array. |
| pValue | Receives the colour at indices 1 to 4 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindSymbol | ( | const char * | pszName, |
| const char ** | ppszValue, | ||
| bool | bFail ) const |
Find the symbol that follows a tag.
| pszName | The symbol that starts the child array. |
| ppszValue | Receives the symbol at index 1 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindInt | ( | const char * | pszName, |
| int * | pnValue, | ||
| bool | bFail ) const |
Find the integer that follows a tag.
| pszName | The symbol that starts the child array. |
| pnValue | Receives the integer at index 1 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindFloat | ( | const char * | pszName, |
| float * | pfValue, | ||
| bool | bFail ) const |
Find the floating-point number that follows a tag.
| pszName | The symbol that starts the child array. |
| pfValue | Receives the number at index 1 of the child array when it exists. |
| bFail | Passed to FindArray(). |
| bool DataArray::FindBool | ( | const char * | pszName, |
| int * | pnValue, | ||
| bool | bFail ) const |
Find the truth value that follows a tag.
| pszName | The symbol that starts the child array. |
| pnValue | Receives 1 when the integer at index 1 of the child array is not zero and 0 otherwise, when the child array exists. |
| bFail | Passed to FindArray(). |
| const char * DataArray::Sym | ( | int | nIndex | ) | const |
Report a node as a symbol.
| nIndex | The node. |
| int DataArray::Int | ( | int | nIndex | ) | const |
Report a node as an integer.
| nIndex | The node. |
| float DataArray::Float | ( | int | nIndex | ) | const |
Report a node as a float.
| nIndex | The node. |
| DataArray * DataArray::Array | ( | int | nIndex | ) | const |
Report a node as an array.
| nIndex | The node. |
| void DataArray::SetNode | ( | int | nIndex, |
| Node | value, | ||
| int | nType ) |
Replace a node with a value of a kind.
| nIndex | The node. The child array a node replaces loses a reference and a new child array gains one. Symbol text is interned. |
| nIndex | The node. |
| value | The value. |
| nType | The kind of the value, one of NodeType. |
| void DataArray::Print | ( | PrnStream & | stream | ) | const |
Write the array as script text.
| stream | The stream to write to. |
|
static |
Build the path of the compiled copy of a data file.
The compiled copy is <directory>/gen/<base>.<extension>.bin. It is used when the game runs from the disc or when bCompiled asks for it, and the path is copied unchanged otherwise.
| pszOut | Receives the path. |
| pszPath | The path of the data file. |
| bCompiled | Use the compiled copy even when the game does not run from the disc. |
|
static |
Create an array of nodes with one reference.
| nSize | The number of nodes. |
|
static |
Define a script macro, taking a reference on its value.
| pszName | The name of the macro. |
| pValue | The value of the macro. |
|
static |
Find the value of a script macro.
| pszName | The name of the macro. |
|
inline |
|
inline |
| void * DataArray::operator new | ( | size_t | size | ) |
Allocate from the pool allocator under the name DataArray.
The control compiles this inline.
| size | The size of the object. |
| void DataArray::operator delete | ( | void * | mem | ) |
Return memory to the pool allocator.
| mem | The memory. |
| void DataArray::Print | ( | PrnStream & | s | ) |
Write the array in script syntax.
An array with nested arrays is written one node to a line, indented.
| s | The stream. |
| void DataArray::Resize | ( | int | size | ) |
Change the number of nodes.
Removed nested arrays are released; added nodes are integer zeroes.
| size | The new number of nodes. |
| void DataArray::AddRef | ( | ) |
Take a reference.
| void DataArray::Release | ( | ) |
Drop a reference, deleting the array with its last one.
| DataArray * DataArray::FindArray | ( | int | tag | ) |
Find the nested array whose first node equals a value.
A sorted array is searched by bisection, an unsorted one from the start.
| tag | The value of the first node. |
| DataArray * DataArray::FindArray | ( | const char * | tag, |
| bool | fail ) |
Find the nested array whose first node is a symbol.
| tag | The symbol's text. |
| fail | Whether a missing array is a failure. |
| bool DataArray::FindSymbol | ( | const char * | tag, |
| const char ** | value, | ||
| bool | fail ) |
Read the symbol after a tag.
| tag | The tag. |
| value | Receives the symbol. |
| fail | Whether a missing tag is a failure. |
| bool DataArray::FindInt | ( | const char * | tag, |
| int * | value, | ||
| bool | fail ) |
Read the integer after a tag.
| tag | The tag. |
| value | Receives the integer. |
| fail | Whether a missing tag is a failure. |
| bool DataArray::FindFloat | ( | const char * | tag, |
| float * | value, | ||
| bool | fail ) |
Read the real number after a tag.
An integer converts.
| tag | The tag. |
| value | Receives the number. |
| fail | Whether a missing tag is a failure. |
| bool DataArray::FindBool | ( | const char * | tag, |
| bool * | value, | ||
| bool | fail ) |
Read the integer after a tag as a truth value.
| tag | The tag. |
| value | Receives whether the integer is nonzero. |
| fail | Whether a missing tag is a failure. |
| int DataArray::Type | ( | int | i | ) |
| const char * DataArray::Sym | ( | int | i | ) |
Read a symbol node.
Another type is a failure.
| i | The node. |
| DataNode DataArray::Node | ( | int | i | ) |
Read a node of any type.
| i | The node. |
| int DataArray::Int | ( | int | i | ) |
Read an integer node.
Another type is a failure.
| i | The node. |
| float DataArray::Float | ( | int | i | ) |
Read a real number node.
An integer converts; another type is a failure.
| i | The node. |
| DataArray * DataArray::Array | ( | int | i | ) |
Read an array node.
Another type is a failure.
| i | The node. |
| void DataArray::SetNode | ( | int | i, |
| DataNode | value, | ||
| int | type ) |
Replace a node.
A symbol is entered into the shared string table, and an array gains a reference; the array the node held loses one.
| i | The node. |
| value | The value. |
| type | The value's DataType. |
| void DataArray::SetFileLine | ( | const char * | file, |
| int | line ) |
Record where the array was defined.
| file | The script file. |
| line | The line. |
|
inline |