g4tools  5.4.0
typedefs
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_typedefs
5 #define tools_typedefs
6 
7 // Similar to AIDA/v3r3p0/Types.h
8 
9 //NOTE : we avoid to have std includes here to be sure
10 // that in the below ifdef things come only from the compiler.
11 
12 //NOTE : if adding new platform here, look at ./s2int64 too.
13 
14 namespace tools {
15 
16 #ifdef _MSC_VER
17 
18 typedef int int32;
19 typedef __int64 int64;
20 inline const char* int32_format() {static const char s[] = "%d";return s;}
21 inline const char* int64_format() {static const char s[] = "%ld";return s;}
22 
23 typedef unsigned int uint32;
24 typedef unsigned __int64 uint64;
25 inline const char* uint32_format() {static const char s[] = "%u";return s;}
26 inline const char* uint64_format() {static const char s[] = "%lu";return s;}
27 
28 #ifdef _WIN64
29 typedef unsigned long long diff_pointer_t;
30 #else
31 typedef unsigned long diff_pointer_t;
32 #endif
33 
34 #ifdef _WIN64
35 typedef unsigned long long upointer;
36 inline const char* upointer_format() {static const char s[] = "%llu";return s;}
37 inline const char* upointer_format_x() {static const char s[] = "0x%llx";return s;}
38 #else
39 typedef unsigned long upointer;
40 inline const char* upointer_format() {static const char s[] = "%lu";return s;}
41 inline const char* upointer_format_x() {static const char s[] = "0x%lx";return s;}
42 #endif
43 
44 #elif defined(_LP64)
45 
46 // 64 Bit Platforms
47 typedef int int32;
48 typedef long int64;
49 inline const char* int32_format() {static const char s[] = "%d";return s;}
50 inline const char* int64_format() {static const char s[] = "%ld";return s;}
51 
52 typedef unsigned int uint32;
53 typedef unsigned long uint64;
54 inline const char* uint32_format() {static const char s[] = "%u";return s;}
55 inline const char* uint64_format() {static const char s[] = "%lu";return s;}
56 
57 typedef unsigned long diff_pointer_t;
58 
59 typedef unsigned long upointer;
60 inline const char* upointer_format() {static const char s[] = "%lu";return s;}
61 inline const char* upointer_format_x() {static const char s[] = "0x%lx";return s;}
62 
63 #else
64 
65 // 32-Bit Platforms
66 typedef int int32;
67 typedef long long int64;
68 inline const char* int32_format() {static const char s[] = "%d";return s;}
69 inline const char* int64_format() {static const char s[] = "%lld";return s;}
70 
71 typedef unsigned int uint32;
72 typedef unsigned long long uint64;
73 inline const char* uint32_format() {static const char s[] = "%u";return s;}
74 inline const char* uint64_format() {static const char s[] = "%llu";return s;}
75 
76 typedef unsigned long diff_pointer_t;
77 
78 typedef unsigned long upointer;
79 inline const char* upointer_format() {static const char s[] = "%lu";return s;}
80 inline const char* upointer_format_x() {static const char s[] = "0x%lx";return s;}
81 
82 #endif
83 
84 inline uint32 uint32_mx() { //4 294 967 295
85  uint32 n = 0;
86  for(unsigned int i=0;i<32;i++) n += 1<<i;
87  return n;
88 }
89 inline uint64 uint64_mx() { //18 446 744 073 709 551 615
90  uint64 one = 1;
91  uint64 n = 0;
92  for(unsigned int i=0;i<64;i++) n += one<<i;
93  return n;
94 }
95 
96 typedef unsigned char byte;
97 
98 //for ./io :
99 typedef unsigned char uchar;
100 typedef short int16;
101 typedef unsigned short ushort;
102 typedef unsigned short uint16;
103 typedef uint32 ref;
104 typedef char* cstr_t;
105 typedef const char* const_cstr_t;
106 
107 class fits_bit {public:char m_c;}; //for exlib/cfitsio
108 class csv_time {public:long m_l;}; //for rcsv_ntuple
109 
110 inline unsigned int size_char() {return 1;}
111 inline unsigned int size_short() {return 2;}
112 inline unsigned int size_int() {return 4;}
113 inline unsigned int size_int64() {return 8;}
114 inline unsigned int size_float() {return 4;}
115 inline unsigned int size_double() {return 8;}
116 
117 // used in arrout :
118 inline const char* type_format(float) {static const char s[] = "%g";return s;}
119 inline const char* type_format(double) {static const char s[] = "%g";return s;}
120 
121 inline const char* type_format(char) {static const char s[] = "%d";return s;}
122 inline const char* type_format(short) {static const char s[] = "%d";return s;}
123 inline const char* type_format(int) {static const char s[] = "%d";return s;}
124 inline const char* type_format(int64) {return int64_format();}
125 
126 inline const char* type_format(unsigned char) {static const char s[] = "%u";return s;}
127 inline const char* type_format(unsigned short) {static const char s[] = "%u";return s;}
128 inline const char* type_format(unsigned int) {static const char s[] = "%u";return s;}
129 inline const char* type_format(uint64) {return uint64_format();}
130 
131 typedef unsigned int key_code;
132 
133 }
134 
135 #endif
tools::uint32_mx
uint32 uint32_mx()
Definition: typedefs:84
tools::upointer_format_x
const char * upointer_format_x()
Definition: typedefs:80
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::byte
unsigned char byte
Definition: typedefs:96
tools::int64
long long int64
Definition: typedefs:67
tools::csv_time
Definition: typedefs:108
tools::size_short
unsigned int size_short()
Definition: typedefs:111
tools::size_double
unsigned int size_double()
Definition: typedefs:115
tools::type_format
const char * type_format(float)
Definition: typedefs:118
tools::key_code
unsigned int key_code
Definition: typedefs:131
tools::fits_bit::m_c
char m_c
Definition: typedefs:107
tools::upointer_format
const char * upointer_format()
Definition: typedefs:79
tools::ref
uint32 ref
Definition: typedefs:103
tools::fits_bit
Definition: typedefs:107
tools::size_int64
unsigned int size_int64()
Definition: typedefs:113
tools::uint64_format
const char * uint64_format()
Definition: typedefs:74
tools::uchar
unsigned char uchar
Definition: typedefs:99
tools::int32
int int32
Definition: typedefs:66
tools::cstr_t
char * cstr_t
Definition: typedefs:104
tools::size_char
unsigned int size_char()
Definition: typedefs:110
tools::uint32_format
const char * uint32_format()
Definition: typedefs:73
tools::upointer
unsigned long upointer
Definition: typedefs:78
tools::int64_format
const char * int64_format()
Definition: typedefs:69
tools::csv_time::m_l
long m_l
Definition: typedefs:108
tools::diff_pointer_t
unsigned long diff_pointer_t
Definition: typedefs:76
tools::size_float
unsigned int size_float()
Definition: typedefs:114
tools::size_int
unsigned int size_int()
Definition: typedefs:112
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::uint16
unsigned short uint16
Definition: typedefs:102
tools::uint64_mx
uint64 uint64_mx()
Definition: typedefs:89
tools::int32_format
const char * int32_format()
Definition: typedefs:68
tools::ushort
unsigned short ushort
Definition: typedefs:101
tools::const_cstr_t
const char * const_cstr_t
Definition: typedefs:105
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::int16
short int16
Definition: typedefs:100