das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
datum.h
Go to the documentation of this file.
1/* Copyright (C) 2017 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 _das_datum_h_
21#define _das_datum_h_
22
23#include <das3/value.h>
24#include <das3/units.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* Sized for the largest value that lives inline: a das_time.
31 A composite objects point to external data, and the object needed
32 to interpret them */
33#define DATUM_BUF_SZ 32
34
77struct das_form; /* opaque here; datum.c never dereferences one */
78
79/* The vtComposite box -- its struct and its bit layout -- is private to
80 datum.c. Unlike a das_time or a double, which a caller may reasonably cast
81 a datum pointer to, a composite is not a value you read by looking at it:
82 the extents live in two places depending on size, and the run belongs to
83 whoever supplied it. Use the accessors below. Nothing is lost by hiding
84 it and the representation stays free to change. */
85
86
87typedef struct datum_t {
88 ubyte bytes[DATUM_BUF_SZ]; /* 32 bytes of space */
89 das_val_type vt;
90 uint32_t vsize;
91 das_units units;
92} das_datum;
93
112DAS_API void das_datum_init(
113 das_datum* pThis, const ubyte* pSrc, das_val_type vt, uint32_t vsize,
114 das_units units
115);
116
120DAS_API das_val_type das_datum_elemType(const das_datum* pThis);
121
136DAS_API bool das_datum_box(
137 das_datum* pThis, const struct das_form* pForm, const ubyte* pRun,
138 int nRank, const ptrdiff_t* pShape, das_val_type et, das_units units
139);
140
143DAS_API const struct das_form* das_datum_form(const das_datum* pThis);
144
148DAS_API const ubyte* das_datum_run(const das_datum* pThis);
149
170DAS_API int das_datum_shape(const das_datum* pThis, ptrdiff_t* pShape);
171
175DAS_API size_t das_datum_nElems(const das_datum* pThis);
176
185DAS_API size_t das_datum_runBytes(const das_datum* pThis);
186
199#define das_datum_valid(p) ((p)->vsize > 0)
200
216#define das_datum_islocal(p) \
217 ( ((p)->vt >= VT_MIN_LOCAL) && ((p)->vt <= VT_MAX_LOCAL) )
218
219
231DAS_API bool das_datum_fromStr(das_datum* pThis, const char* sStr);
232
243DAS_API bool das_datum_fromDbl(das_datum* pThis, double value, das_units units);
244
265DAS_API bool das_datum_wrapStr(das_datum* pTHis, const char* sStr, das_units units);
266
267
274DAS_API bool das_datum_byteSeq(
275 das_datum* pThis, das_cbyte_seq seq, das_units units
276);
277
302DAS_API char* das_datum_toStr(
303 const das_datum* pThis, char* sStr, size_t uLen, int nFracDigits
304);
305
311DAS_API char* das_datum_toStrValOnly(
312 const das_datum* pThis, char* sStr, size_t uLen, int nFracDigits
313);
314
318 const das_datum* pThis, char* sStr, size_t uLen, int nFracDigits,
319 const char* sSep
320);
321
322
334DAS_API bool das_datum_toDbl(const das_datum* pThis, double* pOut);
335
353DAS_API int das_datum_toDoubles(
354 const das_datum* pThis, double* pOut, int nMax
355);
356
357
372DAS_API bool das_datum_toEpoch(
373 const das_datum* pThis, das_units epoch, double* pResult
374);
375
387DAS_API bool das_datum_toTime(const das_datum* pThis, das_time* pDt);
388
389
394#define das_datum_asStr(dm) *((char**)&dm)
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif /* _das_datum_h_ */
DAS_API void das_datum_init(das_datum *pThis, const ubyte *pSrc, das_val_type vt, uint32_t vsize, das_units units)
General datum initialization.
char * das_datum_toStrValOnlySep(const das_datum *pThis, char *sStr, size_t uLen, int nFracDigits, const char *sSep)
Similar to das_datum_toStr, but can specify a separator for vectors.
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:144
das_val_type
Enumeration of types stored in Das Array (DasAry) objects from value.h.
Definition value.h:81
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition time.h:43
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...
A generic value type for use in arrays, datums and variables.