LibreOffice Module tools (master) 1
solar.h
Go to the documentation of this file.
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 INCLUDED_TOOLS_SOLAR_H
21#define INCLUDED_TOOLS_SOLAR_H
22
23#include <sal/types.h>
24#include <osl/endian.h>
25
31typedef sal_uIntPtr sal_uLong; /* Replaces type ULONG */
32
33// misc. macros to leverage platform and compiler differences
34
35// solar binary types
36
37/* Solar (portable) Binary (exchange) Type; OSI 6 subset
38 always little endian;
39 not necessarily aligned */
40
41typedef sal_uInt8 SVBT16[2];
42typedef sal_uInt8 SVBT32[4];
43typedef sal_uInt8 SVBT64[8];
44
45#ifdef __cplusplus
46
47inline sal_uInt16 SVBT16ToUInt16( const SVBT16 p ) { return static_cast<sal_uInt16>
48 (static_cast<sal_uInt16>(p[0])
49 + (static_cast<sal_uInt16>(p[1]) << 8)); }
50inline sal_Int16 SVBT16ToInt16( const SVBT16 p ) { return sal_Int16(SVBT16ToUInt16(p)); }
51inline sal_uInt32 SVBT32ToUInt32 ( const SVBT32 p ) { return static_cast<sal_uInt32>
52 (static_cast<sal_uInt32>(p[0])
53 + (static_cast<sal_uInt32>(p[1]) << 8)
54 + (static_cast<sal_uInt32>(p[2]) << 16)
55 + (static_cast<sal_uInt32>(p[3]) << 24)); }
56#if defined OSL_LITENDIAN
57inline double SVBT64ToDouble( const SVBT64 p )
58{
59 double n;
60 reinterpret_cast<sal_uInt8*>(&n)[0] = p[0];
61 reinterpret_cast<sal_uInt8*>(&n)[1] = p[1];
62 reinterpret_cast<sal_uInt8*>(&n)[2] = p[2];
63 reinterpret_cast<sal_uInt8*>(&n)[3] = p[3];
64 reinterpret_cast<sal_uInt8*>(&n)[4] = p[4];
65 reinterpret_cast<sal_uInt8*>(&n)[5] = p[5];
66 reinterpret_cast<sal_uInt8*>(&n)[6] = p[6];
67 reinterpret_cast<sal_uInt8*>(&n)[7] = p[7];
68 return n;
69}
70#else
71inline double SVBT64ToDouble( const SVBT64 p ) { double n;
72 reinterpret_cast<sal_uInt8*>(&n)[0] = p[7];
73 reinterpret_cast<sal_uInt8*>(&n)[1] = p[6];
74 reinterpret_cast<sal_uInt8*>(&n)[2] = p[5];
75 reinterpret_cast<sal_uInt8*>(&n)[3] = p[4];
76 reinterpret_cast<sal_uInt8*>(&n)[4] = p[3];
77 reinterpret_cast<sal_uInt8*>(&n)[5] = p[2];
78 reinterpret_cast<sal_uInt8*>(&n)[6] = p[1];
79 reinterpret_cast<sal_uInt8*>(&n)[7] = p[0];
80 return n; }
81#endif
82
83inline void ShortToSVBT16( sal_uInt16 n, SVBT16 p )
84{
85 p[0] = static_cast<sal_uInt8>(n);
86 p[1] = static_cast<sal_uInt8>(n >> 8);
87}
88inline void UInt32ToSVBT32 ( sal_uInt32 n, SVBT32 p )
89{
90 p[0] = static_cast<sal_uInt8>(n);
91 p[1] = static_cast<sal_uInt8>(n >> 8);
92 p[2] = static_cast<sal_uInt8>(n >> 16);
93 p[3] = static_cast<sal_uInt8>(n >> 24);
94}
95inline void Int32ToSVBT32 ( sal_Int32 n, SVBT32 p ) { UInt32ToSVBT32(sal_uInt32(n), p); }
96#if defined OSL_LITENDIAN
97inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = reinterpret_cast<sal_uInt8*>(&n)[0];
98 p[1] = reinterpret_cast<sal_uInt8*>(&n)[1];
99 p[2] = reinterpret_cast<sal_uInt8*>(&n)[2];
100 p[3] = reinterpret_cast<sal_uInt8*>(&n)[3];
101 p[4] = reinterpret_cast<sal_uInt8*>(&n)[4];
102 p[5] = reinterpret_cast<sal_uInt8*>(&n)[5];
103 p[6] = reinterpret_cast<sal_uInt8*>(&n)[6];
104 p[7] = reinterpret_cast<sal_uInt8*>(&n)[7]; }
105#else
106inline void DoubleToSVBT64( double n, SVBT64 p ) { p[0] = reinterpret_cast<sal_uInt8*>(&n)[7];
107 p[1] = reinterpret_cast<sal_uInt8*>(&n)[6];
108 p[2] = reinterpret_cast<sal_uInt8*>(&n)[5];
109 p[3] = reinterpret_cast<sal_uInt8*>(&n)[4];
110 p[4] = reinterpret_cast<sal_uInt8*>(&n)[3];
111 p[5] = reinterpret_cast<sal_uInt8*>(&n)[2];
112 p[6] = reinterpret_cast<sal_uInt8*>(&n)[1];
113 p[7] = reinterpret_cast<sal_uInt8*>(&n)[0]; }
114#endif
115#endif
116
117#endif
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void * p
sal_Int64 n
sal_uInt8 SVBT64[8]
Definition: solar.h:43
sal_uInt8 SVBT32[4]
Definition: solar.h:42
sal_uInt8 SVBT16[2]
Definition: solar.h:41
sal_uIntPtr sal_uLong
Intermediate type to solve type clash with Windows headers.
Definition: solar.h:31
unsigned char sal_uInt8