Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _SOLAR_H
21 : #define _SOLAR_H
22 :
23 : #include <sal/types.h>
24 : #include <osl/endian.h>
25 : #include <comphelper/fileformat.h>
26 :
27 : /** Intermediate type to solve type clash with Windows headers.
28 : Should be removed as soon as all code parts have been reviewed
29 : and the correct type is known. Most of the times ULONG is meant
30 : to be a 32-Bit unsigned integer type as sal_uInt32 is often
31 : used for data exchange or for similar method args. */
32 : typedef sal_uIntPtr sal_uLong; /* Replaces type ULONG */
33 :
34 : // misc. macros to leverage platform and compiler differences
35 :
36 : #define DELETEZ( p ) ( delete p,p = 0 )
37 :
38 : // solar binary types
39 :
40 : /* Solar (portable) Binary (exchange) Type; OSI 6 subset
41 : always little endian;
42 : not necessarily aligned */
43 :
44 : typedef sal_uInt8 SVBT16[2];
45 : typedef sal_uInt8 SVBT32[4];
46 : typedef sal_uInt8 SVBT64[8];
47 :
48 : #ifdef __cplusplus
49 :
50 1402362 : inline sal_uInt16 SVBT16ToShort( const SVBT16 p ) { return (sal_uInt16)p[0]
51 1402362 : + ((sal_uInt16)p[1] << 8); }
52 450204 : inline sal_uInt32 SVBT32ToUInt32 ( const SVBT32 p ) { return (sal_uInt32)p[0]
53 450204 : + ((sal_uInt32)p[1] << 8)
54 450204 : + ((sal_uInt32)p[2] << 16)
55 450204 : + ((sal_uInt32)p[3] << 24); }
56 : #if defined OSL_LITENDIAN
57 0 : inline double SVBT64ToDouble( const SVBT64 p ) { double n;
58 0 : ((sal_uInt8*)&n)[0] = p[0];
59 0 : ((sal_uInt8*)&n)[1] = p[1];
60 0 : ((sal_uInt8*)&n)[2] = p[2];
61 0 : ((sal_uInt8*)&n)[3] = p[3];
62 0 : ((sal_uInt8*)&n)[4] = p[4];
63 0 : ((sal_uInt8*)&n)[5] = p[5];
64 0 : ((sal_uInt8*)&n)[6] = p[6];
65 0 : ((sal_uInt8*)&n)[7] = p[7];
66 0 : return n; }
67 : #else
68 : inline double SVBT64ToDouble( const SVBT64 p ) { double n;
69 : ((sal_uInt8*)&n)[0] = p[7];
70 : ((sal_uInt8*)&n)[1] = p[6];
71 : ((sal_uInt8*)&n)[2] = p[5];
72 : ((sal_uInt8*)&n)[3] = p[4];
73 : ((sal_uInt8*)&n)[4] = p[3];
74 : ((sal_uInt8*)&n)[5] = p[2];
75 : ((sal_uInt8*)&n)[6] = p[1];
76 : ((sal_uInt8*)&n)[7] = p[0];
77 : return n; }
78 : #endif
79 :
80 95066 : inline void ShortToSVBT16( sal_uInt16 n, SVBT16 p ) { p[0] = (sal_uInt8) n;
81 95066 : p[1] = (sal_uInt8)(n >> 8); }
82 100794 : inline void UInt32ToSVBT32 ( sal_uInt32 n, SVBT32 p ) { p[0] = (sal_uInt8) n;
83 100794 : p[1] = (sal_uInt8)(n >> 8);
84 100794 : p[2] = (sal_uInt8)(n >> 16);
85 100794 : p[3] = (sal_uInt8)(n >> 24); }
86 : #if defined OSL_LITENDIAN
87 43264 : inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[0];
88 43264 : p[1] = ((sal_uInt8*)&n)[1];
89 43264 : p[2] = ((sal_uInt8*)&n)[2];
90 43264 : p[3] = ((sal_uInt8*)&n)[3];
91 43264 : p[4] = ((sal_uInt8*)&n)[4];
92 43264 : p[5] = ((sal_uInt8*)&n)[5];
93 43264 : p[6] = ((sal_uInt8*)&n)[6];
94 43264 : p[7] = ((sal_uInt8*)&n)[7]; }
95 : #else
96 : inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[7];
97 : p[1] = ((sal_uInt8*)&n)[6];
98 : p[2] = ((sal_uInt8*)&n)[5];
99 : p[3] = ((sal_uInt8*)&n)[4];
100 : p[4] = ((sal_uInt8*)&n)[3];
101 : p[5] = ((sal_uInt8*)&n)[2];
102 : p[6] = ((sal_uInt8*)&n)[1];
103 : p[7] = ((sal_uInt8*)&n)[0]; }
104 : #endif
105 : #endif
106 :
107 : // pragmas
108 :
109 : #if defined _MSC_VER
110 : /* deletion of pointer to incomplete type '...'; no destructor called
111 : serious error, memory deleted without call of dtor */
112 : #pragma warning( error: 4150 )
113 : // warning C4002: too many actual parameters for macro
114 : // warning C4003: not enough actual parameters for macro
115 : #pragma warning(error : 4002 4003)
116 : #endif
117 :
118 : #if defined WNT
119 : #define SVLIBRARY( Base ) Base "lo.dll"
120 : #elif defined MACOSX
121 : #define SVLIBRARY( Base ) "lib" Base "lo.dylib"
122 : #elif defined UNX
123 : #define SVLIBRARY( Base ) "lib" Base "lo.so"
124 : #else
125 : #error unknown platform
126 : #endif
127 :
128 : #endif
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|