xref: /trunk/main/tools/inc/tools/solar.h (revision 86e1cf34)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SOLAR_H
25 #define _SOLAR_H
26 
27 #include <sal/types.h>
28 #include <osl/endian.h>
29 #include <comphelper/fileformat.h>
30 
31 /*** common solar defines ***********************************/
32 
33 #ifdef _SOLAR__PRIVATE
34 #undef _SOLAR__PRIVATE
35 #endif
36 #define _SOLAR__PRIVATE 1
37 #define __REFERENCED	0
38 
39 /************************************************************
40  Intermediate type to solve type clash with Windows headers.
41  Should be removed as soon as all code parts have been reviewed
42  and the correct type is known. Most of the times ULONG is meant
43  to be a 32-Bit unsigned integer type as sal_uInt32 is often
44  used for data exchange or for similar method args.
45 *************************************************************/
46 typedef sal_uIntPtr    sal_uLong; /* Replaces type ULONG */
47 
48 /*** misc. macros to leverage platform and compiler differences ********/
49 
50 typedef int 			FASTBOOL;
51 #define DELETEZ( p )	( delete p,p = 0 )
52 
53 #define __FAR_DATA
54 #define __READONLY_DATA 		const
55 #define __EXPORT
56 
57 #ifdef WNT
58 #if defined (_MSC_VER) && ( _MSC_VER < 1200 )
59 #define __LOADONCALLAPI _cdecl
60 #else
61 #define __LOADONCALLAPI __cdecl
62 #endif
63 #else
64 #define __LOADONCALLAPI
65 #endif
66 
67 #if defined UNX
68 #define ILLEGAL_POINTER ((void*)1)
69 #else
70 #define ILLEGAL_POINTER NULL
71 #endif
72 
73 /*** solar binary types **********************************************/
74 
75 #ifndef _SOLAR_NOSVBT
76 /* Solar (portable) Binary (exchange) Type; OSI 6 subset
77    always little endian;
78    not necessarily aligned */
79 
80 typedef sal_uInt8				SVBT8[1];
81 typedef sal_uInt8				SVBT16[2];
82 typedef sal_uInt8				SVBT32[4];
83 typedef sal_uInt8				SVBT64[8];
84 
85 #ifdef __cplusplus
86 
SVBT8ToByte(const SVBT8 p)87 inline sal_uInt8 	SVBT8ToByte  ( const SVBT8	p ) { return p[0]; }
SVBT16ToShort(const SVBT16 p)88 inline sal_uInt16	SVBT16ToShort( const SVBT16 p ) { return (sal_uInt16)p[0]
89 												   + ((sal_uInt16)p[1] <<  8); }
SVBT32ToUInt32(const SVBT32 p)90 inline sal_uInt32	SVBT32ToUInt32 ( const SVBT32 p ) { return (sal_uInt32)p[0]
91 												   + ((sal_uInt32)p[1] <<  8)
92 												   + ((sal_uInt32)p[2] << 16)
93 												   + ((sal_uInt32)p[3] << 24); }
94 #if defined OSL_LITENDIAN
SVBT64ToDouble(const SVBT64 p)95 inline double	SVBT64ToDouble( const SVBT64 p ) { double n;
96 													((sal_uInt8*)&n)[0] = p[0];
97 													((sal_uInt8*)&n)[1] = p[1];
98 													((sal_uInt8*)&n)[2] = p[2];
99 													((sal_uInt8*)&n)[3] = p[3];
100 													((sal_uInt8*)&n)[4] = p[4];
101 													((sal_uInt8*)&n)[5] = p[5];
102 													((sal_uInt8*)&n)[6] = p[6];
103 													((sal_uInt8*)&n)[7] = p[7];
104 													return n; }
105 #else
SVBT64ToDouble(const SVBT64 p)106 inline double	SVBT64ToDouble( const SVBT64 p ) { double n;
107 													((sal_uInt8*)&n)[0] = p[7];
108 													((sal_uInt8*)&n)[1] = p[6];
109 													((sal_uInt8*)&n)[2] = p[5];
110 													((sal_uInt8*)&n)[3] = p[4];
111 													((sal_uInt8*)&n)[4] = p[3];
112 													((sal_uInt8*)&n)[5] = p[2];
113 													((sal_uInt8*)&n)[6] = p[1];
114 													((sal_uInt8*)&n)[7] = p[0];
115 													return n; }
116 #endif
117 
ByteToSVBT8(sal_uInt8 n,SVBT8 p)118 inline void 	ByteToSVBT8  ( sal_uInt8   n, SVBT8	p ) { p[0] = n; }
ShortToSVBT16(sal_uInt16 n,SVBT16 p)119 inline void 	ShortToSVBT16( sal_uInt16 n, SVBT16 p ) { p[0] = (sal_uInt8) n;
120 													  p[1] = (sal_uInt8)(n >>  8); }
UInt32ToSVBT32(sal_uInt32 n,SVBT32 p)121 inline void 	UInt32ToSVBT32 ( sal_uInt32  n, SVBT32 p ) { p[0] = (sal_uInt8) n;
122 													  p[1] = (sal_uInt8)(n >>  8);
123 													  p[2] = (sal_uInt8)(n >> 16);
124 													  p[3] = (sal_uInt8)(n >> 24); }
125 #if defined OSL_LITENDIAN
DoubleToSVBT64(double n,SVBT64 p)126 inline void 	DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[0];
127 													   p[1] = ((sal_uInt8*)&n)[1];
128 													   p[2] = ((sal_uInt8*)&n)[2];
129 													   p[3] = ((sal_uInt8*)&n)[3];
130 													   p[4] = ((sal_uInt8*)&n)[4];
131 													   p[5] = ((sal_uInt8*)&n)[5];
132 													   p[6] = ((sal_uInt8*)&n)[6];
133 													   p[7] = ((sal_uInt8*)&n)[7]; }
134 #else
DoubleToSVBT64(double n,SVBT64 p)135 inline void 	DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[7];
136 													   p[1] = ((sal_uInt8*)&n)[6];
137 													   p[2] = ((sal_uInt8*)&n)[5];
138 													   p[3] = ((sal_uInt8*)&n)[4];
139 													   p[4] = ((sal_uInt8*)&n)[3];
140 													   p[5] = ((sal_uInt8*)&n)[2];
141 													   p[6] = ((sal_uInt8*)&n)[1];
142 													   p[7] = ((sal_uInt8*)&n)[0]; }
143 #endif
144 #endif
145 #endif
146 
147 
148 /*** standard floating point definitions *******************************/
149 
150 #ifndef F_PI
151 #define F_PI		3.14159265358979323846
152 #endif
153 #ifndef F_PI2
154 #define F_PI2		1.57079632679489661923
155 #endif
156 #ifndef F_PI4
157 #define F_PI4		0.785398163397448309616
158 #endif
159 #ifndef F_PI180
160 #define F_PI180 	0.01745329251994
161 #endif
162 #ifndef F_PI1800
163 #define F_PI1800	0.001745329251994
164 #endif
165 #ifndef F_PI18000
166 #define F_PI18000	0.0001745329251994
167 #endif
168 #ifndef F_2PI
169 #define F_2PI		6.28318530717958647694
170 #endif
171 
172 
173 /*** standard macros *****************************************/
174 
175 #define SWAPSHORT(x) ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8))
176 #define SWAPLONG(x)  ((((x) >> 24) & 0x000000FF) | (((x) & 0x00FF0000) >> 8) | \
177 					  (((x) & 0x0000FF00) <<  8) | (((x) & 0x000000FF) << 24))
178 
179 #ifndef __cplusplus
180 #ifndef min
181 #define min(a,b)	(((a) < (b)) ? (a) : (b))
182 #endif
183 #ifndef max
184 #define max(a,b)	(((a) > (b)) ? (a) : (b))
185 #endif
186 #endif
187 
188 
189 
190 /*** standard inline functions *****************************************/
191 
192 #ifdef __cplusplus
Min(T a,T b)193 template<typename T> inline T Min(T a, T b) { return (a<b?a:b); }
Max(T a,T b)194 template<typename T> inline T Max(T a, T b) { return (a>b?a:b); }
Abs(T a)195 template<typename T> inline T Abs(T a) { return (a>=0?a:-a); }
196 #endif
197 
198 
199 /*** C / C++ - macros **************************************************/
200 
201 #ifdef __cplusplus
202 #define BEGIN_C 	extern "C" {
203 #define END_C		}
204 #define EXTERN_C	extern "C"
205 #else
206 #define BEGIN_C
207 #define END_C
208 #define EXTERN_C
209 #endif
210 
211 
212 /*** macros ************************************************************/
213 
214 #ifdef NOHACKS
215 #define HACK( comment ) #error hack: comment
216 #else
217 #define HACK( comment )
218 #endif
219 
220 #define _MAKE_NUMSTR( n )			# n
221 #define MAKE_NUMSTR( n )			_MAKE_NUMSTR( n )
222 
223 #define _LF 	((char)0x0A)
224 #define _CR 	((char)0x0D)
225 
226 
227 /*** pragmas ************************************************************/
228 
229 #if defined _MSC_VER
230 /* deletion of pointer to incomplete type '...'; no destructor called
231  serious error, memory deleted without call of dtor */
232 #pragma warning( error: 4150 )
233 // warning C4002: too many actual parameters for macro
234 // warning C4003: not enough actual parameters for macro
235 #pragma warning(error : 4002 4003)
236 #endif
237 
238 
239 /* dll file extensions *******************************************************/
240 
241 #if defined WNT
242 #if defined(__MINGW32__)
243   #define __DLLEXTENSION    "gi"
244 #else
245   #define __DLLEXTENSION ""
246 #endif
247 #elif defined OS2
248   #define __DLLEXTENSION ""
249 #elif defined UNX
250 #ifdef HPUX
251   #define __DLLEXTENSION ".sl"
252 #elif defined AIX     || \
253       defined SOLARIS || \
254       defined SCO     || \
255       defined NETBSD  || \
256       defined LINUX   || \
257       defined FREEBSD
258   #define __DLLEXTENSION ".so"
259 #elif defined MACOSX
260   #define __DLLEXTENSION ".dylib"
261 #else
262   #define __DLLEXTENSION ".so"
263 #endif
264 #endif
265 
266 // -----------------------------------------------------------------------
267 
268 #ifndef NOREPLACESTRING
269 #define UniString		String
270 #define XubString		String
271 #else
272 #define XubString		UniString
273 #endif
274 #define xub_Unicode 	sal_Unicode
275 #define xub_uUnicode	sal_Unicode
276 #ifdef STRING32
277 #define xub_StrLen		sal_uInt32
278 #else
279 #define xub_StrLen		sal_uInt16
280 #endif
281 
282 // -- moved here from libcall.hxx ----------------------------------------
283 
284 #define LIBRARY_STR(s)		# s
285 #define LIBRARY_STRING(s)	LIBRARY_STR(s)
286 
287 #define GETFUNCTION( s ) GetFunction( s )
288 #define LIBRARY_CONCAT3( s1, s2, s3 ) \
289 	s1 s2 s3
290 #define LIBRARY_CONCAT4( s1, s2, s3, s4 ) \
291 	s1 s2 s3 s4
292 
293 #if defined WNT || defined OS2
294 #define SVLIBRARY( Base ) \
295 	LIBRARY_CONCAT3( Base, __DLLEXTENSION, ".DLL" )
296 #define SVLIBRARYLANG( Base, Lang ) \
297 	LIBRARY_CONCAT3( Base, Lang, ".DLL" )
298 #elif defined UNX
299 #define SVLIBRARY( Base ) \
300 	LIBRARY_CONCAT3( "lib", Base, __DLLEXTENSION )
301 #define SVLIBRARYLANG( Base, Lang ) \
302 	LIBRARY_CONCAT3( "lib", Base, Lang )
303 #else
304 #define SVLIBRARY( Base ) \
305 	LIBRARY_CONCAT2( Base, __DLLEXTENSION )
306 #define SVLIBRARYLANG( Base, Lang ) \
307 	LIBRARY_CONCAT2( Base, Lang )
308 #endif
309 
310 #if defined MACOSX
311 #define SV_LIBFILENAME(str) \
312 	LIBRARYFILENAME_CONCAT2( str, __DLLEXTENSION )
313 #elif defined UNX
314 #define SV_LIBFILENAME(str) \
315 	LIBRARYFILENAME_CONCAT2( str, __DLLEXTENSION )
316 #else
317 #define SV_LIBFILENAME(str) \
318 	LIBRARYFILENAME_CONCAT3( str, __DLLEXTENSION, ".dll" )
319 #endif
320 
321 #endif	/* _SOLAR_H */
322