MHEG5  15.3.0
source/glue/inc/glue_ulong.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
00003  * Copyright © 2012 Ocean Blue Software Ltd
00004  *
00005  * This file is part of a DTVKit Software Component
00006  * You are permitted to copy, modify or distribute this file subject to the terms
00007  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
00008  * 
00009  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
00010  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
00011  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
00012  * 
00013  * If you or your organisation is not a member of DTVKit then you have access
00014  * to this source code outside of the terms of the licence agreement
00015  * and you are expected to delete this and any associated files immediately.
00016  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
00017  *******************************************************************************/
00025 #ifndef _GLUE_ULONG_H_
00026 #define _GLUE_ULONG_H_
00027 
00028 /*---includes for this file--------------------------------------------------*/
00029 
00030 #include <limits.h>
00031 
00032 #ifdef USE_TRUE_64BIT
00033   #if defined(ULONG_MAX) && ULONG_MAX > 0x7fffffff
00034 // ULONG_MAX is 64 bit, so U64BIT could use 'typedef unsigned long U64BIT;'
00035   #elif defined(LLONG_MAX) && LLONG_MAX > 0x7fffffff
00036 // LLONG_MAX is 64 bit, so U64BIT could use 'typedef unsigned long long U64BIT;'
00037   #else
00038     #undef USE_TRUE_64BIT
00039   #endif
00040 #endif
00041 
00042 #ifdef USE_TRUE_64BIT
00043   #ifdef WIN32
00044 typedef __int64 uint64_t;
00045     #define atoll(s) atol(s)
00046   #else
00047     #include <stdint.h>
00048   #endif
00049   #include <stdlib.h>
00050 #else
00051   #include "techtype.h"
00052 #endif
00053 
00054 /*---Constant and macro definitions for public use---------------------------*/
00055 
00056 /* largest unsigned 64 bit is 18446744073709551615 (2**64-1), so that's 21 chars */
00057 #define MAX_64BIT_DECIMAL_STRING 22
00058 
00059 #ifdef USE_TRUE_64BIT
00060    #define INVALID_64BIT_VAL                 0xffffffffffffffffULL
00061    #define ULL_Get32(variable)               ((U32BIT)variable)
00062    #define ULL_Add(variable, value)           variable += (value)
00063    #define ULL_Add32(variable, value)         variable += ((U64BIT)value)
00064    #define ULL_Sub(variable, value)           variable -= (value)
00065    #define ULL_Sub32(variable, value)         variable -= ((U64BIT)value)
00066    #define ULL_Mul32(variable, value)         variable *= ((U64BIT)value)
00067    #define ULL_Div32(variable, value)         variable /= ((U64BIT)value)
00068    #define ULL_ShiftLeft(variable, value)     variable <<= (value)
00069    #define ULL_ShiftRight(variable, value)    variable >>= (value)
00070    #define ULL_Set32(variable, value)         variable = (U64BIT)value
00071    #define ULL_SetInvalid(variable)          variable = INVALID_64BIT_VAL
00072    #define ULL_IsValid(variable)             variable != INVALID_64BIT_VAL
00073    #define ULL_IsEqual(variable, value)       (variable == value)
00074    #define ULL_Mod32(variable, value)         (variable % (value))
00075    #define ULL_Compare(first, second)         (first > second) ? 1 : (first == second) ? 0 : -1
00076    #define ULL_Compare32(first, second)       UL_Compare(first, ((U64BIT)second))
00077 #else
00078 /* U64BIT is a structure with 'h' and 'l' as 32 bit variables */
00079    #define ULL_Get32(variable)               variable.l
00080    #define ULL_Add(variable, value)           variable = ULONG_Add(variable, value)
00081    #define ULL_Add32(variable, value)         variable = ULONG_Add32(variable, value)
00082    #define ULL_Sub(variable, value)           variable = ULONG_Sub(variable, value)
00083    #define ULL_Sub32(variable, value)         variable = ULONG_Sub32(variable, value)
00084    #define ULL_Mul32(variable, value)         variable = ULONG_Mul32(variable, value)
00085    #define ULL_Div32(variable, value)         variable = ULONG_Div32(variable, value)
00086    #define ULL_ShiftLeft(variable, value)     variable = ULONG_ShiftLeft(variable, value)
00087    #define ULL_ShiftRight(variable, value)    variable = ULONG_ShiftRight(variable, value)
00088    #define ULL_Set32(variable, value)         variable.h = 0; variable.l = value;
00089    #define ULL_SetInvalid(variable)          variable.h = 0xffffffffU; variable.l = 0xffffffffU;
00090    #define ULL_IsValid(variable)             ((variable.h != 0xffffffffU) || (variable.l != 0xffffffffU))
00091    #define ULL_IsEqual(variable, value)       (variable.l == value.l && variable.h == value.h)
00092    #define ULL_Mod32(variable, value)         ULONG_Mod32(variable, value)
00093    #define ULL_Compare(first, second)         ULONG_Compare(first, second)
00094    #define ULL_Compare32(first, second)       ULONG_Compare32(first, second)
00095 #endif
00096 
00097 #define ULL_Itoa(variable, str)      ULONG_Itoa(variable, str)
00098 
00099 /*---Enumerations for public use---------------------------------------------*/
00100 
00101 /*---Global type defs for public use-----------------------------------------*/
00102 
00103 #ifdef USE_TRUE_64BIT
00104 
00105 typedef uint64_t U64BIT;
00106 
00107 #else
00108 
00109 typedef struct { U32BIT h; U32BIT l; } U64BIT;
00110 
00111 #endif
00112 
00113 /*---Global variable declarations for public use-----------------------------*/
00114 
00115 /*---Global Function prototypes for public use-------------------------------*/
00116 
00117 #ifndef USE_TRUE_64BIT
00118 
00125 U64BIT ULONG_Add(U64BIT variable, U64BIT value);
00126 
00133 U64BIT ULONG_Add32(U64BIT variable, U32BIT value);
00134 
00143 U64BIT ULONG_Sub(U64BIT variable, U64BIT value);
00144 
00153 U64BIT ULONG_Sub32(U64BIT variable, U32BIT value);
00154 
00161 U64BIT ULONG_Mul32(U64BIT variable, U32BIT value);
00162 
00171 U64BIT ULONG_Div32(U64BIT variable, U32BIT value);
00172 
00179 U64BIT ULONG_ShiftLeft(U64BIT variable, U32BIT value);
00180 
00187 U64BIT ULONG_ShiftRight(U64BIT variable, U32BIT value);
00188 
00198 U32BIT ULONG_Mod32(U64BIT variable, U32BIT value);
00199 
00209 S32BIT ULONG_Compare(U64BIT first, U64BIT second);
00210 
00211 
00221 S32BIT ULONG_Compare32(U64BIT variable, U32BIT value);
00222 
00223 #endif 
00232 U64BIT ULONG_Atoi(char *str);
00233 
00242 void ULONG_Itoa(U64BIT variable, char *str);
00243 
00244 
00245 
00246 #endif /*_GLUE_ULONG_H*/
 All Data Structures Files Functions Variables Typedefs Defines