das2C
das core C utilities (v3)
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 <das2/defs.h>
24 #include <das2/units.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
49 typedef 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 
62 size_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 
117 size_t DasProp_size(const DasProp* pProp);
118 
122 const char* DasProp_name(const DasProp* pProp);
123 
127 const char* DasProp_value(const DasProp* pProp);
128 
132 char DasProp_sep(const DasProp* pProp);
133 
137 bool DasProp_equal(const DasProp* pOne, const DasProp* pTwo);
138 
142 const char* DasProp_typeStr2(const DasProp* pProp);
143 
147 const char* DasProp_typeStr3(const DasProp* pProp);
148 
155 int DasProp_convertInt(const DasProp* pProp, int64_t* pBuf, size_t uBufLen);
156 
163 int DasProp_convertReal(const DasProp* pProp, double* pBuf, size_t uBufLen);
164 
171 int DasProp_convertBool(const DasProp* pProp, uint8_t* pBuf, size_t uBufLen);
172 
176 int DasProp_convertTt2k(const DasProp* pProp, int64_t* pBuf, size_t uBufLen);
177 
181 int DasProp_convertTime(const DasProp* pProp, uint64_t* pBuf, size_t uBufLen);
182 
189 ubyte DasProp_type(const DasProp* pProp);
190 
196 
200 bool DasProp_isValid(const DasProp* pProp);
201 
205 int DasProp_items(const DasProp* pProp);
206 
210 #define DASPROP_MULTI_MASK 0x00000003
211 
212 #define DASPROP_VALID_MASK 0x00000003 // If these bits are 0, the property
213 
214 #define DASPROP_INVALID 0x00000000 // is invalid, ignore it.
215 #define DASPROP_SINGLE 0x00000001
216 #define DASPROP_RANGE 0x00000002
217 #define DASPROP_SET 0x00000003
218 
222 #define DASPROP_TYPE_MASK 0x000000F0
223 
224 #define DASPROP_STRING 0x00000010
225 #define DASPROP_BOOL 0x00000020
226 #define DASPROP_INT 0x00000030
227 #define DASPROP_REAL 0x00000040
228 #define DASPROP_DATETIME 0x00000050
229 
230 #define DASPROP_DAS1 1
231 #define DASPROP_DAS2 2
232 #define DASPROP_DAS3 3
233 
237 #define DasProp_isRange(P) (P->flags & DASPROP_RANGE)
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #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:164
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
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 desciptor.
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 compatable 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.
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-reversable operatio...
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.
const char * DasProp_name(const DasProp *pProp)
Get name of a property.
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...