1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_COMMON_GLOBAL_H
6 #define BALL_COMMON_GLOBAL_H
7 
8 #ifndef BALL_CONFIG_CONFIG_H
9 #	include <BALL/CONFIG/config.h>
10 #endif
11 
12 #include <limits>
13 #include <time.h>
14 
15 #ifdef BALL_HAS_BASETSD_H
16 #	include <basetsd.h>
17 #endif
18 
19 // If possible use the ISO C99-compliant header stdint.h
20 // to define the portable integer types.
21 #ifdef BALL_HAS_STDINT_H
22 #ifdef _WINDOWS
23 typedef signed char             int8_t;
24 typedef unsigned char           uint8_t;
25 typedef signed short            int16_t;
26 typedef unsigned short          uint16_t;
27 typedef signed int              int32_t;
28 typedef unsigned int            uint32_t;
29 typedef long long int           int64_t;
30 typedef unsigned long long int  uint64_t;
31 #else
32 #include <stdint.h>
33 #endif // _WINDOWS
34 
35 //#	include <stdint.h>
36 #endif
37 
38 #ifdef BALL_COMPILER_MSVC
39 # define BALL_HIDE
40 #	ifdef BALL_BUILD_DLL
41 #		define BALL_EXPORT __declspec(dllexport)
42 #		define BALL_EXTERN_VARIABLE __declspec(dllexport) extern
43 #	else
44 #		define BALL_EXPORT __declspec(dllimport)
45 #		define BALL_EXTERN_VARIABLE __declspec(dllimport) extern
46 #	endif
47 #	ifdef BALL_VIEW_BUILD_DLL
48 #		define BALL_VIEW_EXPORT __declspec(dllexport)
49 #	else
50 #		define BALL_VIEW_EXPORT __declspec(dllimport)
51 #	endif
52 #elif defined(BALL_COMPILER_GXX) && (BALL_COMPILER_VERSION_MAJOR > 4 || (BALL_COMPILER_VERSION_MAJOR == 4 && BALL_COMPILER_VERSION_MINOR >= 3))
53 # define BALL_EXPORT __attribute__((visibility ("default")))
54 # define BALL_HIDE __attribute__((visibility ("hidden")))
55 # define BALL_VIEW_EXPORT __attribute__((visibility ("default")))
56 # define BALL_EXTERN_VARIABLE extern __attribute__((visibility ("default")))
57 #else
58 # define BALL_EXPORT
59 # define BALL_HIDE
60 # define BALL_VIEW_EXPORT
61 # define BALL_EXTERN_VARIABLE extern
62 #endif
63 
64 //This declares a BALL_DEPRECATED macro that can be used to mark deprecated api
65 //It is essentially copied from Qt 4.4.1 but simplified, thus there might be
66 //some cases where it does not work as expected, yet.
67 #if defined(BALL_COMPILER_MSVC) && (_MSC_VER >= 1300)
68     #define BALL_DEPRECATED __declspec(deprecated)
69 #elif defined(BALL_COMPILER_GXX) && (BALL_COMPILER_VERSION_MAJOR - 0 > 3 || (BALL_COMPILER_VERSION_MAJOR - 0 == 3 && BALL_COMPILER_VERSION_MINOR - 0 >= 2))
70     #define BALL_DEPRECATED __attribute__((deprecated))
71 #else
72     #define BALL_DEPRECATED
73 #endif
74 
75 namespace BALL
76 {
77 
78     typedef int (*ComparatorType)(const void *, const void *);
79 
80     /**	@name Type aliases defined by BALL.
81             These predefined types are used in BALL for portability and
82             comprehensibility.
83 
84     \ingroup Common
85     */
86     //@{
87 
88     /**	Distance type.
89             Use this type to represent distances in indices. Signed.
90              \par
91             <b>Size:</b> 32 bit \par
92             <b>persistent</b>
93     */
94     typedef BALL_INDEX_TYPE	Distance;
95 
96     /**	Handle type.
97             Use this type to represent <b>handles</b>. Handles are used
98             for the non-ambiguous identification of objects (e.g. object derived
99       from  \link Object Object \endlink ). Handles are unsigned.
100              \par
101             <b>Size:</b> 32 bit \par
102             <b>persistent</b>
103   */
104     typedef BALL_SIZE_TYPE 	Handle;
105 
106     /**	Index type.
107             Use this type to represent indices (e.g. in strings or other sequences).
108             Theses indices may be signed, contrary to the  \link ::Size Size \endlink  type.
109              \par
110             <b>Size:</b> 32 bit \par
111             <b>persistent</b>
112     */
113     typedef BALL_INDEX_TYPE	Index;
114 
115     /**	Size type.
116             Use this type to represent sizes of containers, sequences or alike.
117             Variables of type Size are unsigned.
118              \par
119             <b>Size:</b> 32 bit \par
120             <b>persistent</b>
121     */
122     typedef BALL_SIZE_TYPE 	Size;
123 
124     /**	Time type.
125             Use this type to represent a point in time
126             (as a replaecement for time_t).
127              \par
128             <b>Size:</b> platform dependent \par
129             <b>not persistent</b>
130     */
131     typedef time_t 	Time;
132 
133     /**	HashIndex type.
134             Use this type to access the result of a hash functions. HashIndex is unsigned.
135              \par
136             <b>Size:</b> 32 bit \par
137             <b>persistent</b>
138     */
139     typedef	BALL_SIZE_TYPE	HashIndex;
140 
141     /**	Position type.
142             Use this type to represent positions (e.g. in a container) that
143             cannot be negative (contrary to  \link ::Index Index \endlink ).
144              \par
145             <b>Size:</b> 32 bit \par
146             <b>persistent</b>
147     */
148     typedef	BALL_SIZE_TYPE	Position;
149 
150     /**	Real type.
151             Use this type to represent standard floating point numbers.
152              \par
153             <b>Size:</b> 32 bit \par
154             <b>persistent</b>
155     */
156     typedef float Real;
157 
158     /**	Double-precision real type.
159             Use this type to represent double precision floating point numbers.
160              \par
161             <b>Size:</b> 64 bit \par
162             <b>persistent</b>
163     */
164     typedef double DoubleReal;
165 
166     /**	Unnamed property type.
167             Use this type to represent (unnamed) properties.
168              \par
169             <b>Size:</b> 32 bit \par
170             <b>persistent</b>
171             @see PropertyManager
172     */
173     typedef BALL_SIZE_TYPE Property;
174 
175     /**	Error code property type.
176             Use this type to represent (signed) error codes.  \par
177             <b>Size:</b> 32 bit \par
178             <b>persistent</b>
179             @see PropertyManager
180     */
181     typedef BALL_INDEX_TYPE ErrorCode;
182 
183 
184     /**	Byte type.
185             Use this type to represent byte data (8 bit length).
186             A Byte is always unsigned.
187              \par
188             <b>Size:</b> 8 bit \par
189             <b>persistent</b>
190     */
191     typedef	unsigned char Byte;
192 
193     /**	Long unsigned int type.
194             This type holds unsigned 64 bit integer numbers and is used to store pointers
195             in a portable fashion (for both 32-bit and 64-bit systems).
196              \par
197             <b>Size:</b> 64 bit \par
198             <b>persistent</b>
199     */
200     typedef BALL_ULONG64_TYPE LongSize;
201 
202     /**	Long signed int type.
203             This type holds unsigned 64 bit numbers and is used to store pointers
204             in a portable fashion (for both 32-bit and 64-bit systems).
205              \par
206             <b>Size:</b> 64 bit \par
207             <b>persistent</b>
208     */
209     typedef BALL_LONG64_TYPE LongIndex;
210 
211     /** Unsigned int with the same size as a pointer.
212             Used for internal conversion issues mostly.
213             <b>Size:</b> 32/64 bit (platform dependent)\par
214     */
215     typedef BALL_POINTERSIZEUINT_TYPE PointerSizeUInt;
216 
217     //@}
218 
219     enum ASCII
220     {
221         ASCII__BACKSPACE        = '\b',
222         ASCII__BELL             = '\a',
223         ASCII__CARRIAGE_RETURN  = '\r',
224         ASCII__HORIZONTAL_TAB   = '\t',
225         ASCII__NEWLINE          = '\n',
226         ASCII__RETURN           = ASCII__NEWLINE,
227         ASCII__SPACE            = ' ',
228         ASCII__TAB              = ASCII__HORIZONTAL_TAB,
229         ASCII__VERTICAL_TAB     = '\v',
230 
231         ASCII__COLON            = ':',
232         ASCII__COMMA            = ',',
233         ASCII__EXCLAMATION_MARK = '!',
234         ASCII__POINT            = '.',
235         ASCII__QUESTION_MARK    = '?',
236         ASCII__SEMICOLON        = ';'
237     };
238 
239     static const Distance INVALID_DISTANCE = std::numeric_limits<Distance>::max();
240     static const Distance DISTANCE_MIN = (std::numeric_limits<Distance>::min() + 1);
241     static const Distance DISTANCE_MAX = std::numeric_limits<Distance>::max();
242 
243     static const Handle INVALID_HANDLE = std::numeric_limits<Handle>::max();
244     static const Handle HANDLE_MIN = 0 ;
245     static const Handle HANDLE_MAX = std::numeric_limits<Handle>::max() - 1;
246 
247     static const Index INVALID_INDEX = -1;
248     static const Index INDEX_MIN = 0;
249     static const Index INDEX_MAX = std::numeric_limits<Index>::max();
250 
251     static const Position INVALID_POSITION = std::numeric_limits<Position>::max();
252     static const Position POSITION_MIN = 0;
253     static const Position POSITION_MAX = std::numeric_limits<Position>::max() - 1;
254 
255 #	undef SIZE_MAX
256     static const Size INVALID_SIZE = std::numeric_limits<Size>::max();
257     static const Size SIZE_MIN = 0;
258     static const Size SIZE_MAX = std::numeric_limits<Size>::max() - 1;
259 
260 
261 }
262 
263 #endif // BALL_COMMON_GLOBAL_H
264