Bump version to 6.4-15
[LibreOffice.git] / include / tools / solar.h
blob721573287685b965400f55379ec32f48a5ad148d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_TOOLS_SOLAR_H
21 #define INCLUDED_TOOLS_SOLAR_H
23 #include <sal/types.h>
24 #include <osl/endian.h>
26 /** Intermediate type to solve type clash with Windows headers.
27 Should be removed as soon as all code parts have been reviewed
28 and the correct type is known. Most of the times ULONG is meant
29 to be a 32-Bit unsigned integer type as sal_uInt32 is often
30 used for data exchange or for similar method args. */
31 typedef sal_uIntPtr sal_uLong; /* Replaces type ULONG */
33 // misc. macros to leverage platform and compiler differences
35 #define DELETEZ( p ) ( delete p,p = NULL )
37 // solar binary types
39 /* Solar (portable) Binary (exchange) Type; OSI 6 subset
40 always little endian;
41 not necessarily aligned */
43 typedef sal_uInt8 SVBT16[2];
44 typedef sal_uInt8 SVBT32[4];
45 typedef sal_uInt8 SVBT64[8];
47 #ifdef __cplusplus
49 inline sal_uInt16 SVBT16ToUInt16( const SVBT16 p ) { return static_cast<sal_uInt16>
50 (static_cast<sal_uInt16>(p[0])
51 + (static_cast<sal_uInt16>(p[1]) << 8)); }
52 inline sal_Int16 SVBT16ToInt16( const SVBT16 p ) { return sal_Int16(SVBT16ToUInt16(p)); }
53 inline sal_uInt32 SVBT32ToUInt32 ( const SVBT32 p ) { return static_cast<sal_uInt32>
54 (static_cast<sal_uInt32>(p[0])
55 + (static_cast<sal_uInt32>(p[1]) << 8)
56 + (static_cast<sal_uInt32>(p[2]) << 16)
57 + (static_cast<sal_uInt32>(p[3]) << 24)); }
58 #if defined OSL_LITENDIAN
59 inline double SVBT64ToDouble( const SVBT64 p )
61 double n;
62 reinterpret_cast<sal_uInt8*>(&n)[0] = p[0];
63 reinterpret_cast<sal_uInt8*>(&n)[1] = p[1];
64 reinterpret_cast<sal_uInt8*>(&n)[2] = p[2];
65 reinterpret_cast<sal_uInt8*>(&n)[3] = p[3];
66 reinterpret_cast<sal_uInt8*>(&n)[4] = p[4];
67 reinterpret_cast<sal_uInt8*>(&n)[5] = p[5];
68 reinterpret_cast<sal_uInt8*>(&n)[6] = p[6];
69 reinterpret_cast<sal_uInt8*>(&n)[7] = p[7];
70 return n;
72 #else
73 inline double SVBT64ToDouble( const SVBT64 p ) { double n;
74 reinterpret_cast<sal_uInt8*>(&n)[0] = p[7];
75 reinterpret_cast<sal_uInt8*>(&n)[1] = p[6];
76 reinterpret_cast<sal_uInt8*>(&n)[2] = p[5];
77 reinterpret_cast<sal_uInt8*>(&n)[3] = p[4];
78 reinterpret_cast<sal_uInt8*>(&n)[4] = p[3];
79 reinterpret_cast<sal_uInt8*>(&n)[5] = p[2];
80 reinterpret_cast<sal_uInt8*>(&n)[6] = p[1];
81 reinterpret_cast<sal_uInt8*>(&n)[7] = p[0];
82 return n; }
83 #endif
85 inline void ShortToSVBT16( sal_uInt16 n, SVBT16 p )
87 p[0] = static_cast<sal_uInt8>(n);
88 p[1] = static_cast<sal_uInt8>(n >> 8);
90 inline void UInt32ToSVBT32 ( sal_uInt32 n, SVBT32 p )
92 p[0] = static_cast<sal_uInt8>(n);
93 p[1] = static_cast<sal_uInt8>(n >> 8);
94 p[2] = static_cast<sal_uInt8>(n >> 16);
95 p[3] = static_cast<sal_uInt8>(n >> 24);
97 inline void Int32ToSVBT32 ( sal_Int32 n, SVBT32 p ) { UInt32ToSVBT32(sal_uInt32(n), p); }
98 #if defined OSL_LITENDIAN
99 inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = reinterpret_cast<sal_uInt8*>(&n)[0];
100 p[1] = reinterpret_cast<sal_uInt8*>(&n)[1];
101 p[2] = reinterpret_cast<sal_uInt8*>(&n)[2];
102 p[3] = reinterpret_cast<sal_uInt8*>(&n)[3];
103 p[4] = reinterpret_cast<sal_uInt8*>(&n)[4];
104 p[5] = reinterpret_cast<sal_uInt8*>(&n)[5];
105 p[6] = reinterpret_cast<sal_uInt8*>(&n)[6];
106 p[7] = reinterpret_cast<sal_uInt8*>(&n)[7]; }
107 #else
108 inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = reinterpret_cast<sal_uInt8*>(&n)[7];
109 p[1] = reinterpret_cast<sal_uInt8*>(&n)[6];
110 p[2] = reinterpret_cast<sal_uInt8*>(&n)[5];
111 p[3] = reinterpret_cast<sal_uInt8*>(&n)[4];
112 p[4] = reinterpret_cast<sal_uInt8*>(&n)[3];
113 p[5] = reinterpret_cast<sal_uInt8*>(&n)[2];
114 p[6] = reinterpret_cast<sal_uInt8*>(&n)[1];
115 p[7] = reinterpret_cast<sal_uInt8*>(&n)[0]; }
116 #endif
117 #endif
119 #endif
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */