summaryrefslogtreecommitdiff
path: root/external/mit/libcbor/dist/src/cbor/floats_ctrls.h
blob: 83cb75acd6eb37067d3015f9309ae1e3045b0244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
 *
 * libcbor is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#ifndef LIBCBOR_FLOATS_CTRLS_H
#define LIBCBOR_FLOATS_CTRLS_H

#include "cbor/common.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * ============================================================================
 * Float manipulation
 * ============================================================================
 */

/** Is this a ctrl value?
 *
 * @param item[borrow] A float or ctrl item
 * @return Is this a ctrl value?
 */
bool cbor_float_ctrl_is_ctrl(const cbor_item_t *item);

/** Get the float width
 *
 * @param item[borrow] A float or ctrl item
 * @return The width.
 */
cbor_float_width cbor_float_get_width(const cbor_item_t *item);

/** Get a half precision float
 *
 * The item must have the corresponding width
 *
 * @param[borrow] A half precision float
 * @return half precision value
 */
float cbor_float_get_float2(const cbor_item_t *item);

/** Get a single precision float
 *
 * The item must have the corresponding width
 *
 * @param[borrow] A signle precision float
 * @return single precision value
 */
float cbor_float_get_float4(const cbor_item_t *item);

/** Get a double precision float
 *
 * The item must have the corresponding width
 *
 * @param[borrow] A double precision float
 * @return double precision value
 */
double cbor_float_get_float8(const cbor_item_t *item);

/** Get the float value represented as double
 *
 * Can be used regardless of the width.
 *
 * @param[borrow] Any float
 * @return double precision value
 */
double cbor_float_get_float(const cbor_item_t *item);

/** Constructs a new ctrl item
 *
 * The width cannot be changed once the item is created
 *
 * @return **new** 1B ctrl or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_ctrl();

/** Constructs a new float item
 *
 * The width cannot be changed once the item is created
 *
 * @return **new** 2B float or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_float2();

/** Constructs a new float item
 *
 * The width cannot be changed once the item is created
 *
 * @return **new** 4B float or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_float4();

/** Constructs a new float item
 *
 * The width cannot be changed once the item is created
 *
 * @return **new** 8B float or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_float8();

/** Constructs new null ctrl item
 *
 * @return **new** null ctrl item or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_null();

/** Constructs new undef ctrl item
 *
 * @return **new** undef ctrl item or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_new_undef();

/** Constructs new boolean ctrl item
 *
 * @param value The value to use
 * @return **new** boolen ctrl item or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_build_bool(bool value);

/** Assign a control value
 *
 * \rst
 * .. warning:: It is possible to produce an invalid CBOR value by assigning a
 * invalid value using this mechanism. Please consult the standard before use.
 * \endrst
 *
 * @param item[borrow] A ctrl item
 * @param value The simple value to assign. Please consult the standard for
 * 	allowed values
 */
void cbor_set_ctrl(cbor_item_t *item, uint8_t value);

/** Assigns a float value
 *
 * @param item[borrow] A half precision float
 * @param value The value to assign
 */
void cbor_set_float2(cbor_item_t *item, float value);

/** Assigns a float value
 *
 * @param item[borrow] A single precision float
 * @param value The value to assign
 */
void cbor_set_float4(cbor_item_t *item, float value);

/** Assigns a float value
 *
 * @param item[borrow] A double precision float
 * @param value The value to assign
 */
void cbor_set_float8(cbor_item_t *item, double value);

/** Reads the control value
 *
 * @param item[borrow] A ctrl item
 * @return the simple value
 */
uint8_t cbor_ctrl_value(const cbor_item_t *item);

/** Is this ctrl item a boolean?
 *
 * @param item[borrow] A ctrl item
 * @return Is this ctrl item a boolean?
 */
bool cbor_ctrl_is_bool(const cbor_item_t *item);

/** Constructs a new float
 *
 * @param value the value to use
 * @return **new** float
 */
cbor_item_t *cbor_build_float2(float value);

/** Constructs a new float
 *
 * @param value the value to use
 * @return **new** float or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_build_float4(float value);

/** Constructs a new float
 *
 * @param value the value to use
 * @return **new** float or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_build_float8(double value);

/** Constructs a ctrl item
 *
 * @param value the value to use
 * @return **new** ctrl item or `NULL` upon memory allocation failure
 */
cbor_item_t *cbor_build_ctrl(uint8_t value);

#ifdef __cplusplus
}
#endif

#endif  // LIBCBOR_FLOATS_CTRLS_H