1 module deimos.cbor.floats_ctrls;
2 
3 import deimos.cbor.data;
4 
5 /*
6  * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
7  *
8  * libcbor is free software; you can redistribute it and/or modify
9  * it under the terms of the MIT license. See LICENSE for details.
10  */
11 
12 extern (C):
13 
14 /*
15  * ============================================================================
16  * Float manipulation
17  * ============================================================================
18  */
19 
20 /** Is this a ctrl value?
21  *
22  * @param item[borrow] A float or ctrl item
23  * @return Is this a ctrl value?
24  */
25 bool cbor_float_ctrl_is_ctrl(const cbor_item_t* item);
26 
27 /** Get the float width
28  *
29  * @param item[borrow] A float or ctrl item
30  * @return The width.
31  */
32 cbor_float_width cbor_float_get_width(const cbor_item_t* item);
33 
34 /** Get a half precision float
35  *
36  * The item must have the corresponding width
37  *
38  * @param[borrow] A half precision float
39  * @return half precision value
40  */
41 float cbor_float_get_float2(const cbor_item_t* item);
42 
43 /** Get a single precision float
44  *
45  * The item must have the corresponding width
46  *
47  * @param[borrow] A signle precision float
48  * @return single precision value
49  */
50 float cbor_float_get_float4(const cbor_item_t* item);
51 
52 /** Get a double precision float
53  *
54  * The item must have the corresponding width
55  *
56  * @param[borrow] A double precision float
57  * @return double precision value
58  */
59 double cbor_float_get_float8(const cbor_item_t* item);
60 
61 /** Get the float value represented as double
62  *
63  * Can be used regardless of the width.
64  *
65  * @param[borrow] Any float
66  * @return double precision value
67  */
68 double cbor_float_get_float(const cbor_item_t* item);
69 
70 /** Constructs a new ctrl item
71  *
72  * The width cannot be changed once the item is created
73  *
74  * @return **new** 1B ctrl or `NULL` upon memory allocation failure
75  */
76 cbor_item_t* cbor_new_ctrl();
77 
78 /** Constructs a new float item
79  *
80  * The width cannot be changed once the item is created
81  *
82  * @return **new** 2B float or `NULL` upon memory allocation failure
83  */
84 cbor_item_t* cbor_new_float2();
85 
86 /** Constructs a new float item
87  *
88  * The width cannot be changed once the item is created
89  *
90  * @return **new** 4B float or `NULL` upon memory allocation failure
91  */
92 cbor_item_t* cbor_new_float4();
93 
94 /** Constructs a new float item
95  *
96  * The width cannot be changed once the item is created
97  *
98  * @return **new** 8B float or `NULL` upon memory allocation failure
99  */
100 cbor_item_t* cbor_new_float8();
101 
102 /** Constructs new null ctrl item
103  *
104  * @return **new** null ctrl item or `NULL` upon memory allocation failure
105  */
106 cbor_item_t* cbor_new_null();
107 
108 /** Constructs new undef ctrl item
109  *
110  * @return **new** undef ctrl item or `NULL` upon memory allocation failure
111  */
112 cbor_item_t* cbor_new_undef();
113 
114 /** Constructs new boolean ctrl item
115  *
116  * @param value The value to use
117  * @return **new** boolen ctrl item or `NULL` upon memory allocation failure
118  */
119 cbor_item_t* cbor_build_bool(bool value);
120 
121 /** Assign a control value
122  *
123  * \rst
124  * .. warning:: It is possible to produce an invalid CBOR value by assigning a
125  * invalid value using this mechanism. Please consult the standard before use.
126  * \endrst
127  *
128  * @param item[borrow] A ctrl item
129  * @param value The simple value to assign. Please consult the standard for
130  *      allowed values
131  */
132 void cbor_set_ctrl(cbor_item_t* item, ubyte value);
133 
134 /** Assigns a float value
135  *
136  * @param item[borrow] A half precision float
137  * @param value The value to assign
138  */
139 void cbor_set_float2(cbor_item_t* item, float value);
140 
141 /** Assigns a float value
142  *
143  * @param item[borrow] A single precision float
144  * @param value The value to assign
145  */
146 void cbor_set_float4(cbor_item_t* item, float value);
147 
148 /** Assigns a float value
149  *
150  * @param item[borrow] A double precision float
151  * @param value The value to assign
152  */
153 void cbor_set_float8(cbor_item_t* item, double value);
154 
155 /** Reads the control value
156  *
157  * @param item[borrow] A ctrl item
158  * @return the simple value
159  */
160 ubyte cbor_ctrl_value(const cbor_item_t* item);
161 
162 /** Is this ctrl item a boolean?
163  *
164  * @param item[borrow] A ctrl item
165  * @return Is this ctrl item a boolean?
166  */
167 bool cbor_ctrl_is_bool(const cbor_item_t* item);
168 
169 /** Constructs a new float
170  *
171  * @param value the value to use
172  * @return **new** float
173  */
174 cbor_item_t* cbor_build_float2(float value);
175 
176 /** Constructs a new float
177  *
178  * @param value the value to use
179  * @return **new** float or `NULL` upon memory allocation failure
180  */
181 cbor_item_t* cbor_build_float4(float value);
182 
183 /** Constructs a new float
184  *
185  * @param value the value to use
186  * @return **new** float or `NULL` upon memory allocation failure
187  */
188 cbor_item_t* cbor_build_float8(double value);
189 
190 /** Constructs a ctrl item
191  *
192  * @param value the value to use
193  * @return **new** ctrl item or `NULL` upon memory allocation failure
194  */
195 cbor_item_t* cbor_build_ctrl(ubyte value);