MHEG  17.9.0
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
glue_ulong.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2012 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 #ifndef _GLUE_ULONG_H_
26 #define _GLUE_ULONG_H_
27 
28 /*---includes for this file--------------------------------------------------*/
29 
30 #include <limits.h>
31 
32 #ifdef USE_TRUE_64BIT
33  #if defined(ULONG_MAX) && ULONG_MAX > 0x7fffffff
34 // ULONG_MAX is 64 bit, so U64BIT could use 'typedef unsigned long U64BIT;'
35  #elif defined(LLONG_MAX) && LLONG_MAX > 0x7fffffff
36 // LLONG_MAX is 64 bit, so U64BIT could use 'typedef unsigned long long U64BIT;'
37  #else
38  #undef USE_TRUE_64BIT
39  #endif
40 #endif
41 
42 #ifdef USE_TRUE_64BIT
43  #ifdef WIN32
44 typedef __int64 uint64_t;
45  #define atoll(s) atol(s)
46  #else
47  #include <stdint.h>
48  #endif
49  #include <stdlib.h>
50 #else
51  #include "techtype.h"
52 #endif
53 
54 /*---Constant and macro definitions for public use---------------------------*/
55 
56 /* largest unsigned 64 bit is 18446744073709551615 (2**64-1), so that's 21 chars */
57 #define MAX_64BIT_DECIMAL_STRING 22
58 
59 #ifdef USE_TRUE_64BIT
60  #define INVALID_64BIT_VAL 0xffffffffffffffffULL
61  #define ULL_Get32(variable) ((U32BIT)variable)
62  #define ULL_Add(variable, value) variable += (value)
63  #define ULL_Add32(variable, value) variable += ((U64BIT)value)
64  #define ULL_Sub(variable, value) variable -= (value)
65  #define ULL_Sub32(variable, value) variable -= ((U64BIT)value)
66  #define ULL_Mul32(variable, value) variable *= ((U64BIT)value)
67  #define ULL_Div32(variable, value) variable /= ((U64BIT)value)
68  #define ULL_ShiftLeft(variable, value) variable <<= (value)
69  #define ULL_ShiftRight(variable, value) variable >>= (value)
70  #define ULL_Set32(variable, value) variable = (U64BIT)value
71  #define ULL_SetInvalid(variable) variable = INVALID_64BIT_VAL
72  #define ULL_IsValid(variable) variable != INVALID_64BIT_VAL
73  #define ULL_IsEqual(variable, value) (variable == value)
74  #define ULL_Mod32(variable, value) (variable % (value))
75  #define ULL_Compare(first, second) (first > second) ? 1 : (first == second) ? 0 : -1
76  #define ULL_Compare32(first, second) UL_Compare(first, ((U64BIT)second))
77 #else
78 /* U64BIT is a structure with 'h' and 'l' as 32 bit variables */
79  #define ULL_Get32(variable) variable.l
80  #define ULL_Add(variable, value) variable = ULONG_Add(variable, value)
81  #define ULL_Add32(variable, value) variable = ULONG_Add32(variable, value)
82  #define ULL_Sub(variable, value) variable = ULONG_Sub(variable, value)
83  #define ULL_Sub32(variable, value) variable = ULONG_Sub32(variable, value)
84  #define ULL_Mul32(variable, value) variable = ULONG_Mul32(variable, value)
85  #define ULL_Div32(variable, value) variable = ULONG_Div32(variable, value)
86  #define ULL_ShiftLeft(variable, value) variable = ULONG_ShiftLeft(variable, value)
87  #define ULL_ShiftRight(variable, value) variable = ULONG_ShiftRight(variable, value)
88  #define ULL_Set32(variable, value) variable.h = 0; variable.l = value;
89  #define ULL_SetInvalid(variable) variable.h = 0xffffffffU; variable.l = 0xffffffffU;
90  #define ULL_IsValid(variable) ((variable.h != 0xffffffffU) || (variable.l != 0xffffffffU))
91  #define ULL_IsEqual(variable, value) (variable.l == value.l && variable.h == value.h)
92  #define ULL_Mod32(variable, value) ULONG_Mod32(variable, value)
93  #define ULL_Compare(first, second) ULONG_Compare(first, second)
94  #define ULL_Compare32(first, second) ULONG_Compare32(first, second)
95 #endif
96 
97 #define ULL_Itoa(variable, str) ULONG_Itoa(variable, str)
98 
99 /*---Enumerations for public use---------------------------------------------*/
100 
101 /*---Global type defs for public use-----------------------------------------*/
102 
103 #ifdef USE_TRUE_64BIT
104 
105 typedef uint64_t U64BIT;
106 
107 #else
108 
109 typedef struct { U32BIT h; U32BIT l; } U64BIT;
110 
111 #endif
112 
113 /*---Global variable declarations for public use-----------------------------*/
114 
115 /*---Global Function prototypes for public use-------------------------------*/
116 
117 #ifndef USE_TRUE_64BIT
118 
125 U64BIT ULONG_Add(U64BIT variable, U64BIT value);
126 
133 U64BIT ULONG_Add32(U64BIT variable, U32BIT value);
134 
143 U64BIT ULONG_Sub(U64BIT variable, U64BIT value);
144 
153 U64BIT ULONG_Sub32(U64BIT variable, U32BIT value);
154 
161 U64BIT ULONG_Mul32(U64BIT variable, U32BIT value);
162 
171 U64BIT ULONG_Div32(U64BIT variable, U32BIT value);
172 
179 U64BIT ULONG_ShiftLeft(U64BIT variable, U32BIT value);
180 
187 U64BIT ULONG_ShiftRight(U64BIT variable, U32BIT value);
188 
198 U32BIT ULONG_Mod32(U64BIT variable, U32BIT value);
199 
209 S32BIT ULONG_Compare(U64BIT first, U64BIT second);
210 
211 
221 S32BIT ULONG_Compare32(U64BIT variable, U32BIT value);
222 
223 #endif
232 U64BIT ULONG_Atoi(char *str);
233 
242 void ULONG_Itoa(U64BIT variable, char *str);
243 
244 
245 
246 #endif /*_GLUE_ULONG_H*/
void ULONG_Itoa(U64BIT variable, char *str)
Convert unsigned 64 bit to a string. The string should be able to hold at least 21 characters...
Definition: glue_ulong.c:427
S32BIT ULONG_Compare(U64BIT first, U64BIT second)
Compare two variables, returning a value that indicates the result of the comparison.
Definition: glue_ulong.c:321
U64BIT ULONG_Add32(U64BIT variable, U32BIT value)
Add a 32-bit value to a unsigned 64 bit variable.
Definition: glue_ulong.c:68
U64BIT ULONG_ShiftLeft(U64BIT variable, U32BIT value)
Shift bits left on unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:236
U64BIT ULONG_ShiftRight(U64BIT variable, U32BIT value)
Shift bits right on unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:266
U64BIT ULONG_Sub32(U64BIT variable, U32BIT value)
Subtract a 32-bit value from a unsigned 64 bit variable. It is the responsibility of the caller to ma...
Definition: glue_ulong.c:108
S32BIT ULONG_Compare32(U64BIT variable, U32BIT value)
Compare a variable with a 32-bit value, returning a value that indicates the result of the comparison...
Definition: glue_ulong.c:364
System Wide Global Technical Data Type Definitions.
U32BIT ULONG_Mod32(U64BIT variable, U32BIT value)
Find the remainer after dividing a unsigned 64 bit variable by a 24-bit value. NOTE: This function wi...
Definition: glue_ulong.c:299
U64BIT ULONG_Add(U64BIT variable, U64BIT value)
Add a value to a unsigned 64 bit variable.
Definition: glue_ulong.c:48
U64BIT ULONG_Sub(U64BIT variable, U64BIT value)
Subtract a value from a unsigned 64 bit variable. It is the responsibility of the caller to make sure...
Definition: glue_ulong.c:89
U64BIT ULONG_Mul32(U64BIT variable, U32BIT value)
Multiply a unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:124
U64BIT ULONG_Div32(U64BIT variable, U32BIT value)
Divide a unsigned 64 bit variable by a 24-bit value. NOTE: This function will produce invalid values ...
Definition: glue_ulong.c:195
Definition: glue_ulong.h:109