6. Utilities - PropSet, Random, DataTable, Concat, LinkList, StrUtil
CEETRON SAM provides modules for managing vectors, strings or sets of specialized quantities. The PropSet module maintains a set of named properties which may be one of several primitive types such as integer, float, vector of doubles, character string, etc. The Random module generates random numbers in the interval [0.,1.]; The DataTable module stores, retrieves and interpolates vectors of double precision data as a function of an independent variable. The Concat module provides for data records of arbitrary length to be stored in an efficient concatenated form. It is most useful for storing many small records of data. The LinkList module provides for data records of a specified fixed length to be stored in a linked list. The StrUtil module provides string conversion and length queries for wide character and UTF-8 encoded strings.
6.1. Property Sets - PropSet
The PropSet module maintains an arbitrarily large set of named properties which may be one of several primitive types such as integer, float, vector of doubles, character string, etc. This module is built upon and is a generalization of the Dictionary collection module.
Begin and end an instance of an object, return object error flag
vsy_PropSetBegin()
- create an instance of a PropSet objectvsy_PropSetEnd()
- destroy an instance of a PropSet objectvsy_PropSetError()
- return PropSet object error flagvsy_PropSetCopy()
- make a copy of a PropSet object
Set and query properties
vsy_PropSetDef()
- suggest number of propertiesvsy_PropSetInq()
- get current storage capacityvsy_PropSetCount()
- get number of contained propertiesvsy_PropSetInsert()
- place property in the property setvsy_PropSetLookup()
- return property parameters by namevsy_PropSetLookupDouble()
- return double property by namevsy_PropSetLookupFloat()
- return float property by namevsy_PropSetLookupInteger()
- return integer property by namevsy_PropSetLookupObject()
- return object property by namevsy_PropSetLookupString()
- return string property by namevsy_PropSetRemove()
- remove any property with the specified namevsy_PropSetClear()
- remove all properties from a PropSetvsy_PropSetInitIter()
- prepare to successively visit each propertyvsy_PropSetNextIter()
- return the next property name in the set
Instance a PropSet object using vsy_PropSetBegin()
. Once a
PropSet is instanced, an approximate number of properties to be
stored may defined using vsy_PropSetDef()
.
As properties are inserted the PropSet module will adjust
memory as required. The actual size
of the allocated storage may be determined by calling
vsy_PropSetInq()
.
Each new property is placed in the property set by calling
vsy_PropSetInserti()
, vsy_PropSetInsertfv()
, etc. depending upon the property
type.
The total number of properties contained in the
property set may be found with vsy_PropSetCount()
. The property with a
specified name may be found by calling
vsy_PropSetLookupInteger()
, vsy_PropSetLookupFloat()
, etc.
The property parameters such as data type, size, etc. may be returned
using vsy_PropSetLookup()
.
A property may be removed using vsy_PropSetRemove()
. The method
vsy_PropSetClear()
removes all properties from the property set.
Each property in the property set may be processed with an “iterator”
construct.
The pair of methods
vsy_PropSetInitIter()
and vsy_PropSetNextIter()
are used to visit
each property name using a loop. Call the first method before the body
of the loop to prepare the PropSet object for the iteration. Within
the loop body, call vsy_PropSetNextIter()
. It will return the name of
a property each time it is called. It will return a
NULL pointer when all of the properties have been visited.
6.1.1. Function Descriptions
The currently available PropSet functions are described in detail in this section.
-
vsy_PropSet *vsy_PropSetBegin(void)
create an instance of a PropSet object
Create an instance of a PropSet object. Memory is allocated for the object private data and the pointer to the data is returned.
Destroy an instance of a PropSet object using
void vsy_PropSetEnd (vsy_PropSet *propset)
Return the current value of a PropSet object error flag using
Vint vsy_PropSetError (vsy_PropSet *propset)
Make a copy of a PropSet object. The private data from the frompropset object is copied to the PropSet object. Any previous private data in propset is lost.
void vsy_PropSetCopy (vsy_PropSet *propset, vsy_PropSet *frompropset)
- Returns:
The function returns a pointer to the newly created PropSet object. If the object creation fails, NULL is returned.
-
void vsy_PropSetEnd(vsy_PropSet *p)
destroy an instance of a PropSet object
-
Vint vsy_PropSetError(vsy_PropSet *p)
return the current value of a PropSet object error flag
-
void vsy_PropSetDef(vsy_PropSet *p, Vint numobj)
define initial size
Suggest a number of properties to be stored in the PropSet. This is used to allocate an initial array of storage which is used to hold the pointer to each stored property. Since the names and properties are stored sparsely within the PropSet module, the actual length of the internal array is larger than this supplied number. This function removes any previously entered properties.
Find the number of properties which may be managed by the currently allocated internal storage of a PropSet using
void vsy_PropSetInq (const vsy_PropSet *propset, Vint *numobj,
- Errors
SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.
- Parameters:
p – Pointer to PropSet object.
numobj – Estimated number of objects to be held.
-
void vsy_PropSetInq(const vsy_PropSet *p, Vint *nument)
find the number of properties which may be managed by the currently allocated internal storage
See
vsy_PropSetDef()
-
void vsy_PropSetCount(const vsy_PropSet *p, Vint *num)
get number of contained properties
Get the number of properties which have been inserted and not yet removed.
-
void vsy_PropSetInserti(vsy_PropSet *p, const Vchar *name, Vint v)
place a property in the property set
-
void vsy_PropSetInsertiv(vsy_PropSet *p, const Vchar *name, Vint num, Vint v[])
place a property in the property set
-
void vsy_PropSetInsertf(vsy_PropSet *p, const Vchar *name, Vfloat v)
place a property in the property set
-
void vsy_PropSetInsertfv(vsy_PropSet *p, const Vchar *name, Vint num, Vfloat v[])
place a property in the property set
-
void vsy_PropSetInsertd(vsy_PropSet *p, const Vchar *name, Vdouble v)
place a property in the property set
-
void vsy_PropSetInsertdv(vsy_PropSet *p, const Vchar *name, Vint num, Vdouble v[])
place a property in the property set
-
void vsy_PropSetInsertp(vsy_PropSet *p, const Vchar *name, Vobject *v)
place a property in the property set
-
void vsy_PropSetInsertpv(vsy_PropSet *p, const Vchar *name, Vint num, Vobject *v[])
place a property in the property set
-
void vsy_PropSetInsertc(vsy_PropSet *p, const Vchar *name, Vchar *prop)
place a property in the property set
Place the property prop in the property set, associated with the specified name. This will replace any property which may have previously inserted with the same name. All name comparisons are case sensitive. A copy of the name and property is made internal to the PropSet object.
- Errors
SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.
- Parameters:
p – Pointer to PropSet object.
name – String which identifies the property.
prop – Value or property or vector of properties
-
void vsy_PropSetLookupInteger(const vsy_PropSet *p, const Vchar *name, Vint *v)
return property parameters by name
-
void vsy_PropSetLookupFloat(const vsy_PropSet *p, const Vchar *name, Vfloat *v)
return property parameters by name
-
void vsy_PropSetLookupDouble(const vsy_PropSet *p, const Vchar *name, Vdouble *prop)
return property parameters by name
Get properties with the specified name. If the property has not been inserted then the returned properties are undefined.
- Parameters:
p – Pointer to PropSet object.
name – Name of the desired property.
prop – [out] Returned properties
-
void vsy_PropSetLookupString(const vsy_PropSet *p, const Vchar *name, Vchar v[])
return property parameters by name
-
void vsy_PropSetLookupObject(const vsy_PropSet *p, const Vchar *name, Vobject **v)
return property parameters by name
-
void vsy_PropSetLookup(const vsy_PropSet *p, const Vchar *name, Vint *type, Vint *num, Vint *size)
return property parameters by name
Get property type and size parameters with the specified name. The type, num and size are all returned as zero if no property with that name has been previously inserted into the property set. The size is the result of the application of num multiplied by the sizeof operation on the data type, type. All name comparisons are case sensitive.
- Parameters:
p – Pointer to PropSet object.
name – Name of the desired property.
type – [out] Data type of property
x=SYS_DOUBLE type Vdouble =SYS_FLOAT type Vfloat =SYS_INTEGER type Vint =SYS_OBJECT type Vobject* =SYS_STRING type Vchar*
num – [out] Number of data items in property
size – [out] Size of of data items in property
-
void vsy_PropSetRemove(vsy_PropSet *p, const Vchar *name)
remove a property from the property set
Remove the property with the specified name.
Remove all the properties from a PropSet object using
void vsy_PropSetClear (vsy_PropSet *propset)
- Parameters:
p – Pointer to PropSet object.
name – Name of the property to be removed.
-
void vsy_PropSetClear(vsy_PropSet *p)
remove all the properties from a PropSet object
-
void vsy_PropSetInitIter(vsy_PropSet *p)
process each item in the propset
Sequential access to each item in the property set may be implemented using these two functions. Initialize the iteration using
vsy_PropSetInitIter()
. Each call of the methodvsy_PropSetNextIter()
will return one property name from the property set. After every property has been visited in this manner,vsy_PropSetNextIter()
will return name as a NULL pointer until the iteration is restarted usingvsy_PropSetInitIter()
. The properties are visited in an unspecified order.- Parameters:
p – Pointer to PropSet object.
-
void vsy_PropSetNextIter(vsy_PropSet *p, Vchar **name)
process each item in the propset
- Parameters:
p – Pointer to PropSet object.
name – [out] Name of the next property.
-
void vsy_PropSetCopy(vsy_PropSet *p, vsy_PropSet *q)
make a copy of a PropSet object
6.2. Random Numbers - Random
The Random module is used to generate sequences of floating point random numbers in the interval [0.,1.].
Begin and end an instance of an object, return object error flag
vsy_RandomBegin()
- create an instance of a Random objectvsy_RandomEnd()
- destroy an instance of a Random objectvsy_RandomError()
- return Random object error flag
Set and query bits
vsy_RandomInit()
- set random number seedvsy_RandomNumber()
- generate random number
Instance a Random object using vsy_RandomBegin()
. Once a Random object is
instanced, the random number seed may be set with vsy_RandomInit()
.
Setting the random number seed is optional, a suitable one is set internally
when the object is instanced. Generate and retrieve random numbers using
vsy_RandomNumber()
. Note that the Random module does not use any operating
system random number facilities.
Like all other CEETRON SAM modules, all
Random objects which are instanced are independent and thread-safe.
6.2.1. Function Descriptions
The currently available Random functions are described in detail in this section.
-
vsy_Random *vsy_RandomBegin(void)
create an instance of a Random object
Create an instance of a Random object. Memory is allocated for the object private data and the pointer to the data is returned. The random number seed is initialized to a positive number.
Destroy an instance of a Random object using
void vsy_RandomEnd (vsy_Random *random)
Return the current value of a Random object error flag using
Vint vsy_RandomError (vsy_Random *random)
- Returns:
The function returns a pointer to the newly created Random object. If the object creation fails, NULL is returned.
-
void vsy_RandomEnd(vsy_Random *p)
destroy an instance of a Random object
-
Vint vsy_RandomError(vsy_Random *p)
return the current value of a Random object error flag
-
void vsy_RandomInit(vsy_Random *p, Vint seed)
set random number seed
Set the random number seed. The seed should be a large positive integer for the best random number sequence. If the input seed is less than or equal to zero, the seed is set to one. This function may be called any number of times. The seed will initialize the subsequent sequence of random numbers generated by
vsy_RandomNumber()
.- Parameters:
p – Pointer to Random object.
seed – Random number seed.
-
void vsy_RandomNumber(vsy_Random *p, Vfloat *number)
generate random number
Generate and return a random number, random in the interval [0.,1.]. The internal seed is altered by this operation. Use
vsy_RandomInit()
to set the random number seed.- Parameters:
p – Pointer to Random object.
number – [out] Random number
6.3. Data Tables - DataTable
The DataTable module holds a collection of double precision vectors as a function of an independent double precision variable. The vectors held in DataTable may be interpolated at any input value of the independent variable. The data is assumed to be piecewise linear. The user may specify the algorithm used to extrapolate the vector data for values of the independent variable outside the range of user input. The DataTable object may expand to contain an increasing number of vectors. It also supports “iterator” functions which are used to successively visit each vector stored in the data table.
Begin and end an instance of an object, return object error flag
vsy_DataTableBegin()
- create an instance of a DataTable objectvsy_DataTableEnd()
- destroy an instance of a DataTable objectvsy_DataTableError()
- return DataTable object error flag
Set and query elements
vsy_DataTableDef()
- define number of stored vectors and lengthvsy_DataTableInq()
- get current number of vectors and lengthvsy_DataTableClear()
- remove all vectors from the DataTable objectvsy_DataTableCount()
- get number of inserted vectorsvsy_DataTableEval()
- interpolate vectors at specified valuevsy_DataTableEvalGrad()
- interpolate vectors and gradients at valuevsy_DataTableInsert()
- insert vector at specified valuevsy_DataTableLookup()
- find the vector inserted at a specified valuevsy_DataTableForEach()
- call a function one time for each vectorvsy_DataTableInitIter()
- prepare to successively visit each vectorvsy_DataTableNextIter()
- return the next vectorvsy_DataTableSetParami()
- type of interpolation and extrapolation
Instance a DataTable object using vsy_DataTableBegin()
. Once a
DataTable is instanced, an approximate number of double precision
vectors to be stored may
be defined using vsy_DataTableDef()
. The user also specifies in this
function the length
of the vectors which are to be maintained by DataTable.
Each vector in the DataTable object is assumed to be the specified length.
The function vsy_DataTableDef()
allocates an internal array for
the storage of vector pointers.
As vectors are inserted the DataTable module will expand
its internal storage as required. The function vsy_DataTableInq()
returns
the number of vectors which may be managed by the presently allocated
storage.
Each new vector and the associated value of the independent variable
are placed in the data table using vsy_DataTableInsert()
.
The DataTable module does not copy the vector data, it only stores the
pointer to the vector and the value of the associated independent variable.
Two vectors may not be stored at the same value of the associated independent
variable.
The total number of vectors contained in the data table may be found by
calling vsy_DataTableCount()
.
A vector which is inserted with a specified value of the independent variable
may be retrieved using vsy_DataTableLookup()
.
The function vsy_DataTableClear()
removes all vectors from the data table.
Use the function vsy_DataTableEval()
to interpolate or extrapolate the
vector data for a given value of the independent variable.
The type of interpolation and extrapolation to be performed is defined
using vsy_DataTableSetParami()
.
Use vsy_DataTableEvalGrad()
to compute the function gradients as well.
Each vector in the data table may be processed with an “iterator”
construct. The method vsy_DataTableForEach()
takes a function as its
argument and calls that function repeatedly, each time with a vector from
the data table. The pair of methods vsy_DataTableInitIter()
and
vsy_DataTableNextIter()
are used to visit each independent variable, vector
pair using a
loop. Call the first method before the body of the loop to prepare the
DataTable object for the iteration. Within the loop body, call
vsy_DataTableNextIter()
. It will return a double precision value
of the independent variable and a pointer to the vector each
time it is called. It will return zero and a NULL pointer when all of the
vectors have been processed.
6.3.1. Function Descriptions
The currently available DataTable functions are described in detail in this section.
-
vsy_DataTable *vsy_DataTableBegin(void)
create an instance of a DataTable object
Create an instance of a DataTable object. Memory is allocated for the object private data and the pointer to the data is returned.
Destroy an instance of a DataTable object using
void vsy_DataTableEnd (vsy_DataTable *datatable)
Return the current value of a DataTable object error flag using
Vint vsy_DataTableError (vsy_DataTable *datatable)
- Returns:
The function returns a pointer to the newly created DataTable object. If the object creation fails, NULL is returned.
-
void vsy_DataTableEnd(vsy_DataTable *p)
destroy an instance of a DataTable object
-
Vint vsy_DataTableError(vsy_DataTable *p)
return the current value of a DataTable object error flag
-
void vsy_DataTableDef(vsy_DataTable *p, Vint numobj, Vint length)
define number of stored vectors and length
Suggest a number of vectors of size length to be stored in the DataTable. This is used to allocate the initial array of storage which is used to hold each vector/value pair. If the number of inserted vectors is eventually greater than this initial estimate, storage space will dynamically expanded to hold the extra vectors. This function removes any previously inserted vectors.
Find the number and length of vectors which may be managed with the presently allocated storage using
void vsy_DataTableInq (const vsy_DataTable *datatable, Vint *numobj, Vint *length)
- Errors
SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.SYS_ERROR_VALUE
is generated if an improper length is specified.
- Parameters:
p – Pointer to DataTable object.
numobj – Estimated number of vectors to be held.
length – Number of values in each double precision vector
-
void vsy_DataTableInq(const vsy_DataTable *p, Vint *len, Vint *siz)
find the number and length of vectors which may be managed with the presently allocated storage
-
void vsy_DataTableSetParami(vsy_DataTable *p, Vint ptype, Vint iparam)
specify type of interpolation and extrapolation
Set data table evaluation parameters. The
DATATABLE_EXTRAPOLATE
parameter sets the extrapolation method used when the data is to evaluated at a value outside of the input range. The settingDATATABLE_LINEAR
extrapolates linearly using the slope of the first two or last two entries which ever applies. The settingDATATABLE_PARABOLIC_SLOPE
extrapolates linearly using the slope of the parabola fit through the first three or last three entries which ever applies. If only one vector is defined the evaluation is always clamped. If two vectors are defined andDATATABLE_PARABOLIC_SLOPE
has been specified, then linear extrapolation is performed. The defaultDATATABLE_EXTRAPOLATE
isDATATABLE_LINEAR
.The
DATATABLE_INTERPOLATE
parameter sets the interpolation method. Currently the only interpolation method implemented isDATATABLE_LINEAR
. The defaultDATATABLE_INTERPOLATE
isDATATABLE_LINEAR
.- Errors
SYS_ERROR_ENUM
is generated if an improper ptype is specified.
- Parameters:
p – Pointer to DataTable object.
ptype – Type of parameter to set
x=DATATABLE_EXTRAPOLATE Extrapolation method =DATATABLE_INTERPOLATE Interpolation method
iparam – Specifies the integer value that ptype will be set to.
x=DATATABLE_LINEAR Linear interpolation, extrapolation =DATATABLE_CLAMP Clamp to extremes extrapolation =DATATABLE_PARABOLIC_SLOPE Parabolic slope extrapolation
-
void vsy_DataTableCount(const vsy_DataTable *p, Vint *num)
get number of contained vectors
Get the number of vectors which have been inserted.
-
void vsy_DataTableInsert(vsy_DataTable *p, Vdouble value, Vdouble vec[])
insert vector at specified value
Insert the vector vec in the DataTable object. Associate value with this new vector. The data is not copied from vec, instead the pointer value of vec is stored.
- Errors
SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.SYS_ERROR_OPERATION
is generated if a vector has already been inserted at the specified value.
- Parameters:
p – Pointer to DataTable object.
value – Double precision independent variable
vec – Pointer to vector
-
void vsy_DataTableLookup(const vsy_DataTable *p, Vdouble value, Vdouble *vec[])
find the vector inserted at a specified value
Get a pointer to the vector associated the specified value. Returns a NULL pointer if no vector has been entered with this value.
- Parameters:
p – Pointer to DataTable object.
value – Double precision independent variable
vec – [out] Pointer to vector associated with value
-
void vsy_DataTableEval(vsy_DataTable *p, Vdouble value, Vdouble vec[])
interpolate vectors at specified value
Get vector of data evaluated at the specified value. The type of interpolation and extrapolation used during the evaluation is defined using
vsy_DataTableSetParami()
.- Errors
SYS_ERROR_OPERATION
is generated if no data vectors have been defined.
- Parameters:
p – Pointer to DataTable object.
value – Double precision independent variable
vec – [out] Vector data evaluated at value
-
void vsy_DataTableEvalGrad(vsy_DataTable *p, Vdouble value, Vdouble vec[], Vdouble grad[])
interpolate vectors and gradients at specified value
Get vector of data evaluated at the specified value. The type of interpolation and extrapolation used during the evaluation is defined using
vsy_DataTableSetParami()
.- Errors
SYS_ERROR_OPERATION
is generated if no data vectors have been defined.
- Parameters:
p – Pointer to DataTable object.
value – Double precision independent variable
vec – [out] Vector data evaluated at value
grad – [out] Gradient data evaluated at value
-
void vsy_DataTableClear(vsy_DataTable *p)
remove all vectors from the DataTable object
Remove all vectors.
- Parameters:
p – Pointer to DataTable object.
-
void vsy_DataTableInitIter(vsy_DataTable *p)
sequential access to each vector in the data table
-
void vsy_DataTableNextIter(vsy_DataTable *p, Vdouble *var, Vdouble **value)
sequential access to each vector in the data table
-
void vsy_DataTableForEach(vsy_DataTable *p, Vfunc1 *func)
call a function one time for each vector
Calls the supplied function repeatedly, each time using a vector from the data table as the sole argument to this function. This is useful for deallocating a collection of vectors, prior to calling
vsy_DataTableEnd()
. The vectors are visited in an unspecified order.Sequential access to each vector in the data table may also be implemented using
void vsy_DataTableInitIter (vsy_DataTable *datatable)
This is followed by repeated calls to the method
Each call of the methodvoid vsy_DataTableNextIter (vsy_DataTable *datatable, Vdouble *value Vdouble **vec)
vsy_DataTableNextIter()
will return a new vector from the data table, together with its associated value. These value/vec pairs are visited in ascending order of the values. After every vector has been visited in this manner,vsy_DataTableNextIter()
will return a value of zero and a NULL pointer until the iteration is restarted usingvsy_DataTableInitIter()
.- Parameters:
p – Pointer to DataTable object.
func – Pointer to function which is to be applied to each vector.
6.4. Concatenated Storage - Concat
The Concat module stores a series of data records, each of arbitrary length, in an expandable, concatenated storage form. As data records are added to a Concat object, any additional required memory is allocated in relatively large blocks, decreasing the possibility of memory fragmentation due to many small memory allocations. The Concat module supports “iterator” functions which are used to successively visit each data record stored in the concatenated storage.
Begin and end an instance of an object, return object error flag
vsy_ConcatBegin()
- create an instance of a Concat objectvsy_ConcatEnd()
- destroy an instance of a Concat objectvsy_ConcatError()
- return Concat object error flag
Set and query indices
vsy_ConcatDef()
- define total number of bytes to be storedvsy_ConcatInq()
- get current number of bytes storedvsy_ConcatClear()
- delete all data recordsvsy_ConcatCount()
- get number of added recordsvsy_ConcatAdd()
- add a data record of arbitrary lengthvsy_ConcatRef()
- return last addition pointervsy_ConcatInitIter()
- prepare to successively visit each recordvsy_ConcatNextIter()
- return the next record and length
Instance a Concat object using vsy_ConcatBegin()
. Once a
Concat is instanced, an approximate number of bytes
to be stored may
be defined using vsy_ConcatDef()
.
The function, vsy_ConcatDef()
may also
be used to reinitialize the Concat object.
As records are added the Concat module will expand
its internal storage as required.
The function vsy_ConcatInq()
returns
the number of bytes which are currently stored.
Data records are added to the concatenation by calling vsy_ConcatAdd()
.
The data record is defined by a specified number of bytes and a pointer
to the start of the data. The function copies the data and concatenates
it to any previously added data records. The last data concatenation
pointer may be queried using vsy_ConcatRef()
. Call this function just
after a call to vsy_ConcatAdd()
to determine the memory pointer at which
the prior added data was copied.
The total number of records contained in the concatentation may be found by
calling vsy_ConcatCount()
.
Note that there are no functions to remove a specific data record.
The pair of methods vsy_ConcatInitIter()
and
vsy_ConcatNextIter()
are used to visit each data record using a
loop. Call the first method before the body of the loop to prepare the
Concat object for the iteration. Within the loop body, call
vsy_ConcatNextIter()
. It will return a number of bytes and pointer
to the start of the data record each
time it is called. It will return zero and a NULL pointer when all of the
records have been processed.
All data may be deleted using vsy_ConcatClear()
.
6.4.1. Function Descriptions
The currently available Concat functions are described in detail in this section.
-
vsy_Concat *vsy_ConcatBegin(void)
create an instance of a Concat object
Create an instance of a Concat object. Memory is allocated for the object private data and the pointer to the data is returned.
Destroy an instance of a Concat object using
void vsy_ConcatEnd (vsy_Concat *concat)
Return the current value of a Concat object error flag using
Vint vsy_ConcatError (vsy_Concat *concat)
- Returns:
The function returns a pointer to the newly created Concat object. If the object creation fails, NULL is returned.
-
void vsy_ConcatDef(vsy_Concat *p, Vlong maxbytes)
define total number of bytes to be stored
Suggest a number of bytes, maxbytes to be stored in the Concat. If an added data record is eventually greater than this initial estimate, storage space will dynamically expand to hold the data. This function deletes any previously entered data.
Find the number of bytes presently stored using
void vsy_ConcatInq (const vsy_Concat *concat, Vlong *maxbytes)
- Errors
SYS_ERROR_VALUE
is generated if an improper maxbytes is specified.
- Parameters:
p – Pointer to Concat object.
maxbytes – Estimated number of bytes to be held.
-
void vsy_ConcatCount(const vsy_Concat *p, Vint *num)
get number of added records
Get the number of data records which have been added.
- Parameters:
p – Pointer to Concat object.
num – [out] Number of added data records
-
void vsy_ConcatAdd(vsy_Concat *p, Vint nbytes, void *data)
add a data record of arbitrary length
Copy nbytes of data from pointer, data, to concatenated storage. Use
vsy_ConcatRef()
to determine the memory location to which the data was copied in concatenation storage after calling this function.- Errors
SYS_ERROR_VALUE
is generated if an improper nbytes is specified.SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.
- Parameters:
p – Pointer to Concat object.
nbytes – Number of bytes in data
data – Pointer to data to copy to concatenation
-
void vsy_ConcatRef(const vsy_Concat *p, void **data)
return last addition pointer
Return the pointer to the last memory location in concatenated storage to which the previous data record was added.
- Parameters:
p – Pointer to Concat object.
data – [out] Pointer to last data addition address in concatention
-
void vsy_ConcatClear(vsy_Concat *p)
delete all data records
Clear all data from the concatenation.
- Parameters:
p – Pointer to Concat object.
-
void vsy_ConcatInitIter(vsy_Concat *p)
process each record in concatenation
Sequential access to each data record in the concatenation may be implemented using these two functions. Initialize the iteration using
vsy_ConcatInitIter()
. Each call of the methodvsy_ConcatNextIter()
will return information for one data record in the concatenation. After every data record has been visited in this manner,vsy_ConcatNextIter()
will return nbytes as zero and data as a NULL pointer until the iteration is restarted usingvsy_ConcatInitIter()
. The data records are visited in the order of addition.- Parameters:
p – Pointer to Concat object.
6.5. Linked List Storage - LinkList
The LinkList module stores a series of data records, each of fixed length, in a linked list structure. As data records are added to a LinkList object, any additional required memory is allocated in relatively large blocks, decreasing the possibility of memory fragmentation due to many small memory allocations. The linked list data organization makes the LinkList module useful for efficient management of fixed length data records which are repeatedly inserted and deleted. The LinkList module supports “iterator” functions which are used to successively visit each data record stored in the linked list.
Begin and end an instance of an object, return object error flag
vsy_LinkListBegin()
- create an instance of a LinkList objectvsy_LinkListEnd()
- destroy an instance of a LinkList objectvsy_LinkListError()
- return LinkList object error flag
Set and query indices
vsy_LinkListDef()
- define length of recordsvsy_LinkListInq()
- get current number of records and lengthvsy_LinkListClear()
- delete all data recordsvsy_LinkListCount()
- get number of recordsvsy_LinkListAdd()
- add a data record to linked listvsy_LinkListRef()
- return pointer given indexvsy_LinkListRemove()
- delete a record given indexvsy_LinkListHead()
- return head record index and pointervsy_LinkListInitIter()
- prepare to successively visit each recordvsy_LinkListNextIter()
- return the next record index and pointer
Instance a LinkList object using vsy_LinkListBegin()
. Once a
LinkList is instanced, specify the approximate number of records
to be stored and the fixed length of each record
using vsy_LinkListDef()
.
The function, vsy_LinkListDef()
may also
be used to reinitialize the LinkList object.
As records are added the LinkList module will expand
its internal storage as required.
Records are keyed by an integer index. A fixed length of memory is
associated with each record.
Data records may be added to the linked list by calling vsy_LinkListAdd()
.
In this case the function returns an integer key and a pointer to the
memory associated with the integer key.
The pointer is guaranteed
to be aligned for use with all data types.
Use vsy_LinkListRef()
to return the pointer to the memory associated with
a given index. A record may be deleted using vsy_LinkListRemove()
.
The total number of records contained in the linked list may be found by
calling vsy_LinkListCount()
.
The pair of methods vsy_LinkListInitIter()
and
vsy_LinkListNextIter()
are used to visit each data record using a
loop. Call the first method before the body of the loop to prepare the
LinkList object for the iteration. Within the loop body, call
vsy_LinkListNextIter()
. It will return an integer index and pointer
to the start of the data record each
time it is called. It will return zero and a NULL pointer when all of the
records have been processed.
All data may be deleted using vsy_LinkListClear()
.
6.5.1. Function Descriptions
The currently available LinkList functions are described in detail in this section.
-
vsy_LinkList *vsy_LinkListBegin(void)
create an instance of a LinkList object
Create an instance of a LinkList object. Memory is allocated for the object private data and the pointer to the data is returned.
Destroy an instance of a LinkList object using
void vsy_LinkListEnd (vsy_LinkList *linklist)
Return the current value of a LinkList object error flag using
Vint vsy_LinkListError (vsy_LinkList *linklist)
- Returns:
The function returns a pointer to the newly created LinkList object. If the object creation fails, NULL is returned.
-
void vsy_LinkListEnd(vsy_LinkList *p)
destroy an instance of a LinkList object
-
Vint vsy_LinkListError(vsy_LinkList *p)
return the current value of a LinkList object error flag
-
void vsy_LinkListDef(vsy_LinkList *p, Vint len, Vint nbytes)
define length of records
Specify a number of records, len, and the length of each record, nbytes to be stored in the LinkList. The number of records, len, only need be approximate. This function deletes any previously entered data.
Find the number of records currently allocated and the fixed length of each record in bytes using
void vsy_LinkListInq (const vsy_LinkList *linklist, Vint *len, Vint *nbytes)
- Errors
SYS_ERROR_VALUE
is generated if an improper len or nbytes is specified.
- Parameters:
p – Pointer to LinkList object.
len – Approximate number of records
nbytes – Length of each record in bytes
-
void vsy_LinkListInq(const vsy_LinkList *p, Vint *len, Vint *nbytes)
find the number of records currently allocated and the fixed length of each record in bytes
-
void vsy_LinkListCount(const vsy_LinkList *p, Vint *num)
get number of records
Get the number of data records.
- Parameters:
p – Pointer to LinkList object.
num – [out] Number of data records
-
void vsy_LinkListAdd(vsy_LinkList *p, Vint *index, Vobject **value)
add a data record to linked list
Add a record to the linked list. An index is returned as well as a pointer, value, to the memory associated with the index.
- Errors
SYS_ERROR_MEMORY
is generated if new storage was unable to be allocated.
- Parameters:
p – Pointer to LinkList object.
index – [out] Index of record
value – [out] Pointer to memory associated with index.
-
void vsy_LinkListRef(const vsy_LinkList *p, Vint index, Vobject **value)
return pointer given index
Return the pointer to memory associated with index. If the index has not been defined, value is set to NULL.
- Parameters:
p – Pointer to LinkList object.
index – Index of record
value – [out] Pointer to memory associated with index.
-
void vsy_LinkListRemove(vsy_LinkList *p, Vint index)
delete a record given index
Remove the record associated with index from the linked list.
- Errors
SYS_ERROR_VALUE
is generated if an improper index is specified.
- Parameters:
p – Pointer to LinkList object.
index – Index of record
-
void vsy_LinkListClear(vsy_LinkList *p)
delete all data records
Clear all data from the linked list.
- Parameters:
p – Pointer to LinkList object.
-
void vsy_LinkListHead(vsy_LinkList *p, Vint *index, Vobject **value)
return head record index and pointer
Access the data record at the head of the linked list.
- Parameters:
p – Pointer to LinkList object.
index – [out] Index of record
value – [out] Pointer to memory associated with index.
-
void vsy_LinkListInitIter(vsy_LinkList *p)
process each record in linked list
Access to each data record in the linked list may be implemented using these two functions. Initialize the iteration using
vsy_LinkListInitIter()
. Each call of the methodvsy_LinkListNextIter()
will return information for one data record in the linked list. After every data record has been visited in this manner,vsy_LinkListNextIter()
will return index as zero and value as a NULL pointer until the iteration is restarted usingvsy_LinkListInitIter()
.- Parameters:
p – Pointer to LinkList object.
6.6. String Utilities - StrUtil
The StrUtil module is a static module. Its main purpose is to provide utilities for wide character and UTF-8 encoded string conversion and length queries.
The StrUtil module supports the following functions.
UTF-8 and Wide Character String Functions
vut_StrUtilFromUTF8()
- convert UTF-8 string to wide charactervut_StrUtilToUTF8()
- convert wide character string to UTF-8vut_StrUtilLenUTF8()
- determine character length of UTF-8 stringvut_StrUtilMBCSfromUTF8()
- convert UTF-8 string to MBCS
The StrUtil module is designed to provide system independent
string utilities for UTF-8 and wide character string conversion and
length query. The vut_StrUtilMBCSfromUTF8()
will convert UTF-8 to
Multi-Byte Character Set (MBCS).
6.6.1. Function Descriptions
The currently available StrUtil functions are described in detail in this section.
-
void vut_StrUtilFromUTF8(const char *utf8buf, Vint maxwidechar, wchar_t *widebuf)
convert UTF-8 string to wide character
Convert a UTF-8 encoded string to a wide character string. The input parameter maxwidechar is the maximum length able to be accommodated in widebuf.
- Parameters:
utf8buf – UTF-8 encoded string
maxwidechar – Maximum number of wide characters.
widebuf – [out] Wide character encoded string
-
void vut_StrUtilToUTF8(const wchar_t *widebuf, Vint maxutf8char, char *utf8buf)
convert wide character string to UTF-8
Convert a wide character encoded string to a UTF-8 character string. The input parameter maxutf8char is the maximum length able to be accommodated in utf8buf.
- Parameters:
widebuf – Wide character encoded string
maxutf8char – Maximum number of UTF-8 characters.
utf8buf – [out] UTF-8 encoded string
-
Vint vut_StrUtilLenUTF8(const char *utf8buf)
determine character length of UTF-8 string
The number of UTF-8 encoded characters is returned.
- Parameters:
utf8buf – UTF-8 encoded string
-
void vut_StrUtilMBCSfromUTF8(const char *utf8buf, Vint maxMBCSchar, Vuchar mbcs[])
convert UTF-8 string to MBCS
Convert a UTF-8 encoded string to a wide character string. The input parameter maxwidechar is the maximum length able to be accommodated in widebuf.
- Parameters:
utf8buf – UTF-8 encoded string
maxMBCSchar – Maximum number of MBCS characters.
mbcs – [out] MBCS string