libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 libdas2, the Core Das2 C Library.
4  *
5  * Libdas2 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  * Libdas2 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 libdas2; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
20 #include <stdint.h>
21 
22 #ifndef _das_value_h_
23 #define _das_value_h_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 #define DAS_FILL_VALUE -1e31
35 
37 #define DAS_INT64_FILL -0x7FFFFFFFFFFFFFFFL
38 #define DAS_INT32_FILL -0x7FFFFFFF
39 
40 
45 typedef uint8_t byte;
46 
51 typedef enum das_val_type {
54  vtUnknown = 0,
55 
56  /* The following type is not used by datums, but by array indexing elements
57  * that track the size and location of child dimensions */
58  vtIndex,
59 
76 
77  /* The following two types are only used by datums, not arrays.
78  *
79  * When generating Datums from Arrays:
80  *
81  * - If the array element type is etUnknown then etByteSeq is used, size
82  * is element size.
83  *
84  * - If the array element type is etByte and the D2ARY_AS_STRING flag is
85  * set then etText is used.
86  *
87  * - If the array element type is anything else and D2ARY_AS_SUBSEQ is
88  * set then etByteSeq is used, size is element size times the size of
89  * the fastest moving index the location read.
90  */
91 
95 
99 
100 } das_val_type;
101 
102 
107 const void* das_vt_fill(das_val_type vt);
108 
110 size_t das_vt_size(das_val_type vt);
111 
113 const char* das_vt_toStr(das_val_type vt);
114 
116 typedef int (*das_valcmp_func)(const void*, const void*);
117 
120 
121 /* In the future the token ID will come from the lexer, for now just make
122  * something up*/
123 #define D2OP_PLUS 100
124 
152 
153 
165 bool das_str2double(const char* str, double* pRes);
166 
167 
180 bool das_str2int(const char* str, int* pRes);
181 
192 bool das_str2bool(const char* str, bool* pRes);
193 
209 bool das_str2baseint(const char* str, int base, int* pRes);
210 
233 bool das_strn2baseint(const char* str, int nLen, int base, int* pRes);
234 
235 /* Don't think these are used anywhere
236 typedef struct das_real_array{
237  double* values;
238  size_t length;
239 } das_real_array;
240 
241 typedef struct das_creal_array{
242  const double* values;
243  size_t length;
244 } das_creal_array;
245 
246 typedef struct das_int_array{
247  int* values;
248  size_t length;
249 } das_int_array;
250 
251 typedef struct das_cint_array{
252  const int* values;
253  size_t length;
254 } das_cint_array;
255 */
256 
264 double* das_csv2doubles(const char * s, int* nitems);
265 
266 
281 char* das_doubles2csv( char * buf, const double * value, int nitems );
282 
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif /* _das_value_h_ */
291 
int(* das_valcmp_func)(const void *, const void *)
Comparison functions look like this.
Definition: value.h:116
Indicates array values are unsigned 8-bit unsigned integers (bytes)
Definition: value.h:61
Indicates array values are signed 64-bit integers (longs)
Definition: value.h:69
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_val_type
Enumeration of types stored in Das Array (DasAry) objects Not that any kind of value may be stored in...
Definition: value.h:51
bool das_str2bool(const char *str, bool *pRes)
Convert a string value to a boolean value.
double * das_csv2doubles(const char *s, int *nitems)
Parse a comma separated list of ASCII values into a double array.
Indicates array values are das_time_t structures.
Definition: value.h:75
Indicates datum values are size_t plus const byte* pairs, no more is known about the bytes...
Definition: value.h:98
bool das_str2double(const char *str, double *pRes)
Convert a string value to a 8-byte float, similar to strtod(3).
Indicates array values are signed 16-bit integers (shorts)
Definition: value.h:65
For generic storage, designates elements as unknown, you have to cast the array return values yoursel...
Definition: value.h:54
bool das_str2baseint(const char *str, int base, int *pRes)
Convert a string to an integer with explicit base and overflow checking.
const char * das_vt_toStr(das_val_type vt)
Get a text string representation of an element type.
Indicates array values are 64-bit floating point values (doubles)
Definition: value.h:73
Indicates datum values are const char* pointers to null terminated UTF-8 strings. ...
Definition: value.h:94
const void * das_vt_fill(das_val_type vt)
Get the default fill value for a given element type.
das_valcmp_func das_vt_getcmp(das_val_type vt)
Get the comparison function for two values of this type.
size_t das_vt_size(das_val_type vt)
Get the size in bytes for a given element type.
Indicates array values are signed 32-bit integers (ints)
Definition: value.h:67
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...
Indicates array values are unsigned 16-bit integers (shorts)
Definition: value.h:63
Indicates array values are 32-bit floating point values (floats)
Definition: value.h:71
char * das_doubles2csv(char *buf, const double *value, int nitems)
Print an array of doubles into a string buffer.
bool das_str2int(const char *str, int *pRes)
Convert the initial portion of a string to an integer with explicit over/underflow checks...