das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
property.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * This file is part of das2C, the Core Das2 C Library.
4 *
5 * Das2C is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 2.1 as published
7 * by the Free Software Foundation.
8 *
9 * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
20#ifndef _property_h_
21#define _property_h_
22
23#include <das3/defs.h>
24#include <das3/units.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
49typedef struct das_prop {
50 uint64_t flags; // property type, validity, value offset
51 das_units units; // Units, if any
52 char buffer[16]; // A buffer for the property name and value,
53 // typically over-malloc'ed.
54} DasProp;
55
62size_t dasprop_memsz(const char* sName, const char* sValue);
63
110 ubyte* pBuf, size_t uBufSz, const char* sType, ubyte uType, const char* sName,
111 const char* sValue, char cSep, das_units units, int nStandard
112);
113
117size_t DasProp_size(const DasProp* pProp);
118
120#define DasProp_units(P) ((P)->units)
121
125#define DasProp_name(P) ((P)->buffer)
126
127/* const char* DasProp_name(const DasProp* pProp); */
128
132const char* DasProp_value(const DasProp* pProp);
133
140size_t DasProp_escapeSize(const DasProp* pProp);
141
158const char* DasProp_xmlValue(const DasProp* pProp, char* sBuf, size_t uLen);
159
160/*
161/ * Get a sub value for a multivalued property.
162 *
163 * If DasProp_isSet() or DasProp_isRange() returns true, then this property
164 * has sub values.
165 *
166 * @param pProp The property in question
167 *
168 * @param idx The index of the sub property, index 0 should always be defined.
169 *
170 * @param sBuf A buffer to receive the value.
171 *
172 * @param nLen The length of the buffer to receive the value. Up to nLen - 1
173 * bytes will be copied in, then a null is appended. Output should
174 * always be null terminated even if there wasn't enough room for the
175 * entire sub-value.
176 *
177 * @returns The number of bytes needed to store the sub value along with it's
178 * terminating null. If this is greater then nLen, then the output
179 * has been truncated.
180 * /
181bool DasProp_subValue(const DasProp* pProp, int idx, char* sBuf, size_t nLen);
182*/
183
187char DasProp_sep(const DasProp* pProp);
188
189/* Decode an |Hx| property-value separator (possibly a backslash escape: \n \t
190 * \r \\‍) to a single byte. Empty/NULL -> '\0' so callers fall back to guessing.
191 * 0x00 is not representable here -- property values are string-typed, so the
192 * larger |Pd| packet-separator set (which can carry 0x00) needs its own decoder.
193 * Free function (no DasProp receiver), hence the lowercase name (cf dasprop_memsz). */
194char dasprop_unescapeSep(const char* sSep);
195
199bool DasProp_equal(const DasProp* pOne, const DasProp* pTwo);
200
204const char* DasProp_typeStr2(const DasProp* pProp);
205
209const char* DasProp_typeStr3(const DasProp* pProp);
210
217int DasProp_convertInt(const DasProp* pProp, int64_t* pBuf, size_t uBufLen);
218
225int DasProp_convertReal(const DasProp* pProp, double* pBuf, size_t uBufLen);
226
233int DasProp_convertBool(const DasProp* pProp, uint8_t* pBuf, size_t uBufLen);
234
241int DasProp_convertTt2k(const DasProp* pProp, int64_t* pBuf, size_t uBufLen);
242
246int DasProp_convertTime(const DasProp* pProp, uint64_t* pBuf, size_t uBufLen);
247
254int DasProp_extractItems(const DasProp* pProp, char** psBuf, size_t uNumStrs, size_t uLenEa);
255
256
263ubyte DasProp_type(const DasProp* pProp);
264
270
274bool DasProp_isValid(const DasProp* pProp);
275
279int DasProp_items(const DasProp* pProp);
280
284#define DASPROP_MULTI_MASK 0x00000003
285
286#define DASPROP_VALID_MASK 0x00000003 // If these bits are 0, the property
287
288#define DASPROP_INVALID 0x00000000 // is invalid, ignore it.
289#define DASPROP_SINGLE 0x00000001
290#define DASPROP_RANGE 0x00000002
291#define DASPROP_SET 0x00000003
292
296#define DASPROP_TYPE_MASK 0x000000F0
297
298#define DASPROP_STRING 0x00000010
299#define DASPROP_BOOL 0x00000020
300#define DASPROP_INT 0x00000030
301#define DASPROP_REAL 0x00000040
302#define DASPROP_DATETIME 0x00000050
303
304#define DASPROP_DAS1 1
305#define DASPROP_DAS2 2
306#define DASPROP_DAS3 3
307
311#define DasProp_isType(P,T) ((P->flags & DASPROP_TYPE_MASK) == T)
312
316#define DasProp_isRange(P) ((P->flags & DASPROP_RANGE)==DASPROP_RANGE)
317
323#define DasProp_isSet(P) ((P->flags & DASPROP_SET)==DASPROP_SET)
324
325#ifdef __cplusplus
326}
327#endif
328
329#endif // _property_h_
Minimal definitions for das2 utilities that can safely be run without calling das_init().
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
size_t dasprop_memsz(const char *sName, const char *sValue)
Get required storage space for a property given a name and value.
Individual properties of a descriptor.
Definition property.h:49
int DasProp_convertReal(const DasProp *pProp, double *pBuf, size_t uBufLen)
Convert real-value properties to double.
int DasProp_convertInt(const DasProp *pProp, int64_t *pBuf, size_t uBufLen)
Convert integer property values to 64-bit ints.
DasErrCode DasProp_init(ubyte *pBuf, size_t uBufSz, const char *sType, ubyte uType, const char *sName, const char *sValue, char cSep, das_units units, int nStandard)
Flexible das1, das2 and das3 compatible property memory initializer.
bool DasProp_isValid(const DasProp *pProp)
Determine if this property has a valid type definition.
const char * DasProp_typeStr3(const DasProp *pProp)
Get a das3 type string for this property.
const char * DasProp_xmlValue(const DasProp *pProp, char *sBuf, size_t uLen)
Get the string value for a property with illegal XML characters escaped.
size_t DasProp_size(const DasProp *pProp)
Return the memory footprint of a property.
int DasProp_convertTime(const DasProp *pProp, uint64_t *pBuf, size_t uBufLen)
Convert datatime properties to a double based value of units.
int DasProp_items(const DasProp *pProp)
Determine the number of items in a multi valued property.
void DasProp_invalidate(DasProp *pProp)
Mark this property as invalid, this erases the type information and is thus a non-reversible operatio...
size_t DasProp_escapeSize(const DasProp *pProp)
Get the size of needed escape buffer if property contains illegal XML chars.
int DasProp_convertTt2k(const DasProp *pProp, int64_t *pBuf, size_t uBufLen)
Convert datatime properties TT2K long integers.
int DasProp_convertBool(const DasProp *pProp, uint8_t *pBuf, size_t uBufLen)
Convert boolean property values to bytes.
const char * DasProp_typeStr2(const DasProp *pProp)
Get a das2 type string for this property
char DasProp_sep(const DasProp *pProp)
Get the value separator character for array-style properties.
bool DasProp_equal(const DasProp *pOne, const DasProp *pTwo)
Determine if two properties contain equal content.
int DasProp_extractItems(const DasProp *pProp, char **psBuf, size_t uNumStrs, size_t uLenEa)
Just extract the property strings, don't convert anything.
const char * DasProp_value(const DasProp *pProp)
Get the string value for a property.
ubyte DasProp_type(const DasProp *pProp)
Get a property type code.
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...