wavelength 1.0.0
Loading...
Searching...
No Matches
Data.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4
5#include <vector>
6
7#include "utl/BinStream.h"
8#include "utl/PrnStream.h"
9
18class DataArray {
19public:
27
29 union DataNode {
30 int i;
31 float f;
32 const char *sym;
34 };
35
42 DataArray(int size);
43
51 DataArray(BinStream &bs, std::vector<const char *> &filenames);
52
59
67 void *operator new(size_t size);
68
75 void operator delete(void *mem);
76
85 void Print(PrnStream &s);
86
94 void Resize(int size);
95
101 void AddRef();
102
108 void Release();
109
119
128 DataArray *FindArray(const char *tag, bool fail);
129
139 bool FindSymbol(const char *tag, const char **value, bool fail);
140
150 bool FindInt(const char *tag, int *value, bool fail);
151
161 bool FindFloat(const char *tag, float *value, bool fail);
162
172 bool FindBool(const char *tag, bool *value, bool fail);
173
181 int Type(int i);
182
190 const char *Sym(int i);
191
200
208 int Int(int i);
209
217 float Float(int i);
218
227
237 void SetNode(int i, DataNode value, int type);
238
246 void SetFileLine(const char *file, int line);
247
249 int Size() const {
250 return mSize;
251 }
252
253private:
261 void PrintNode(PrnStream &s, int i);
262
269 bool HasArrays();
270
278 void SetType(int i, int type);
279
281 int *TypeWords() {
282 return &mNodes[mSize].i;
283 }
284
285 DataNode *mNodes;
286 const char *mFile;
287 short mSize;
288 short mRefs;
289 short mLine;
290 short mSorted;
291};
292
301
DataArray * NewDataArray(int size)
Create an array of integer zeroes, with one reference.
void DataMergeTags(DataArray *dest, DataArray *src)
Merge the nested arrays of one array into another by their first node.
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Reference-counted array of script data nodes.
Definition dataarray.h:20
int Type(int i)
Report the type of a node.
bool FindBool(const char *tag, bool *value, bool fail)
Read the integer after a tag as a truth value.
int Size() const
Definition Data.h:249
void Print(PrnStream &s)
Write the array in script syntax.
DataNode Node(int i)
Read a node of any type.
DataArray * FindArray(int tag)
Find the nested array whose first node equals a value.
bool FindSymbol(const char *tag, const char **value, bool fail)
Read the symbol after a tag.
void Resize(int size)
Change the number of nodes.
void Release()
Drop a reference, deleting the array with its last one.
DataArray * Array(int i)
Read an array node.
void AddRef()
Take a reference.
int Int(int i)
Read an integer node.
bool FindInt(const char *tag, int *value, bool fail)
Read the integer after a tag.
DataType
The type of a node.
Definition Data.h:21
@ kDataFloat
Definition Data.h:24
@ kDataInt
Definition Data.h:22
@ kDataSymbol
Definition Data.h:23
@ kDataArray
Definition Data.h:25
DataArray(BinStream &bs, std::vector< const char * > &filenames)
Read an array, with one reference, as a compiled script stores it.
void SetFileLine(const char *file, int line)
Record where the array was defined.
void SetNode(int i, DataNode value, int type)
Replace a node.
const char * Sym(int i)
Read a symbol node.
DataArray(int size)
Create an array of integer zeroes, with one reference.
bool FindFloat(const char *tag, float *value, bool fail)
Read the real number after a tag.
DataArray * FindArray(const char *tag, bool fail)
Find the nested array whose first node is a symbol.
float Float(int i)
Read a real number node.
~DataArray()
Release the child arrays and free the nodes.
DataArray(int nSize)
Construct an array of cleared integer nodes with one reference.
Text output stream.
Definition prnstream.h:16
One node.
Definition Data.h:29
float f
Definition Data.h:31
const char * sym
Definition Data.h:32
DataArray * array
Definition Data.h:33
int i
Definition Data.h:30