das2C
das core C utilities (v3)
descriptor.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2024 Chris Piker <chris-piker@uiowa.edu>
2  * 2004-2006 Jeremy Faden <jeremy-faden@uiowa.edu>
3  *
4  * This file is part of das2C, the Core Das2 C Library.
5  *
6  * Das2C is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
21 #ifndef _descriptor_h_
22 #define _descriptor_h_
23 #include <stdbool.h>
24 
25 #include <das2/units.h>
26 #include <das2/util.h>
27 #include <das2/buffer.h>
28 #include <das2/property.h>
29 #include <das2/array.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
43 typedef enum DescriptorType {
44  UNK_DESC=0, STREAM=14000,
45  PLANE=14001, PACKET=14002,
46  PHYSDIM=15001, DATASET=15002,
47  FRAME=15003
48 } desc_type_t;
49 
50 
51 const char* das_desc_type_str(desc_type_t dt);
52 
74 typedef struct das_descriptor {
75  desc_type_t type;
76 
77  /* Properties will now be held in a das array so that they are in a continuous
78  block of memory. Properties are laid out in memory as so:
79 
80  valid_code\0name\0type_code\0value\0
81 
82  this means that the array is RANK_2(0,4,*) and it will need 2 ancillary
83  arrays of pointers to keep track of the boundaries. Thus the number of
84  independent allocations drops from:
85 
86  properties * N so O(N)
87  to:
88  3 so O(1)
89 
90  and there is no upper limit to the number of properties (yay!)
91  */
92  //char* properties[400];
93  DasAry properties;
94 
95  //Number of invalid properites (saved to make length cals faster)
96  size_t uInvalid;
97 
98  const struct das_descriptor* parent;
99  bool bLooseParsing;
100 } DasDesc;
101 
110 #define DasDesc_type(P) ((P)->type)
111 
112 /* @name DasDesc Functions
113  * These work for any type of Descriptor, including ::PlaneDesc ,
114  * ::PktDesc, ::StreamDesc, ::DasDs and ::DasDim.
115  * To make your compiler happy you will need to cast Plane, Packet and
116  * Stream Descriptor pointers to just the generic type of Descriptor pointer
117  * when using these functions. For example:
118  * @code
119  * PktDesc* pPktDesc;
120  * DasDesc_has((Descriptor*)pPktDesc, "SomePropName");
121  * @endcode
122  * @memberof DasDesc
123  */
124 /* @{ */
125 
126 
127 
132 DAS_API void DasDesc_init(DasDesc* pThis, desc_type_t type);
133 
134 
139 DAS_API char* DasDesc_info(const DasDesc* pThis, char* sBuf, int nLen, char* sIndent);
140 
141 /* Make an 'Unknown' type descriptor, incase you like using descriptor objects
142  * to store things in your code, not used by the library
143  * @memberof DasDesc
144  */
145 DAS_API DasDesc* new_Descriptor(void);
146 
147 DAS_API void DasDesc_freeProps(DasDesc* pThis);
148 
162 DAS_API bool DasDesc_equals(const DasDesc* pThis, const DasDesc* pOther);
163 
175 DAS_API const DasDesc* DasDesc_parent(DasDesc* pThis);
176 
194 DAS_API size_t DasDesc_length(const DasDesc* pThis);
195 
216 DAS_API const DasProp* DasDesc_getPropByIdx(const DasDesc* pThis, size_t uIdx);
217 
232 DAS_API const char* DasDesc_getNameByIdx(const DasDesc* pThis, size_t uIdx);
233 
248 DAS_API const char* DasDesc_getValByIdx(const DasDesc* pThis, size_t uIdx);
249 
253 DAS_API const char* DasDesc_getTypeByIdx(const DasDesc* pThis, size_t uIdx);
254 
255 
259 DAS_API const char* DasDesc_getTypeByIdx3(const DasDesc* pThis, size_t uIdx);
260 
269 DAS_API bool DasDesc_has(const DasDesc* pThis, const char* sName );
270 
294  DasDesc* pThis, const char* sType, const char* sName, const char* sVal
295 );
296 
303  DasDesc* pThis, const char* sType, ubyte uType, const char* sName,
304  const char* sVal, char cSep, das_units units, int nStandard
305 );
306 
308 DAS_API DasErrCode DasDesc_setProp(DasDesc* pThis, const DasProp* pProp);
309 
310 DAS_API const char* DasDesc_getType(const DasDesc* pThis, const char* sName);
311 
312 DAS_API const char* DasDesc_get(const DasDesc* pThis, const char* sName);
313 
321 const DasProp* DasDesc_getProp(const DasDesc* pThis, const char* sName);
322 
323 
334 const DasProp* DasDesc_getLocal(const DasDesc* pThis, const char* sName);
335 
336 
337 
338 
348 DAS_API bool DasDesc_remove(DasDesc* pThis, const char* sName);
349 
353 DAS_API const char* DasDesc_getStr(const DasDesc* pThis, const char* sName);
354 
355 
403 DAS_API size_t DasDesc_getStrAry(
404  DasDesc* pThis, const char* sName, char* pBuf, size_t uBufSz,
405  char** psVals, size_t uMaxVals
406 );
407 
417 DAS_API size_t DasDesc_getArray(
418  DasDesc* pThis, const char* sName, char cSep,
419  char* pBuf, size_t uBufSz, char** psVals, size_t uMaxVals
420 );
421 
422 
429  DasDesc* pThis, const char* sName, const char* sVal
430 );
431 
436  DasDesc* pThis, const char* sName, const char* sFmt, ...
437 );
438 
439 
444 DAS_API double DasDesc_getDouble(const DasDesc* pThis, const char* sName);
445 
450  DasDesc* pThis, const char* sName, double value
451 );
452 
467 DAS_API double DasDesc_getDatum(
468  DasDesc* pThis, const char* sName, das_units units
469 );
470 
484  DasDesc* pThis, const char* sName, double rVal, das_units units
485 );
486 
506 DAS_API double* DasDesc_getDoubleAry(
507  DasDesc* pThis, const char* sName, int* pNumItems
508 );
509 
514  DasDesc* pThis, const char* sName, int nItems, double* pValues
515 );
516 
527 DAS_API int DasDesc_getInt(const DasDesc* pThis, const char* sName);
528 
532 DAS_API DasErrCode DasDesc_setInt(DasDesc* pThis, const char* sName, int nVal);
533 
541 DAS_API bool DasDesc_getBool(DasDesc* pThis, const char* sName);
542 
550  DasDesc* pThis, const char* sName, bool bVal
551 );
552 
557  DasDesc* pThis, const char* sName, double beg, double end, das_units units
558 );
559 
568  DasDesc* pThis, const char* sName, char* sMin, char* sMax,
569  das_units* pUnits, size_t uLen
570 );
571 
577  DasDesc* pThis, const char* sName, int nItems, float* pValues
578 );
579 
585 DAS_API void DasDesc_copyIn(DasDesc* pThis, const DasDesc* pOther);
586 
587 /* New lib is source compatable, not binary compatable */
588 #define DasDesc_encode DasDesc_encode2
589 
599  DasDesc* pThis, DasBuf* pBuf, const char* sIndent
600 );
601 
605  DasDesc* pThis, DasBuf* pBuf, const char* sIndent
606 );
607 
608 
609 
610 /* * @} */
611 
612 #ifdef __cplusplus
613 }
614 #endif
615 
616 #endif /* _descriptor_h_ */
A dynamic buffer with multi-dimensional array style access.
Utility to assist with encode and decode operations.
const DasProp * DasDesc_getProp(const DasDesc *pThis, const char *sName)
Get a property if present in descriptor or it's parent (das3)
DAS_API DasErrCode DasDesc_setProp(DasDesc *pThis, const DasProp *pProp)
Overwrite, or copy-in a fully formatted property.
DAS_API DasErrCode DasDesc_setBool(DasDesc *pThis, const char *sName, bool bVal)
Set a boolean property Encodes the value as either the string "true" or the string "false".
desc_type_t
enumeration of Descriptor types, used internally for type checking.
Definition: descriptor.h:43
DAS_API DasErrCode DasDesc_flexSet(DasDesc *pThis, const char *sType, ubyte uType, const char *sName, const char *sVal, char cSep, das_units units, int nStandard)
Create or set a existing property.
DAS_API DasErrCode DasDesc_encode3(DasDesc *pThis, DasBuf *pBuf, const char *sIndent)
Encode a generic set of properties to a buffer, in das3 format.
const DasProp * DasDesc_getLocal(const DasDesc *pThis, const char *sName)
Get a property if present in this descriptor only (das3)
DAS_API size_t DasDesc_getArray(DasDesc *pThis, const char *sName, char cSep, char *pBuf, size_t uBufSz, char **psVals, size_t uMaxVals)
Get string array with given seperator.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: defs.h:164
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
Dynamic recursive ragged arrays.
Definition: array.h:270
Buffer class to handle accumulating byte streams.
Definition: buffer.h:47
Base structure for Stream Header Items.
Definition: descriptor.h:74
DAS_API DasErrCode DasDesc_setStr(DasDesc *pThis, const char *sName, const char *sVal)
SetProperty methods add properties to any Descriptor (stream,packet,plane).
DAS_API const char * DasDesc_getValByIdx(const DasDesc *pThis, size_t uIdx)
Get a property value by an index.
DAS_API const char * DasDesc_getStr(const DasDesc *pThis, const char *sName)
read the property of type String named sName.
DAS_API int DasDesc_getInt(const DasDesc *pThis, const char *sName)
Get a property integer value.
DAS_API const char * DasDesc_getTypeByIdx3(const DasDesc *pThis, size_t uIdx)
Get a data type of a property by an index, das3 covention.
DAS_API const char * DasDesc_getTypeByIdx(const DasDesc *pThis, size_t uIdx)
Get a data type of a property by an index.
DAS_API 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.
DAS_API const char * DasDesc_getNameByIdx(const DasDesc *pThis, size_t uIdx)
Get a property name by an index.
DAS_API DasErrCode DasDesc_setDoubleArray(DasDesc *pThis, const char *sName, int nItems, double *pValues)
Set the property of type double array.
DAS_API bool DasDesc_equals(const DasDesc *pThis, const DasDesc *pOther)
Check to see if two descriptors contain the same properties Note, the order of the properties may be ...
DAS_API DasErrCode DasDesc_encode2(DasDesc *pThis, DasBuf *pBuf, const char *sIndent)
Encode a generic set of properties to a buffer.
DAS_API DasErrCode DasDesc_setDatum(DasDesc *pThis, const char *sName, double rVal, das_units units)
Set property of type Datum (double, UnitType pair)
DAS_API const DasDesc * DasDesc_parent(DasDesc *pThis)
The the parent of a Descriptor.
DAS_API char * DasDesc_info(const DasDesc *pThis, char *sBuf, int nLen, char *sIndent)
Print 1-line versions of each property in a descriptor.
DAS_API size_t DasDesc_getStrAry(DasDesc *pThis, const char *sName, char *pBuf, size_t uBufSz, char **psVals, size_t uMaxVals)
Get a multi-valued string property.
DAS_API double * DasDesc_getDoubleAry(DasDesc *pThis, const char *sName, int *pNumItems)
Get the values of an array property.
DAS_API DasErrCode DasDesc_setDouble(DasDesc *pThis, const char *sName, double value)
Set property of type double.
DAS_API size_t DasDesc_length(const DasDesc *pThis)
Get the number of properties in a descriptor.
DAS_API bool DasDesc_remove(DasDesc *pThis, const char *sName)
Remove a property from a descriptor, if preset.
DAS_API bool DasDesc_has(const DasDesc *pThis, const char *sName)
Determine if a property is present in a Descriptor or it's ancestors.
DAS_API DasErrCode DasDesc_setInt(DasDesc *pThis, const char *sName, int nVal)
Set the property of type int.
DAS_API DasErrCode DasDesc_setFloatAry(DasDesc *pThis, const char *sName, int nItems, float *pValues)
Set the property of type float array.
DAS_API DasErrCode DasDesc_vSetStr(DasDesc *pThis, const char *sName, const char *sFmt,...)
Set a string property in the manner of sprintf.
DAS_API const DasProp * DasDesc_getPropByIdx(const DasDesc *pThis, size_t uIdx)
Get a property name by an index.
DAS_API bool DasDesc_getBool(DasDesc *pThis, const char *sName)
Get a property boolean value.
DAS_API DasErrCode DasDesc_set(DasDesc *pThis, const char *sType, const char *sName, const char *sVal)
Generic property setter.
DAS_API void DasDesc_copyIn(DasDesc *pThis, const DasDesc *pOther)
Deepcopy properties into a descriptor.
DAS_API double DasDesc_getDatum(DasDesc *pThis, const char *sName, das_units units)
Get the a numeric property in the specified units.
DAS_API void DasDesc_init(DasDesc *pThis, desc_type_t type)
Initialize a memory location as a valid das descriptor.
DAS_API double DasDesc_getDouble(const DasDesc *pThis, const char *sName)
Read the property of type double named sName.
DAS_API DasErrCode DasDesc_setDatumRng(DasDesc *pThis, const char *sName, double beg, double end, das_units units)
Set property of type DatumRange (double, double, UnitType triple)
Individual properties of a desciptor.
Definition: property.h:49
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...