yumapro  20.10-12
YumaPro SDK
ncx_num.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4  *
5  * Unless required by applicable law or agreed to in writing,
6  * software distributed under the License is distributed on an
7  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations
10  * under the License.
11  */
12 #ifndef _H_ncx_num
13 #define _H_ncx_num
14 
15 /* FILE: ncx_num.h
16 *********************************************************************
17 * *
18 * P U R P O S E *
19 * *
20 *********************************************************************/
21 
27 /*********************************************************************
28 * *
29 * C H A N G E H I S T O R Y *
30 * *
31 *********************************************************************
32 
33 date init comment
34 ----------------------------------------------------------------------
35 17-feb-10 abb Begun; split out from ncx.c
36 */
37 
38 #include <xmlstring.h>
39 
40 #ifndef _H_dlq
41 #include "dlq.h"
42 #endif
43 
44 #ifndef _H_ncxtypes
45 #include "ncxtypes.h"
46 #endif
47 
48 #ifndef _H_tk
49 #include "tk.h"
50 #endif
51 
52 #ifndef _H_typ
53 #include "typ.h"
54 #endif
55 
56 #ifndef _H_val
57 #include "val.h"
58 #endif
59 
60 #ifndef _H_xmlns
61 #include "xmlns.h"
62 #endif
63 
64 #ifndef _H_yang
65 #include "yang.h"
66 #endif
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 /********************************************************************
73 * *
74 * F U N C T I O N S *
75 * *
76 *********************************************************************/
77 
93 extern void
94  ncx_init_num (ncx_num_t *num);
95 
96 
108 extern void
109  ncx_clean_num (ncx_btype_t btyp,
110  ncx_num_t *num);
111 
112 
126 extern int32
127  ncx_compare_nums (const ncx_num_t *num1,
128  const ncx_num_t *num2,
129  ncx_btype_t btyp);
130 
131 
138 extern void
139  ncx_set_num_min (ncx_num_t *num,
140  ncx_btype_t btyp);
141 
142 
149 extern void
150  ncx_set_num_max (ncx_num_t *num,
151  ncx_btype_t btyp);
152 
153 
160 extern void
161  ncx_set_num_one (ncx_num_t *num,
162  ncx_btype_t btyp);
163 
164 
171 extern void
172  ncx_set_num_zero (ncx_num_t *num,
173  ncx_btype_t btyp);
174 
175 
182 extern void
183  ncx_set_num_nan (ncx_num_t *num,
184  ncx_btype_t btyp);
185 
186 
195 extern boolean
196  ncx_num_is_nan (ncx_num_t *num,
197  ncx_btype_t btyp);
198 
199 
208 extern boolean
209  ncx_num_zero (const ncx_num_t *num,
210  ncx_btype_t btyp);
211 
212 
226 extern status_t
227  ncx_convert_num (const xmlChar *numstr,
228  ncx_numfmt_t numfmt,
229  ncx_btype_t btyp,
230  ncx_num_t *val);
231 
232 
245 extern status_t
246  ncx_convert_dec64 (const xmlChar *numstr,
247  ncx_numfmt_t numfmt,
248  uint8 digits,
249  ncx_num_t *val);
250 
251 
261 extern status_t
262  ncx_decode_num (const xmlChar *numstr,
263  ncx_btype_t btyp,
264  ncx_num_t *retnum);
265 
266 
278 extern status_t
279  ncx_decode_num_ex (const xmlChar *numstr,
280  ncx_btype_t btyp,
281  ncx_num_t *retnum,
282  typ_def_t *typdef);
283 
284 
294 extern status_t
295  ncx_decode_dec64 (const xmlChar *numstr,
296  uint8 digits,
297  ncx_num_t *retnum);
298 
299 
316 extern status_t
317  ncx_copy_num (const ncx_num_t *num1,
318  ncx_num_t *num2,
319  ncx_btype_t btyp);
320 
321 
339 extern status_t
340  ncx_cast_num (const ncx_num_t *num1,
341  ncx_btype_t btyp1,
342  ncx_num_t *num2,
343  ncx_btype_t btyp2);
344 
345 
363 extern status_t
364  ncx_num_floor (const ncx_num_t *num1,
365  ncx_num_t *num2,
366  ncx_btype_t btyp);
367 
368 
386 extern status_t
387  ncx_num_ceiling (const ncx_num_t *num1,
388  ncx_num_t *num2,
389  ncx_btype_t btyp);
390 
391 
409 extern status_t
410  ncx_round_num (const ncx_num_t *num1,
411  ncx_num_t *num2,
412  ncx_btype_t btyp);
413 
414 
430 extern boolean
431  ncx_num_is_integral (const ncx_num_t *num,
432  ncx_btype_t btyp);
433 
434 
443 extern int64
444  ncx_cvt_to_int64 (const ncx_num_t *num,
445  ncx_btype_t btyp);
446 
447 
457 extern ncx_numfmt_t
458  ncx_get_numfmt (const xmlChar *numstr);
459 
460 
468 extern void
469  ncx_printf_num (const ncx_num_t *num,
470  ncx_btype_t btyp,
471  log_debug_t level);
472 
473 
482 extern void
483  ncx_printf_num_ex (const ncx_num_t *num,
484  ncx_btype_t btyp,
485  log_debug_t level,
486  FILE *overrideOut);
487 
488 
495 extern void
496  ncx_alt_printf_num (const ncx_num_t *num,
497  ncx_btype_t btyp);
498 
499 
506 extern void
507  ncx_audit_printf_num (const ncx_num_t *num,
508  ncx_btype_t btyp);
509 
510 
521 extern status_t
522  ncx_sprintf_num (xmlChar *buff,
523  const ncx_num_t *num,
524  ncx_btype_t btyp,
525  uint32 *len);
526 
527 
537 extern boolean
538  ncx_is_min (const ncx_num_t *num,
539  ncx_btype_t btyp);
540 
541 
551 extern boolean
552  ncx_is_max (const ncx_num_t *num,
553  ncx_btype_t btyp);
554 
555 
568 extern status_t
569  ncx_convert_tkcnum (tk_chain_t *tkc,
570  ncx_btype_t btyp,
571  ncx_num_t *val);
572 
573 
585 extern status_t
586  ncx_convert_tkc_dec64 (tk_chain_t *tkc,
587  uint8 digits,
588  ncx_num_t *val);
589 
590 
597 extern int64
598  ncx_get_dec64_base (const ncx_num_t *num);
599 
600 
607 extern int64
608  ncx_get_dec64_fraction (const ncx_num_t *num);
609 
610 
614 #ifdef __cplusplus
615 } /* end extern 'C' */
616 #endif
617 
618 #endif /* _H_ncx_num */
typ_get_basetype
ncx_btype_t typ_get_basetype(const typ_def_t *typdef)
Get the final base type of the specified typ_def_t.
Definition: typ.c:1764
xml_strlen
uint32 xml_strlen(const xmlChar *str)
Get the String len for xmlChar.
Definition: xml_util.c:1406
ERR_NCX_NOT_IN_RANGE
@ ERR_NCX_NOT_IN_RANGE
288
Definition: status_enum.h:331
TK_TT_DNUM
@ TK_TT_DNUM
decimal number
Definition: tk.h:331
NCX_NF_OCTAL
@ NCX_NF_OCTAL
YANG octal format.
Definition: ncxtypes.h:334
ncx_convert_tkc_dec64
status_t ncx_convert_tkc_dec64(tk_chain_t *tkc, uint8 digits, ncx_num_t *val)
Convert the current token in a token chain to a ncx_num_t struct, expecting NCX_BT_DECIMAL64.
Definition: ncx_num.c:2699
NCX_BT_INT32
@ NCX_BT_INT32
int32
Definition: ncxtypes.h:209
xml_strncpy
uint32 xml_strncpy(xmlChar *copyTo, const xmlChar *copyFrom, uint32 maxlen)
String copy for xmlChar – checks for buffer overflow.
Definition: xml_util.c:1518
ncx_convert_dec64
status_t ncx_convert_dec64(const xmlChar *numstr, ncx_numfmt_t numfmt, uint8 digits, ncx_num_t *val)
Convert a number string to a decimal64 number.
Definition: ncx_num.c:1039
ncx_alt_printf_num
void ncx_alt_printf_num(const ncx_num_t *num, ncx_btype_t btyp)
Printf a ncx_num_t contents to the alternate log file.
Definition: ncx_num.c:2278
ncx_decode_num
status_t ncx_decode_num(const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum)
Handle some sort of number string.
Definition: ncx_num.c:1288
val.h
Value Node Basic Support.
xml_util.h
XML Utilities.
ncx_set_num_nan
void ncx_set_num_nan(ncx_num_t *num, ncx_btype_t btyp)
Set a FP number to the Not a Number value.
Definition: ncx_num.c:592
NCX_MIN_UINT
#define NCX_MIN_UINT
Min and max uint.
Definition: ncxconst.h:557
tk.h
NCX Syntax Token Handler.
ncx_num.h
NCX Module Library Number Utility Functions.
NCX_MIN_ULONG
#define NCX_MIN_ULONG
Min and max uint64.
Definition: ncxconst.h:565
ncx_printf_num_ex
void ncx_printf_num_ex(const ncx_num_t *num, ncx_btype_t btyp, log_debug_t level, FILE *overrideOut)
Printf a ncx_num_t contents (write to a file)
Definition: ncx_num.c:2234
TK_TT_RNUM
@ TK_TT_RNUM
real number
Definition: tk.h:333
NCX_NF_HEX
@ NCX_NF_HEX
YANG hexidecimal format.
Definition: ncxtypes.h:336
ncx_init_num
void ncx_init_num(ncx_num_t *num)
Init a ncx_num_t struct.
Definition: ncx_num.c:162
ncxconst.h
Contains NCX constants.
ncx_is_min
boolean ncx_is_min(const ncx_num_t *num, ncx_btype_t btyp)
Return TRUE if the specified number is the min value for its type.
Definition: ncx_num.c:2522
ncx_num_is_nan
boolean ncx_num_is_nan(ncx_num_t *num, ncx_btype_t btyp)
Check if a FP number is set to the Not a Number value.
Definition: ncx_num.c:627
ncx_is_max
boolean ncx_is_max(const ncx_num_t *num, ncx_btype_t btyp)
Return TRUE if the specified number is the max value for its type.
Definition: ncx_num.c:2579
TK_CUR_VAL
#define TK_CUR_VAL(T)
return the current token value
Definition: tk.h:128
log_audit_write
void void void void void void void void void log_audit_write(const char *fstr,...) __attribute__((format(printf
Write an new entry to the audit log file.
NCX_NF_DEC
@ NCX_NF_DEC
YANG deciaml format.
Definition: ncxtypes.h:335
NCX_BT_UINT8
@ NCX_BT_UINT8
uint8
Definition: ncxtypes.h:211
NCX_NF_NONE
@ NCX_NF_NONE
not set
Definition: ncxtypes.h:333
ncx_cvt_to_int64
int64 ncx_cvt_to_int64(const ncx_num_t *num, ncx_btype_t btyp)
Convert a number to an integer64; Use rounding for float64.
Definition: ncx_num.c:2103
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
NCX_BT_UINT64
@ NCX_BT_UINT64
uint64
Definition: ncxtypes.h:214
ERR_NCX_WRONG_TKTYPE
@ ERR_NCX_WRONG_TKTYPE
245
Definition: status_enum.h:284
NCX_NF_REAL
@ NCX_NF_REAL
internal format for XPath
Definition: ncxtypes.h:337
typ_get_fraction_digits
uint8 typ_get_fraction_digits(const typ_def_t *typdef)
Get the fraction-digits field from the typdef chain typdef must be an NCX_BT_DECIMAL64 or 0 will be r...
Definition: typ.c:5253
ncx_audit_printf_num
void ncx_audit_printf_num(const ncx_num_t *num, ncx_btype_t btyp)
Printf a ncx_num_t contents to the audit log file.
Definition: ncx_num.c:2314
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
ncx_get_dec64_base
int64 ncx_get_dec64_base(const ncx_num_t *num)
Get the base part of a decimal64 number.
Definition: ncx_num.c:2756
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
ncx_decode_num_ex
status_t ncx_decode_num_ex(const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum, typ_def_t *typdef)
Handle some sort of number string EXTENDED.
Definition: ncx_num.c:1312
NCX_MAX_DCHAR
#define NCX_MAX_DCHAR
max decimal digits in a plain int
Definition: ncxconst.h:429
ncx_round_num
status_t ncx_round_num(const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
Get the rounded value of a number.
Definition: ncx_num.c:1963
NCX_BT_INT64
@ NCX_BT_INT64
int64
Definition: ncxtypes.h:210
ERR_NCX_INVALID_VALUE
@ ERR_NCX_INVALID_VALUE
258
Definition: status_enum.h:299
ncx_set_num_zero
void ncx_set_num_zero(ncx_num_t *num, ncx_btype_t btyp)
Set a number to zero.
Definition: ncx_num.c:542
TK_TT_HNUM
@ TK_TT_HNUM
hex number
Definition: tk.h:332
NCX_BT_UINT16
@ NCX_BT_UINT16
uint16
Definition: ncxtypes.h:212
get_error_string
const char * get_error_string(status_t res)
Get the error message for a specific internal error.
Definition: status.c:239
ERR_INTERNAL_PTR
@ ERR_INTERNAL_PTR
002
Definition: status_enum.h:192
yang.h
YANG Module parser utilities.
typ.h
Parameter Type Handler.
ncx_get_numfmt
ncx_numfmt_t ncx_get_numfmt(const xmlChar *numstr)
Get the number format of the specified string.
Definition: ncx_num.c:2164
NCX_MAX_LONG
#define NCX_MAX_LONG
Min and max long.
Definition: ncxconst.h:549
ncx_num_ceiling
status_t ncx_num_ceiling(const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
Get the ceiling value of a number.
Definition: ncx_num.c:1884
ncx_compare_nums
int32 ncx_compare_nums(const ncx_num_t *num1, const ncx_num_t *num2, ncx_btype_t btyp)
Compare 2 ncx_num_t union contents.
Definition: ncx_num.c:242
ncx_num_floor
status_t ncx_num_floor(const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
Get the floor value of a number.
Definition: ncx_num.c:1806
ncx_num_is_integral
boolean ncx_num_is_integral(const ncx_num_t *num, ncx_btype_t btyp)
Check if the number is integral or if it has a fractional part.
Definition: ncx_num.c:2038
NCX_MAX_NUMLEN
#define NCX_MAX_NUMLEN
max number len to use for static buffer allocation only
Definition: ncxconst.h:136
ERR_NCX_INVALID_NUM
@ ERR_NCX_INVALID_NUM
241
Definition: status_enum.h:280
ncx_sprintf_num
status_t ncx_sprintf_num(xmlChar *buff, const ncx_num_t *num, ncx_btype_t btyp, uint32 *len)
Sprintf a ncx_num_t contents.
Definition: ncx_num.c:2357
ncx_clean_num
void ncx_clean_num(ncx_btype_t btyp, ncx_num_t *num)
Scrub the memory in a ncx_num_t by freeing all the sub-fields.
Definition: ncx_num.c:189
ncx_convert_tkcnum
status_t ncx_convert_tkcnum(tk_chain_t *tkc, ncx_btype_t btyp, ncx_num_t *val)
Convert the current token in a token chain to a ncx_num_t struct.
Definition: ncx_num.c:2640
ERR_NCX_WRONG_NUMTYP
@ ERR_NCX_WRONG_NUMTYP
289
Definition: status_enum.h:332
ERR_NCX_DEC64_FRACOVFL
@ ERR_NCX_DEC64_FRACOVFL
363
Definition: status_enum.h:406
log.h
NCX System Logging Manager.
ERR_BUFF_OVFL
@ ERR_BUFF_OVFL
106
Definition: status_enum.h:218
ncxtypes.h
YANG module data structures Many internal representations of YANG module constructs.
NCX_DEF_FRACTION_DIGITS
#define NCX_DEF_FRACTION_DIGITS
YANG default fraction-digits.
Definition: ncxconst.h:304
ncx_get_dec64_fraction
int64 ncx_get_dec64_fraction(const ncx_num_t *num)
Get the fraction part of a decimal64 number.
Definition: ncx_num.c:2787
ncx_set_num_one
void ncx_set_num_one(ncx_num_t *num, ncx_btype_t btyp)
Set a number to one.
Definition: ncx_num.c:492
ncx_num_zero
boolean ncx_num_zero(const ncx_num_t *num, ncx_btype_t btyp)
Compare a ncx_num_t to zero.
Definition: ncx_num.c:663
NCX_BT_FLOAT64
@ NCX_BT_FLOAT64
hidden: just for XPath
Definition: ncxtypes.h:216
NCX_BT_UINT32
@ NCX_BT_UINT32
uint32
Definition: ncxtypes.h:213
xml_strcpy
uint32 xml_strcpy(xmlChar *copyTo, const xmlChar *copyFrom)
String copy for xmlChar.
Definition: xml_util.c:1486
ncx_cast_num
status_t ncx_cast_num(const ncx_num_t *num1, ncx_btype_t btyp1, ncx_num_t *num2, ncx_btype_t btyp2)
Cast a number as another number type.
Definition: ncx_num.c:1516
ncx_set_num_max
void ncx_set_num_max(ncx_num_t *num, ncx_btype_t btyp)
Set a number to the maximum value for its type.
Definition: ncx_num.c:428
ncx_printf_num
void ncx_printf_num(const ncx_num_t *num, ncx_btype_t btyp, log_debug_t level)
Printf a ncx_num_t contents using logging functions.
Definition: ncx_num.c:2214
ncx.h
YANG module utility functions.
ncx_copy_num
status_t ncx_copy_num(const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
Copy the contents of num1 to num2.
Definition: ncx_num.c:1451
TK_CUR_TYP
#define TK_CUR_TYP(T)
return the current token type
Definition: tk.h:125
ncx_set_num_min
void ncx_set_num_min(ncx_num_t *num, ncx_btype_t btyp)
Set a number to the minimum value for its type.
Definition: ncx_num.c:368
ncx_convert_num
status_t ncx_convert_num(const xmlChar *numstr, ncx_numfmt_t numfmt, ncx_btype_t btyp, ncx_num_t *val)
Convert a number string to a numeric type.
Definition: ncx_num.c:717
ERR_NCX_INVALID_HEXNUM
@ ERR_NCX_INVALID_HEXNUM
242
Definition: status_enum.h:281
ncx_decode_dec64
status_t ncx_decode_dec64(const xmlChar *numstr, uint8 digits, ncx_num_t *retnum)
Handle some sort of decimal64 number string (NCX_BT_DECIMAL64)
Definition: ncx_num.c:1383
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
NCX_BT_DECIMAL64
@ NCX_BT_DECIMAL64
decimal64
Definition: ncxtypes.h:215
ERR_NCX_DEC64_BASEOVFL
@ ERR_NCX_DEC64_BASEOVFL
362
Definition: status_enum.h:405
NCX_BT_INT8
@ NCX_BT_INT8
int8
Definition: ncxtypes.h:207
NCX_MIN_INT
#define NCX_MIN_INT
Min and max int.
Definition: ncxconst.h:536
xmlns.h
XML namespace support.
status.h
Global error messages for status code enumerations.
NCX_BT_NONE
@ NCX_BT_NONE
base type not set
Definition: ncxtypes.h:201
log_alt_write
void log_alt_write(const char *fstr,...) __attribute__((format(printf
Write to the alternate log file.
dlq.h
dlq provides general double-linked list and queue support:
NCX_IS_HEX_CH
#define NCX_IS_HEX_CH(c)
Standard 0x0 syntax to indicate a HEX number is specified.
Definition: ncxconst.h:419
VAL_MAX_NUMLEN
#define VAL_MAX_NUMLEN
maximum number of bytes in a number string
Definition: val.h:152
NCX_BT_INT16
@ NCX_BT_INT16
int16
Definition: ncxtypes.h:208