libdas2
das2 core C utilities
|
#include <das2/descriptor.h>
Base structure for Stream Header Items.
Descriptors have properties associated with them. Stream Descriptors, Packet Descriptors, and Plane Descriptors are all extensions of this object type, thus the functions for this structure may be used with any Descriptor structure in the library.
Note: Properties Cascade
Properties cascade in Das2 Streams. Thus if a particular descriptor does not have a particular property then the various getProperty() functions will search parent descriptors for requested property. The descriptor ownership hierarchy for Das2 Streams is:
This class this is just a hobbled dictionary of objects plus some string conversion functions. Using an actual C dictionary implementation would improve code quite a bit. If I were going to go to the trouble to do that I would make it multi-lingual as well. -cwp
Descriptor Functions | |
These work for any type of Descriptor, including PlaneDesc , PktDesc, StreamDesc, DasDs and DasVar. To make your compiler happy you will need to cast Plane, Packet and Stream Descriptor pointers to just the generic type of Descriptor pointer when using these functions. For example: | |
bool | DasDesc_equals (const DasDesc *pOne, const DasDesc *pTwo) |
Check to see if two descriptors contain the same properties Note, the order of the properties may be different between the descriptors but if the contents are the same then the descriptors are considered to be equal. More... | |
const DasDesc * | DasDesc_parent (DasDesc *pThis) |
The the parent of a Descriptor. More... | |
size_t | DasDesc_length (const DasDesc *pThis) |
Get the number of properties in a descriptor. More... | |
const char * | DasDesc_getNameByIdx (const DasDesc *pThis, size_t uIdx) |
Get a property name by an index. More... | |
const char * | DasDesc_getValByIdx (const DasDesc *pThis, size_t uIdx) |
Get a property value by an index. More... | |
const char * | DasDesc_getTypeByIdx (const DasDesc *pThis, size_t uIdx) |
Get a data type of a property by an index. | |
bool | DasDesc_has (const DasDesc *pThis, const char *propertyName) |
Determine if a property is present in a Descriptor or it's ancestors. More... | |
DasErrCode | DasDesc_set (DasDesc *pThis, const char *sType, const char *sName, const char *sVal) |
Generic property setter. More... | |
bool | DasDesc_remove (DasDesc *pThis, const char *propretyName) |
Remove a property from a descriptor, if preset. More... | |
const char * | DasDesc_getStr (const DasDesc *pThis, const char *propertyName) |
read the property of type String named propertyName. | |
DasErrCode | DasDesc_setStr (DasDesc *pThis, const char *sName, const char *sVal) |
SetProperty methods add properties to any Descriptor (stream,packet,plane). More... | |
DasErrCode | DasDesc_vSetStr (DasDesc *pThis, const char *sName, const char *sFmt,...) |
Set a string property in the manner of sprintf. | |
double | DasDesc_getDouble (const DasDesc *pThis, const char *propertyName) |
Read the property of type double named propertyName. More... | |
DasErrCode | DasDesc_setDouble (DasDesc *pThis, const char *propertyName, double value) |
Set property of type double. | |
double | DasDesc_getDatum (DasDesc *pThis, const char *sPropName, das_units units) |
Get the a numeric property in the specified units. More... | |
DasErrCode | DasDesc_setDatum (DasDesc *pThis, const char *sName, double rVal, das_units units) |
Set property of type Datum (double, UnitType pair) More... | |
double * | DasDesc_getDoubleAry (DasDesc *pThis, const char *propertyName, int *nitems) |
Get the values of an array property. More... | |
DasErrCode | DasDesc_setDoubleArray (DasDesc *pThis, const char *propertyName, int nitems, double *value) |
Set the property of type double array. | |
int | DasDesc_getInt (const DasDesc *pThis, const char *propertyName) |
Get a property integer value. More... | |
DasErrCode | DasDesc_setInt (DasDesc *pThis, const char *sName, int nVal) |
Set the property of type int. | |
bool | DasDesc_getBool (DasDesc *pThis, const char *sPropName) |
Get a property boolean value. More... | |
DasErrCode | DasDesc_setDatumRng (DasDesc *pThis, const char *sName, double beg, double end, das_units units) |
Set property of type DatumRange (double, double, UnitType triple) | |
DasErrCode | DasDesc_getStrRng (DasDesc *pThis, const char *sName, char *sMin, char *sMax, das_units *pUnits, size_t uLen) |
Get a property of type DatumRange with unconverted strings. More... | |
DasErrCode | DasDesc_setFloatAry (DasDesc *pThis, const char *propertyName, int nitems, float *value) |
Set the property of type float array. More... | |
void | DasDesc_copyIn (DasDesc *pThis, const DasDesc *source) |
Deepcopy properties into a descriptor. More... | |
DasErrCode | DasDesc_encode (DasDesc *pThis, DasBuf *pBuf, const char *sIndent) |
Encode a generic set of properties to a buffer. More... | |
Check to see if two descriptors contain the same properties Note, the order of the properties may be different between the descriptors but if the contents are the same then the descriptors are considered to be equal.
Note that parent descriptor properties are not checked when handling the comparison.
pOne | The first descriptor |
pTwo | The second descriptor |
The the parent of a Descriptor.
Plane descriptors are owned by packet descriptors and packet descriptors are owned by stream descriptors. This function lets you craw the ownership hierarchy
pThis |
size_t DasDesc_length | ( | const DasDesc * | pThis | ) |
Get the number of properties in a descriptor.
Descriptor's have a hierarchy. In general when a property is requested, if a given Descriptor does not have a property the request is passed to the parent descriptor. This function only returns the number of properties in the given descriptor. It does not include properties owned by parents or ancestors.
This is useful when iterating over all properties in a descriptor.
pThis | A pointer to the descriptor to query |
const char * DasDesc_getNameByIdx | ( | const DasDesc * | pThis, |
size_t | uIdx | ||
) |
Get a property name by an index.
This is useful when iterating over all properties in a Descriptor. Only properties owed by a descriptor are queried in this manner. Parent descriptors are not consulted.
pThis | A pointer to the descriptor to query |
uIdx | The index of the property, will be a value between 0 and the return value from Desc_getNProps() |
const char * DasDesc_getValByIdx | ( | const DasDesc * | pThis, |
size_t | uIdx | ||
) |
Get a property value by an index.
This is useful when iterating over all properties in a Descriptor. Only properties owned by a descriptor are queried in this manner. Parent descriptors are not consulted.
pThis | A pointer to the descriptor to query |
uIdx | The number of the property, will be a value from 0 and 1 less than the return value from Desc_getNProps() |
bool DasDesc_has | ( | const DasDesc * | pThis, |
const char * | propertyName | ||
) |
Determine if a property is present in a Descriptor or it's ancestors.
pThis | the descriptor object to query |
propertyName | the name of the property to retrieve. |
DasErrCode DasDesc_set | ( | DasDesc * | pThis, |
const char * | sType, | ||
const char * | sName, | ||
const char * | sVal | ||
) |
Generic property setter.
All properties are stored internally as strings. The various typed Desc_setProp* functions all call this function after converting their arguments to strings.
pThis | The Descriptor to receive the property |
sType | The Type of property should be one of the strings:
|
sName | The property name, which cannot contain spaces |
sVal | The value, which may be anything including NULL |
bool DasDesc_remove | ( | DasDesc * | pThis, |
const char * | propretyName | ||
) |
Remove a property from a descriptor, if preset.
It is safe to call this function for properties not present on the descriptor, it simply does nothing and returns false.
DasErrCode DasDesc_setStr | ( | DasDesc * | pThis, |
const char * | sName, | ||
const char * | sVal | ||
) |
SetProperty methods add properties to any Descriptor (stream,packet,plane).
The typed methods (e.g. setPropertyDatum) property tag the property with a type so that it will be parsed into the given type.
double DasDesc_getDouble | ( | const DasDesc * | pThis, |
const char * | propertyName | ||
) |
Read the property of type double named propertyName.
The property value is parsed using sscanf.
Get the a numeric property in the specified units.
Descriptor properties my be provided as Datums. Datums are a double value along with a specified measurement unit.
pThis | The Descriptor containing the property in question. |
sPropName | The name of the property to retrieve. |
units | The units of measure in which the return value will be represented. If the property value is stored in a different set of units than those indicated by this parameter than the output will be converted to the given unit type. |
DasErrCode DasDesc_setDatum | ( | DasDesc * | pThis, |
const char * | sName, | ||
double | rVal, | ||
das_units | units | ||
) |
Set property of type Datum (double, UnitType pair)
If a property with this name already exists it is 1st deleted and then the new property is added in its place.
pThis | The descriptor to receive the property |
sName | The name of the property to set |
rVal | The numeric value of the property |
units | The units of measure for the property |
double * DasDesc_getDoubleAry | ( | DasDesc * | pThis, |
const char * | propertyName, | ||
int * | nitems | ||
) |
Get the values of an array property.
Space for the array is allocated by getDoubleArrayFromString. and nitems is set to indicate the size of the array.
[in] | pThis | the descriptor object to query |
[in] | propertyName | the name of the proprety to retrieve |
[out] | nitems | a pointer to a an integer containing the number of values in the returned array. |
int DasDesc_getInt | ( | const DasDesc * | pThis, |
const char * | propertyName | ||
) |
Get a property integer value.
pThis | the descriptor object to query |
propertyName | the name of the proprety to retrieve |
bool DasDesc_getBool | ( | DasDesc * | pThis, |
const char * | sPropName | ||
) |
Get a property boolean value.
pThis | the descriptor object to query |
sPropName | the name of the proprety to retrieve |
DasErrCode DasDesc_getStrRng | ( | DasDesc * | pThis, |
const char * | sName, | ||
char * | sMin, | ||
char * | sMax, | ||
das_units * | pUnits, | ||
size_t | uLen | ||
) |
Get a property of type DatumRange with unconverted strings.
This version is handy if you just want to know the intrinsic units of the range without converting the values to some specific type of double value.
DasErrCode DasDesc_setFloatAry | ( | DasDesc * | pThis, |
const char * | propertyName, | ||
int | nitems, | ||
float * | value | ||
) |
Set the property of type float array.
Note the array is cast to a double array before encoding.
Deepcopy properties into a descriptor.
pThis | the descriptor to receive a copy of the properties |
source | the descriptor with the properties to be copied. |
DasErrCode DasDesc_encode | ( | DasDesc * | pThis, |
DasBuf * | pBuf, | ||
const char * | sIndent | ||
) |
Encode a generic set of properties to a buffer.
pThis | The descriptors who's properties should be encoded |
pBuf | A buffer object to receive the XML data |
sIndent | An indent level for the property strings, makes 'em look nice |