Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/tools/solar.h
Line
Count
Source
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
26
#include <algorithm>
27
28
/** Intermediate type to solve type clash with Windows headers.
29
 Should be removed as soon as all code parts have been reviewed
30
 and the correct type is known. Most of the times ULONG is meant
31
 to be a 32-Bit unsigned integer type as sal_uInt32 is often
32
 used for data exchange or for similar method args. */
33
typedef sal_uIntPtr    sal_uLong; /* Replaces type ULONG */
34
35
// misc. macros to leverage platform and compiler differences
36
37
// solar binary types
38
39
/* Solar (portable) Binary (exchange) Type; OSI 6 subset
40
   always little endian;
41
   not necessarily aligned */
42
43
typedef sal_uInt8   SVBT16[2];
44
typedef sal_uInt8   SVBT32[4];
45
typedef sal_uInt8   SVBT64[8];
46
47
3.70G
inline sal_uInt16 SVBT16ToUInt16( const SVBT16 p ) { return static_cast<sal_uInt16>
48
3.70G
                                                     (static_cast<sal_uInt16>(p[0])
49
3.70G
                                                   + (static_cast<sal_uInt16>(p[1]) <<  8)); }
50
2.18M
inline sal_Int16 SVBT16ToInt16( const SVBT16 p ) { return sal_Int16(SVBT16ToUInt16(p)); }
51
550M
inline sal_uInt32 SVBT32ToUInt32 ( const SVBT32 p ) { return static_cast<sal_uInt32>
52
550M
                                                     (static_cast<sal_uInt32>(p[0])
53
550M
                                                   + (static_cast<sal_uInt32>(p[1]) <<  8)
54
550M
                                                   + (static_cast<sal_uInt32>(p[2]) << 16)
55
550M
                                                   + (static_cast<sal_uInt32>(p[3]) << 24)); }
56
inline double   SVBT64ToDouble( const SVBT64 p )
57
115
{
58
115
    double n;
59
115
#if defined OSL_LITENDIAN
60
115
    std::copy(p, p + 8, reinterpret_cast<sal_uInt8*>(&n));
61
#else
62
    std::reverse_copy(p, p + 8, reinterpret_cast<sal_uInt8*>(&n));
63
#endif
64
115
    return n;
65
115
}
66
67
inline void     ShortToSVBT16( sal_uInt16 n, SVBT16 p )
68
53.3k
{
69
53.3k
    p[0] = static_cast<sal_uInt8>(n);
70
53.3k
    p[1] = static_cast<sal_uInt8>(n >>  8);
71
53.3k
}
72
inline void     UInt32ToSVBT32 ( sal_uInt32  n, SVBT32 p )
73
5.69M
{
74
5.69M
    p[0] = static_cast<sal_uInt8>(n);
75
5.69M
    p[1] = static_cast<sal_uInt8>(n >>  8);
76
5.69M
    p[2] = static_cast<sal_uInt8>(n >> 16);
77
5.69M
    p[3] = static_cast<sal_uInt8>(n >> 24);
78
5.69M
}
79
0
inline void     Int32ToSVBT32 ( sal_Int32  n, SVBT32 p ) { UInt32ToSVBT32(sal_uInt32(n), p); }
80
inline void     DoubleToSVBT64( double n, SVBT64 p )
81
0
{
82
0
#if defined OSL_LITENDIAN
83
0
    std::copy(reinterpret_cast<sal_uInt8*>(&n), reinterpret_cast<sal_uInt8*>(&n) + 8, p);
84
#else
85
    std::reverse_copy(reinterpret_cast<sal_uInt8*>(&n), reinterpret_cast<sal_uInt8*>(&n) + 8, p);
86
#endif
87
0
}
88
89
#endif
90
91
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */