das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
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 das2C; 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 <das3/units.h>
26#include <das3/util.h>
27#include <das3/buffer.h>
28#include <das3/property.h>
29#include <das3/array.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
43typedef enum DescriptorType {
44 UNK_DESC=0, STREAM=14000,
45 PLANE=14001, PACKET=14002,
46 DATASET=15000, PHYSDIM=15001,
47 VARIABLE=15002,
49
50
51DAS_API const char* das_desc_type_toStr(desc_type_t dt);
52
74typedef 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 properties (saved to make length cals faster)
96 size_t uInvalid;
97
98 struct das_descriptor* parent;
99 bool bLooseParsing;
100
101 /* This descriptor does NOT inherit properties: DasDesc_getProp stops
102 its parent walk here even when parent is set. */
103 bool bNoInherit;
104} DasDesc;
105
114#define DasDesc_type(P) ((P)->type)
115
116/* @name DasDesc Functions
117 * These work for any type of Descriptor, including ::PlaneDesc ,
118 * ::PktDesc, ::DasStream, ::DasDs and ::DasDim.
119 * To make your compiler happy you will need to cast Plane, Packet and
120 * Stream Descriptor pointers to just the generic type of Descriptor pointer
121 * when using these functions. For example:
122 * @code
123 * PktDesc* pPktDesc;
124 * DasDesc_has((Descriptor*)pPktDesc, "SomePropName");
125 * @endcode
126 * @memberof DasDesc
127 */
128/* @{ */
129
130
131
140DAS_API void DasDesc_init(DasDesc* pThis, desc_type_t type);
141
142
165DAS_API int DasDesc_info(
166 const DasDesc* pThis, char* sBuf, size_t uLen, const char* sIndent
167);
168
169/* Make an 'Unknown' type descriptor, incase you like using descriptor objects
170 * to store things in your code, not used by the library
171 * @memberof DasDesc
172 */
173DAS_API DasDesc* new_Descriptor(void);
174
180DAS_API void DasDesc_freeProps(DasDesc* pThis);
181
187DAS_API void DasDesc_clearProps(DasDesc* pThis);
188
202DAS_API bool DasDesc_equals(const DasDesc* pThis, const DasDesc* pOther);
203
215DAS_API const DasDesc* DasDesc_parent(const DasDesc* pThis);
216
234DAS_API size_t DasDesc_length(const DasDesc* pThis);
235
256DAS_API const DasProp* DasDesc_getPropByIdx(const DasDesc* pThis, size_t uIdx);
257
272DAS_API const char* DasDesc_getNameByIdx(const DasDesc* pThis, size_t uIdx);
273
288DAS_API const char* DasDesc_getValByIdx(const DasDesc* pThis, size_t uIdx);
289
293DAS_API const char* DasDesc_getTypeByIdx(const DasDesc* pThis, size_t uIdx);
294
295
299DAS_API const char* DasDesc_getTypeByIdx3(const DasDesc* pThis, size_t uIdx);
300
324 DasDesc* pThis, const char* sType, const char* sName, const char* sVal
325);
326
335 DasDesc* pThis, const char* sType, ubyte uType, const char* sName,
336 const char* sVal, char cSep, das_units units, int nStandard
337);
338
343DAS_API DasErrCode DasDesc_setProp(DasDesc* pThis, const DasProp* pProp);
344
349DAS_API const char* DasDesc_getType(const DasDesc* pThis, const char* sName);
350
359DAS_API das_units DasDesc_getUnits(const DasDesc* pThis, const char* sName);
360
366DAS_API const char* DasDesc_get(const DasDesc* pThis, const char* sName);
367
376DAS_API bool DasDesc_has(const DasDesc* pThis, const char* sName );
377
383DAS_API bool DasDesc_hasLocal(const DasDesc* pThis, const char* sName);
384
385
393DAS_API const DasProp* DasDesc_getProp(const DasDesc* pThis, const char* sName);
394
405DAS_API const DasProp* DasDesc_getLocal(const DasDesc* pThis, const char* sName);
406
416DAS_API bool DasDesc_remove(DasDesc* pThis, const char* sName);
417
421DAS_API const char* DasDesc_getStr(const DasDesc* pThis, const char* sName);
422
423
471DAS_API size_t DasDesc_getStrAry(
472 DasDesc* pThis, const char* sName, char* pBuf, size_t uBufSz,
473 char** psVals, size_t uMaxVals
474);
475
485DAS_API size_t DasDesc_getArray(
486 DasDesc* pThis, const char* sName, char cSep,
487 char* pBuf, size_t uBufSz, char** psVals, size_t uMaxVals
488);
489
490
497 DasDesc* pThis, const char* sName, const char* sVal
498);
499
504 DasDesc* pThis, const char* sName, const char* sFmt, ...
505);
506
507
512DAS_API double DasDesc_getDouble(const DasDesc* pThis, const char* sName);
513
518 DasDesc* pThis, const char* sName, double value
519);
520
535DAS_API double DasDesc_getDatum(
536 DasDesc* pThis, const char* sName, das_units units
537);
538
552 DasDesc* pThis, const char* sName, double rVal, das_units units
553);
554
574DAS_API double* DasDesc_getDoubleAry(
575 DasDesc* pThis, const char* sName, int* pNumItems
576);
577
582 DasDesc* pThis, const char* sName, int nItems, double* pValues
583);
584
595DAS_API int DasDesc_getInt(const DasDesc* pThis, const char* sName);
596
600DAS_API DasErrCode DasDesc_setInt(DasDesc* pThis, const char* sName, int nVal);
601
609DAS_API bool DasDesc_getBool(DasDesc* pThis, const char* sName);
610
618 DasDesc* pThis, const char* sName, bool bVal
619);
620
625 DasDesc* pThis, const char* sName, double beg, double end, das_units units
626);
627
636 DasDesc* pThis, const char* sName, char* sMin, char* sMax,
637 das_units* pUnits, size_t uLen
638);
639
645 DasDesc* pThis, const char* sName, int nItems, float* pValues
646);
647
653DAS_API void DasDesc_copyIn(DasDesc* pThis, const DasDesc* pOther);
654
664 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
665);
666
670 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
671);
672
680 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
681);
682
686DAS_API bool DasDesc_hasAnyProps(const DasDesc* pThis);
687
688
689
690/* * @} */
691
692#ifdef __cplusplus
693}
694#endif
695
696#endif /* _descriptor_h_ */
A dynamic buffer with multi-dimensional array style access.
Utility to assist with encode and decode operations.
DAS_API const DasProp * DasDesc_getLocal(const DasDesc *pThis, const char *sName)
Get a property if present in this descriptor only (das3)
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".
DAS_API const DasProp * DasDesc_getProp(const DasDesc *pThis, const char *sName)
Get a property if present in descriptor or it's parent (das3)
desc_type_t
enumeration of Descriptor types, used internally for type checking.
Definition descriptor.h:43
DAS_API DasErrCode DasDesc_encode3(DasDesc *pThis, DasBuf *pBuf, const char *sIndent)
Encode a generic set of properties to a buffer, in das3 format.
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 separator.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:189
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:141
Dynamic recursive ragged arrays.
Definition array.h:243
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 DasDesc * DasDesc_parent(const DasDesc *pThis)
The the parent of a Descriptor.
DAS_API das_units DasDesc_getUnits(const DasDesc *pThis, const char *sName)
Get the units of a property.
DAS_API const char * DasDesc_getValByIdx(const DasDesc *pThis, size_t uIdx)
Get a property value by an index.
DAS_API bool DasDesc_hasLocal(const DasDesc *pThis, const char *sName)
Does this descriptor alone have this property.
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 convention.
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 bool DasDesc_hasAnyProps(const DasDesc *pThis)
Does this descriptor hold at least one valid property?
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 void DasDesc_freeProps(DasDesc *pThis)
For use in derived destructors, frees the property array.
DAS_API double * DasDesc_getDoubleAry(DasDesc *pThis, const char *sName, int *pNumItems)
Get the values of an array property.
DAS_API int DasDesc_info(const DasDesc *pThis, char *sBuf, size_t uLen, const char *sIndent)
Print 1-line versions of each property in a descriptor.
DAS_API DasErrCode DasDesc_setProp(DasDesc *pThis, const DasProp *pProp)
Overwrite, or copy-in a fully formatted 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 const char * DasDesc_get(const DasDesc *pThis, const char *sName)
Get a raw property string.
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 void DasDesc_clearProps(DasDesc *pThis)
Resets the property count to 0, but frees no memory.
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_setInt(DasDesc *pThis, const char *sName, int nVal)
Set the property of type int.
DAS_API const char * DasDesc_getType(const DasDesc *pThis, const char *sName)
Get the type string for a property.
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 DasErrCode DasDesc_encode3Bare(DasDesc *pThis, DasBuf *pBuf, const char *sIndent)
Encode das3 properties WITHOUT the enclosing properties element.
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 descriptor.
Definition property.h:49
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...