das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
value.h
Go to the documentation of this file.
1/* Copyright (C) 2018 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#include <stdint.h>
21
22#include <das3/util.h>
23#include <das3/units.h> /* das_sem_default needs das_units to read calendar reps */
24
25#ifndef _das_value_h_
26#define _das_value_h_
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
37#define DAS_FILL_VALUE -1e31
38
40#define DAS_INT64_FILL -0x7FFFFFFFFFFFFFFFL
41#define DAS_INT32_FILL -0x7FFFFFFF
42
43
48typedef struct das_byte_seq_t{
49 ubyte* ptr;
50 size_t sz;
51} das_byte_seq;
52
53typedef struct das_const_byte_seq_t{
54 const ubyte* ptr;
55 size_t sz;
56} das_cbyte_seq;
57
59#define DAS_BS_NULL ((das_byte_seq){NULL, 0})
60#define DAS_CBS_NULL ((das_cbyte_seq){NULL, 0})
61
62
63#define VT_MIN_SIMPLE vtUByte
64#define VT_MAX_SIMPLE vtTime
65
66/* The types a das_datum stores in its own bytes, as against the ones it can
67 only box a pointer to. A contiguous range because the enum is ordered that
68 way on purpose: everything from vtText up reaches outside itself.
69 See das_datum_islocal() in datum.h. */
70#define VT_MIN_LOCAL vtUByte
71#define VT_MAX_LOCAL vtIndex
72
82typedef enum das_val_type_e {
83
87
90 /* VT_MIN_SIMPLE = vtUByte */
91
94
96 vtByte = 2,
97
100
103
106
108 vtInt = 6,
109
112
115
118
121
123 vtTime = 11,
124
125 /* VT_MAX_SIMPLE = vtTime */
126
127 /* The following type is not used by datums, but by array indexing elements
128 * that track the size and location of child dimensions */
129 vtIndex = 12,
130
131 /* The following two types are only used by variables and datums
132 *
133 * When generating Datums from Arrays:
134 *
135 * - If the array element type is etUnknown then vtByteSeq is used, size
136 * is element size.
137 *
138 * - If the array element type is etByte and the D2ARY_AS_STRING flag is
139 * set then vtText is used.
140 *
141 * - If the array element type is anything else and D2ARY_AS_SUBSEQ is
142 * set then vtByteSeq is used, size is element size times the size of
143 * the fastest moving index the location read.
144 */
145
148 vtText = 13,
149
151 /* Include later: vtPixel = 14, */
152
156
162 vtComposite = 16
163
165
166/* What one storage element of a composite value holds.
167 *
168 * This enum is a subset of what das_val_type can describe.
169 *
170 * Note there is no element for affine time. A TT2000 point-time is stored as a
171 * plain etLong, and the affine rule rides as a formalism in form.h, not as an
172 * element type. The bits of a time and a count are identical; only the
173 * composition rules differ, and rules are not storage. The one struct time
174 * that IS an element is etTime, the das_time broken-down calendar wart. */
175typedef enum das_elem_type_e {
176 etUnknown = 0, /* == vtUnknown */
177 etUByte = 1, /* == vtUByte, also the byte-run element of a <bytes> */
178 etByte = 2, /* == vtByte */
179 etUShort = 3, /* == vtUShort */
180 etShort = 4, /* == vtShort */
181 etUInt = 5, /* == vtUInt */
182 etInt = 6, /* == vtInt */
183 etULong = 7, /* == vtULong */
184 etLong = 8, /* == vtLong. a TT2000 point-time is stored here */
185 etFloat = 9, /* == vtFloat */
186 etDouble = 10, /* == vtDouble */
187 etTime = 11 /* == vtTime. das_time struct, broken-down-time wart */
188} das_elem_type;
189
192DAS_API bool das_elem_asDouble(das_elem_type et, const ubyte* p, double* pOut);
193
194
203DAS_API extern const char* DAS_ENC_BYTE;
204DAS_API extern const char* DAS_ENC_UBYTE;
205DAS_API extern const char* DAS_ENC_BEINT;
206DAS_API extern const char* DAS_ENC_BEUINT;
207DAS_API extern const char* DAS_ENC_BEREAL;
208DAS_API extern const char* DAS_ENC_LEINT;
209DAS_API extern const char* DAS_ENC_LEUINT;
210DAS_API extern const char* DAS_ENC_LEREAL;
211DAS_API extern const char* DAS_ENC_UTF8;
212DAS_API extern const char* DAS_ENC_BLOB;
213DAS_API extern const char* DAS_ENC_BASE64;
214
227DAS_API const char* das_enc_fromStr(const char* sEncType);
228
229
239DAS_API extern const char* DAS_SEM_BLOB;
240DAS_API extern const char* DAS_SEM_BOOL;
241DAS_API extern const char* DAS_SEM_DATE;
242DAS_API extern const char* DAS_SEM_INT;
243DAS_API extern const char* DAS_SEM_REAL;
244DAS_API extern const char* DAS_SEM_TEXT;
245
260DAS_API const char* das_sem_default(das_val_type vt, das_units units);
261
263DAS_API das_val_type das_vt_default(const char* sSemantic);
264
280DAS_API const char* das_sem_fromStr(const char* sSemantic);
281
306DAS_API das_val_type das_vt_store_type(
307 const char* sEncType, int nItemBytes, const char* sInterp
308);
309
313DAS_API const char* das_vt_serial_type(das_val_type et);
314
318#define das_vt_isint(VT) ( VT >= vtUByte && VT <= vtLong )
319
323#define das_vt_isreal(VT) ( VT == vtFloat || VT == vtDouble )
324
330#define das_vt_rank(VT) ( ((VT==vtText)||(VT==vtByteSeq)) ? 1:0)
331
332
339DAS_API const void* das_vt_fill(das_val_type vt);
340
345DAS_API size_t das_vt_size(das_val_type vt);
346
350DAS_API const char* das_vt_toStr(das_val_type vt);
351
355DAS_API das_val_type das_vt_fromStr(const char* sType);
356
357
358/* * Given a string and it's expected interpretation, return a suitable storage type
359 */
360/* DAS_API das_val_type das_vt_guess_store(const char* sInterp, const char* sValue); */
361
363typedef int (*das_valcmp_func)(const ubyte*, const ubyte*);
364
367
384 const ubyte* pA, das_val_type vtA, const ubyte* pB, das_val_type vtB
385);
386
387
388#define das_vt_cmpAny das_value_cmpAny
389
390/* In the future the token ID will come from the lexer, for now just make
391 * something up*/
392#define D2OP_PLUS 100
393
421
422#define DAS_VAL_NOERR_RNG 0x1
423#define DAS_VAL_ERR_RESLOSS 0x2
447 das_val_type vtIn, const ubyte* pValIn, const ubyte* pFillIn,
448 das_val_type vtOut, ubyte* pValOut, const ubyte* pFillOut,
449 uint32_t uFlags
450);
451
512DAS_API DasErrCode das_value_binop(
513 int nOp, das_val_type vtL, const ubyte* pL, das_val_type vtR,
514 const ubyte* pR, das_val_type vtOut, ubyte* pOut
515);
516
517DAS_API DasErrCode das_value_accum(
518 das_val_type vt, ubyte* pAccum, const ubyte* pStep, ptrdiff_t nCount
519);
520
539 char* sBuf, size_t uBufLen, das_val_type vt, const char* sSemantic, int nFitTo
540);
541
549DAS_API void das_value_trimReal(char* sVal);
550
558 ubyte* pBuf, int uBufLen, das_val_type vt, const char* sStr
559);
560
561
573DAS_API bool das_str2double(const char* str, double* pRes);
574
575
588DAS_API bool das_str2int(const char* str, int* pRes);
589
600DAS_API bool das_str2bool(const char* str, bool* pRes);
601
617DAS_API bool das_str2baseint(const char* str, int base, int* pRes);
618
641DAS_API bool das_strn2baseint(const char* str, int nLen, int base, int* pRes);
642
643/* Don't think these are used anywhere
644typedef struct das_real_array{
645 double* values;
646 size_t length;
647} das_real_array;
648
649typedef struct das_creal_array{
650 const double* values;
651 size_t length;
652} das_creal_array;
653
654typedef struct das_int_array{
655 int* values;
656 size_t length;
657} das_int_array;
658
659typedef struct das_cint_array{
660 const int* values;
661 size_t length;
662} das_cint_array;
663*/
664
672DAS_API double* das_csv2doubles(const char * s, int* nitems);
673
674
690DAS_API char* das_doubles2csv(char* pBuf, size_t uBufSz, const double* pValues, int nValues);
691
692
694DAS_API char* das_floats2csv(char* pBuf, size_t uBufSz, const float* pValues, int nValues);
695
696
697#ifdef __cplusplus
698}
699#endif
700
701#endif /* _das_value_h_ */
702
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:189
DAS_API const char * das_enc_fromStr(const char *sEncType)
Resolve a wire-encoding string to its canonical schema value.
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:141
DAS_API das_val_type das_vt_default(const char *sSemantic)
Given a semantic meaning, suggest a default value type.
DAS_API const char * das_sem_fromStr(const char *sSemantic)
Resolve a semantic string to its canonical schema value.
DAS_API const char * DAS_SEM_BLOB
Value meanings, which are a higher level concept then the plain storage information.
DAS_API const char * das_sem_default(das_val_type vt, das_units units)
Suggest a default semantic for a (value type, units) pair.
DAS_API const char * DAS_ENC_BYTE
The EncodingType pattern from das-basic-stream-v3.0.xsd namely: byte,ubyte,BEint,BEuint,...
das_val_type
Enumeration of value classes: what one whole externally indexable thing is – a number,...
Definition value.h:82
@ vtByte
Indicates array values are signed 8-bit integers (signed bytes)
Definition value.h:96
@ vtShort
Indicates array values are signed 16-bit integers (shorts)
Definition value.h:102
@ vtULong
Indicates array values are unsigned 64-bit unsigned integers (ulongs)
Definition value.h:111
@ vtFloat
Indicates array values are 32-bit floating point values (floats)
Definition value.h:117
@ vtInt
Indicates array values are signed 32-bit integers (ints)
Definition value.h:108
@ vtComposite
These values are run of simple elements plus the DasForm that says what they mean: a rotation,...
Definition value.h:162
@ vtUInt
Indicates array values are unsigned 32-bit integers (uints)
Definition value.h:105
@ vtLong
Indicates array values are unsigned 64-bit integers (longs)
Definition value.h:114
@ vtText
Indicates datum values are const char* pointers to null terminated UTF-8 strings.
Definition value.h:148
@ vtUByte
The basic types.
Definition value.h:93
@ vtUShort
Indicates array values are unsigned 16-bit integers (shorts)
Definition value.h:99
@ vtUnknown
For generic storage, designates elements as unknown, you have to cast the array return values yoursel...
Definition value.h:86
@ vtTime
Indicates array values are das_time_t structures.
Definition value.h:123
@ vtByteSeq
Values are a picture element, possibly in multiple planes.
Definition value.h:155
@ vtDouble
Indicates array values are 64-bit floating point values (doubles)
Definition value.h:120
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...
DAS_API bool das_str2bool(const char *str, bool *pRes)
Convert a string value to a boolean value.
DAS_API char * das_doubles2csv(char *pBuf, size_t uBufSz, const double *pValues, int nValues)
Print an array of doubles into a string buffer.
int(* das_valcmp_func)(const ubyte *, const ubyte *)
Comparison functions look like this.
Definition value.h:363
DAS_API DasErrCode das_value_fmt(char *sBuf, size_t uBufLen, das_val_type vt, const char *sSemantic, int nFitTo)
Generate a printf style format code for a value type, usage and buffer size.
DAS_API bool das_str2double(const char *str, double *pRes)
Convert a string value to a 8-byte float, similar to strtod(3).
DAS_API bool das_str2baseint(const char *str, int base, int *pRes)
Convert a string to an integer with explicit base and overflow checking.
DAS_API bool das_str2int(const char *str, int *pRes)
Convert the initial portion of a string to an integer with explicit over/underflow checks.
DAS_API DasErrCode das_value_fromStr(ubyte *pBuf, int uBufLen, das_val_type vt, const char *sStr)
Get a das value from a null terminated string.
DAS_API void das_value_trimReal(char *sVal)
Small helper for printing reals in less space.
DAS_API das_valcmp_func das_vt_getcmp(das_val_type vt)
Get the comparison function for two values of this type.
DAS_API char * das_floats2csv(char *pBuf, size_t uBufSz, const float *pValues, int nValues)
Similar to das_doubles2csv, but for 32-bit floats.
DAS_API int das_value_cmpAny(const ubyte *pA, das_val_type vtA, const ubyte *pB, das_val_type vtB)
Compare any two value types for equality.
DAS_API das_val_type das_vt_merge(das_val_type right, int op, das_val_type left)
What would be the resulting type given an operation on the given value type.
DAS_API DasErrCode das_value_binXform(das_val_type vtIn, const ubyte *pValIn, const ubyte *pFillIn, das_val_type vtOut, ubyte *pValOut, const ubyte *pFillOut, uint32_t uFlags)
Convert any integral type to any other with range checking and swapping.
DAS_API double * das_csv2doubles(const char *s, int *nitems)
Parse a comma separated list of ASCII values into a double array.
DAS_API bool das_strn2baseint(const char *str, int nLen, int base, int *pRes)
Convert an explicit length string to an integer with explicit base with over/underflow checks.