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, CONTEXT=16000,
49
50
51DAS_API const char* das_desc_type_str(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, ::StreamDesc, ::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
136DAS_API void DasDesc_init(DasDesc* pThis, desc_type_t type);
137
138
143DAS_API char* DasDesc_info(const DasDesc* pThis, char* sBuf, int nLen, char* sIndent);
144
145/* Make an 'Unknown' type descriptor, incase you like using descriptor objects
146 * to store things in your code, not used by the library
147 * @memberof DasDesc
148 */
149DAS_API DasDesc* new_Descriptor(void);
150
156DAS_API void DasDesc_freeProps(DasDesc* pThis);
157
163DAS_API void DasDesc_clearProps(DasDesc* pThis);
164
178DAS_API bool DasDesc_equals(const DasDesc* pThis, const DasDesc* pOther);
179
191DAS_API const DasDesc* DasDesc_parent(const DasDesc* pThis);
192
210DAS_API size_t DasDesc_length(const DasDesc* pThis);
211
232DAS_API const DasProp* DasDesc_getPropByIdx(const DasDesc* pThis, size_t uIdx);
233
248DAS_API const char* DasDesc_getNameByIdx(const DasDesc* pThis, size_t uIdx);
249
264DAS_API const char* DasDesc_getValByIdx(const DasDesc* pThis, size_t uIdx);
265
269DAS_API const char* DasDesc_getTypeByIdx(const DasDesc* pThis, size_t uIdx);
270
271
275DAS_API const char* DasDesc_getTypeByIdx3(const DasDesc* pThis, size_t uIdx);
276
300 DasDesc* pThis, const char* sType, const char* sName, const char* sVal
301);
302
311 DasDesc* pThis, const char* sType, ubyte uType, const char* sName,
312 const char* sVal, char cSep, das_units units, int nStandard
313);
314
319DAS_API DasErrCode DasDesc_setProp(DasDesc* pThis, const DasProp* pProp);
320
325DAS_API const char* DasDesc_getType(const DasDesc* pThis, const char* sName);
326
332DAS_API const char* DasDesc_get(const DasDesc* pThis, const char* sName);
333
342DAS_API bool DasDesc_has(const DasDesc* pThis, const char* sName );
343
349DAS_API bool DasDesc_hasLocal(const DasDesc* pThis, const char* sName);
350
351
359DAS_API const DasProp* DasDesc_getProp(const DasDesc* pThis, const char* sName);
360
371DAS_API const DasProp* DasDesc_getLocal(const DasDesc* pThis, const char* sName);
372
382DAS_API bool DasDesc_remove(DasDesc* pThis, const char* sName);
383
387DAS_API const char* DasDesc_getStr(const DasDesc* pThis, const char* sName);
388
389
437DAS_API size_t DasDesc_getStrAry(
438 DasDesc* pThis, const char* sName, char* pBuf, size_t uBufSz,
439 char** psVals, size_t uMaxVals
440);
441
451DAS_API size_t DasDesc_getArray(
452 DasDesc* pThis, const char* sName, char cSep,
453 char* pBuf, size_t uBufSz, char** psVals, size_t uMaxVals
454);
455
456
463 DasDesc* pThis, const char* sName, const char* sVal
464);
465
470 DasDesc* pThis, const char* sName, const char* sFmt, ...
471);
472
473
478DAS_API double DasDesc_getDouble(const DasDesc* pThis, const char* sName);
479
484 DasDesc* pThis, const char* sName, double value
485);
486
501DAS_API double DasDesc_getDatum(
502 DasDesc* pThis, const char* sName, das_units units
503);
504
518 DasDesc* pThis, const char* sName, double rVal, das_units units
519);
520
540DAS_API double* DasDesc_getDoubleAry(
541 DasDesc* pThis, const char* sName, int* pNumItems
542);
543
548 DasDesc* pThis, const char* sName, int nItems, double* pValues
549);
550
561DAS_API int DasDesc_getInt(const DasDesc* pThis, const char* sName);
562
566DAS_API DasErrCode DasDesc_setInt(DasDesc* pThis, const char* sName, int nVal);
567
575DAS_API bool DasDesc_getBool(DasDesc* pThis, const char* sName);
576
584 DasDesc* pThis, const char* sName, bool bVal
585);
586
591 DasDesc* pThis, const char* sName, double beg, double end, das_units units
592);
593
602 DasDesc* pThis, const char* sName, char* sMin, char* sMax,
603 das_units* pUnits, size_t uLen
604);
605
611 DasDesc* pThis, const char* sName, int nItems, float* pValues
612);
613
619DAS_API void DasDesc_copyIn(DasDesc* pThis, const DasDesc* pOther);
620
621/* New lib is source compatible, not binary compatible */
622#define DasDesc_encode DasDesc_encode2
623
633 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
634);
635
639 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
640);
641
649 DasDesc* pThis, DasBuf* pBuf, const char* sIndent
650);
651
655DAS_API bool DasDesc_hasAnyProps(const DasDesc* pThis);
656
657
658
659/* * @} */
660
661#ifdef __cplusplus
662}
663#endif
664
665#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:184
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:144
Dynamic recursive ragged arrays.
Definition array.h:271
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 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 char * DasDesc_info(const DasDesc *pThis, char *sBuf, int nLen, char *sIndent)
Print 1-line versions of each property in a descriptor.
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 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...