/src/libreoffice/include/oox/helper/helper.hxx
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_OOX_HELPER_HELPER_HXX |
21 | | #define INCLUDED_OOX_HELPER_HELPER_HXX |
22 | | |
23 | | #include <sal/config.h> |
24 | | |
25 | | #include <cstring> |
26 | | #include <limits> |
27 | | #include <optional> |
28 | | |
29 | | #include <o3tl/safeint.hxx> |
30 | | #include <osl/endian.h> |
31 | | #include <rtl/math.hxx> |
32 | | #include <sal/types.h> |
33 | | #include <tools/color.hxx> |
34 | | |
35 | | namespace oox { |
36 | | |
37 | | // Helper macros ============================================================== |
38 | | |
39 | | namespace detail { |
40 | | |
41 | | //TODO: Temporary helper for STATIC_ARRAY_SELECT; ultimately, the latter should be replaced by a |
42 | | // proper function (template): |
43 | 5.17M | template<typename T> constexpr std::make_unsigned_t<T> make_unsigned(T value) { |
44 | 5.17M | if constexpr (std::is_signed_v<T>) { |
45 | 5.17M | return o3tl::make_unsigned(value); |
46 | 5.17M | } else { |
47 | 0 | return value; |
48 | 0 | } |
49 | 5.17M | } Unexecuted instantiation: _ZN3oox6detail13make_unsignedItEEu15__make_unsignedIT_ES2_ _ZN3oox6detail13make_unsignedIiEEu15__make_unsignedIT_ES2_ Line | Count | Source | 43 | 5.17M | template<typename T> constexpr std::make_unsigned_t<T> make_unsigned(T value) { | 44 | 5.17M | if constexpr (std::is_signed_v<T>) { | 45 | 5.17M | return o3tl::make_unsigned(value); | 46 | | } else { | 47 | | return value; | 48 | | } | 49 | 5.17M | } |
Unexecuted instantiation: _ZN3oox6detail13make_unsignedIhEEu15__make_unsignedIT_ES2_ Unexecuted instantiation: _ZN3oox6detail13make_unsignedIjEEu15__make_unsignedIT_ES2_ |
50 | | |
51 | | } |
52 | | |
53 | | /** Expands to the 'index'-th element of a STATIC data array, or to 'def', if |
54 | | 'index' is out of the array limits. */ |
55 | | #define STATIC_ARRAY_SELECT( array, index, def ) \ |
56 | 5.17M | ((detail::make_unsigned(index) < std::size(array)) ? ((array)[static_cast<size_t>(index)]) : (def)) |
57 | | |
58 | | // Common constants =========================================================== |
59 | | |
60 | | const sal_uInt8 WINDOWS_CHARSET_ANSI = 0; |
61 | | const sal_uInt8 WINDOWS_CHARSET_DEFAULT = 1; |
62 | | const sal_uInt8 WINDOWS_CHARSET_SYMBOL = 2; |
63 | | const sal_uInt8 WINDOWS_CHARSET_APPLE_ROMAN = 77; |
64 | | const sal_uInt8 WINDOWS_CHARSET_SHIFTJIS = 128; |
65 | | const sal_uInt8 WINDOWS_CHARSET_HANGEUL = 129; |
66 | | const sal_uInt8 WINDOWS_CHARSET_JOHAB = 130; |
67 | | const sal_uInt8 WINDOWS_CHARSET_GB2312 = 134; |
68 | | const sal_uInt8 WINDOWS_CHARSET_BIG5 = 136; |
69 | | const sal_uInt8 WINDOWS_CHARSET_GREEK = 161; |
70 | | const sal_uInt8 WINDOWS_CHARSET_TURKISH = 162; |
71 | | const sal_uInt8 WINDOWS_CHARSET_VIETNAMESE = 163; |
72 | | const sal_uInt8 WINDOWS_CHARSET_HEBREW = 177; |
73 | | const sal_uInt8 WINDOWS_CHARSET_ARABIC = 178; |
74 | | const sal_uInt8 WINDOWS_CHARSET_BALTIC = 186; |
75 | | const sal_uInt8 WINDOWS_CHARSET_RUSSIAN = 204; |
76 | | const sal_uInt8 WINDOWS_CHARSET_THAI = 222; |
77 | | const sal_uInt8 WINDOWS_CHARSET_EASTERN = 238; |
78 | | const sal_uInt8 WINDOWS_CHARSET_OEM = 255; |
79 | | |
80 | | |
81 | | const ::Color API_RGB_TRANSPARENT (ColorTransparency, 0xffffffff); ///< Transparent color for API calls. |
82 | | const sal_uInt32 UNSIGNED_RGB_TRANSPARENT = static_cast<sal_uInt32>(-1); ///< Transparent color for unsigned int32 places. |
83 | | const ::Color API_RGB_BLACK (0x000000); ///< Black color for API calls. |
84 | | const ::Color API_RGB_GRAY (0x808080); ///< Gray color for API calls. |
85 | | const ::Color API_RGB_WHITE (0xFFFFFF); ///< White color for API calls. |
86 | | |
87 | | const sal_Int16 API_LINE_SOLID = 0; |
88 | | const sal_Int16 API_LINE_DOTTED = 1; |
89 | | const sal_Int16 API_LINE_DASHED = 2; |
90 | | const sal_Int16 API_FINE_LINE_DASHED = 14; |
91 | | |
92 | | const sal_Int16 API_LINE_NONE = 0; |
93 | | const sal_Int16 API_LINE_HAIR = 2; |
94 | | const sal_Int16 API_LINE_THIN = 35; |
95 | | const sal_Int16 API_LINE_MEDIUM = 88; |
96 | | const sal_Int16 API_LINE_THICK = 141; |
97 | | |
98 | | const sal_Int16 API_ESCAPE_NONE = 0; ///< No escapement. |
99 | | const sal_Int16 API_ESCAPE_SUPERSCRIPT = 101; ///< Superscript: raise characters automatically (magic value 101). |
100 | | const sal_Int16 API_ESCAPE_SUBSCRIPT = -101; ///< Subscript: lower characters automatically (magic value -101). |
101 | | |
102 | | const sal_Int8 API_ESCAPEHEIGHT_NONE = 100; ///< Relative character height if not escaped. |
103 | | const sal_Int8 API_ESCAPEHEIGHT_DEFAULT = 58; ///< Relative character height if escaped. |
104 | | |
105 | | |
106 | | // Limitate values ------------------------------------------------------------ |
107 | | |
108 | | template< typename ReturnType, typename Type > |
109 | | inline ReturnType getLimitedValue( Type nValue, Type nMin, Type nMax ) |
110 | 469k | { |
111 | 469k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); |
112 | 469k | } int oox::getLimitedValue<int, int>(int, int, int) Line | Count | Source | 110 | 158k | { | 111 | 158k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 158k | } |
int oox::getLimitedValue<int, long>(long, long, long) Line | Count | Source | 110 | 21.3k | { | 111 | 21.3k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 21.3k | } |
Unexecuted instantiation: unsigned long oox::getLimitedValue<unsigned long, long>(long, long, long) short oox::getLimitedValue<short, short>(short, short, short) Line | Count | Source | 110 | 4.28k | { | 111 | 4.28k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 4.28k | } |
short oox::getLimitedValue<short, int>(int, int, int) Line | Count | Source | 110 | 56.2k | { | 111 | 56.2k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 56.2k | } |
int oox::getLimitedValue<int, double>(double, double, double) Line | Count | Source | 110 | 23.8k | { | 111 | 23.8k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 23.8k | } |
double oox::getLimitedValue<double, double>(double, double, double) Line | Count | Source | 110 | 168k | { | 111 | 168k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 168k | } |
unsigned int oox::getLimitedValue<unsigned int, long>(long, long, long) Line | Count | Source | 110 | 37.2k | { | 111 | 37.2k | return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) ); | 112 | 37.2k | } |
Unexecuted instantiation: long oox::getLimitedValue<long, long>(long, long, long) |
113 | | |
114 | | template< typename ReturnType, typename Type > |
115 | | inline ReturnType getIntervalValue( Type nValue, Type nBegin, Type nEnd ) |
116 | 0 | { |
117 | 0 | static_assert(::std::numeric_limits< Type >::is_integer, "is integer"); |
118 | 0 | Type nInterval = nEnd - nBegin; |
119 | 0 | Type nCount = (nValue < nBegin) ? -((nBegin - nValue - 1) / nInterval + 1) : ((nValue - nBegin) / nInterval); |
120 | 0 | return static_cast< ReturnType >( nValue - nCount * nInterval ); |
121 | 0 | } |
122 | | |
123 | | template< typename ReturnType > |
124 | | inline ReturnType getDoubleIntervalValue( double fValue, double fBegin, double fEnd ) |
125 | 60 | { |
126 | 60 | double fInterval = fEnd - fBegin; |
127 | 60 | double fCount = (fValue < fBegin) ? -(::rtl::math::approxFloor( (fBegin - fValue - 1.0) / fInterval ) + 1.0) : ::rtl::math::approxFloor( (fValue - fBegin) / fInterval ); |
128 | 60 | return static_cast< ReturnType >( fValue - fCount * fInterval ); |
129 | 60 | } Unexecuted instantiation: double oox::getDoubleIntervalValue<double>(double, double, double) short oox::getDoubleIntervalValue<short>(double, double, double) Line | Count | Source | 125 | 60 | { | 126 | 60 | double fInterval = fEnd - fBegin; | 127 | 60 | double fCount = (fValue < fBegin) ? -(::rtl::math::approxFloor( (fBegin - fValue - 1.0) / fInterval ) + 1.0) : ::rtl::math::approxFloor( (fValue - fBegin) / fInterval ); | 128 | 60 | return static_cast< ReturnType >( fValue - fCount * fInterval ); | 129 | 60 | } |
|
130 | | |
131 | | // Read from bitfields -------------------------------------------------------- |
132 | | |
133 | | /** Returns true, if at least one of the bits set in nMask is set in nBitField. */ |
134 | | template< typename Type > |
135 | | inline bool getFlag( Type nBitField, Type nMask ) |
136 | 2.26k | { |
137 | 2.26k | return (nBitField & nMask) != 0; |
138 | 2.26k | } bool oox::getFlag<unsigned int>(unsigned int, unsigned int) Line | Count | Source | 136 | 232 | { | 137 | 232 | return (nBitField & nMask) != 0; | 138 | 232 | } |
bool oox::getFlag<int>(int, int) Line | Count | Source | 136 | 1.58k | { | 137 | 1.58k | return (nBitField & nMask) != 0; | 138 | 1.58k | } |
bool oox::getFlag<unsigned short>(unsigned short, unsigned short) Line | Count | Source | 136 | 9 | { | 137 | 9 | return (nBitField & nMask) != 0; | 138 | 9 | } |
Unexecuted instantiation: bool oox::getFlag<unsigned char>(unsigned char, unsigned char) bool oox::getFlag<long>(long, long) Line | Count | Source | 136 | 439 | { | 137 | 439 | return (nBitField & nMask) != 0; | 138 | 439 | } |
|
139 | | |
140 | | /** Returns nSet, if at least one bit of nMask is set in nBitField, otherwise nUnset. */ |
141 | | template< typename ReturnType, typename Type > |
142 | | inline ReturnType getFlagValue( Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset ) |
143 | 0 | { |
144 | 0 | return getFlag( nBitField, nMask ) ? nSet : nUnset; |
145 | 0 | } Unexecuted instantiation: int oox::getFlagValue<int, unsigned short>(unsigned short, unsigned short, int, int) Unexecuted instantiation: int oox::getFlagValue<int, unsigned char>(unsigned char, unsigned char, int, int) |
146 | | |
147 | | /** Extracts a value from a bit field. |
148 | | |
149 | | Returns the data fragment from nBitField, that starts at bit nStartBit |
150 | | (0-based, bit 0 is rightmost) with the width of nBitCount. The returned |
151 | | value will be right-aligned (normalized). |
152 | | For instance: extractValue<T>(0x4321,8,4) returns 3 (value in bits 8-11). |
153 | | */ |
154 | | template< typename ReturnType, typename Type > |
155 | | inline ReturnType extractValue( Type nBitField, sal_uInt8 nStartBit, sal_uInt8 nBitCount ) |
156 | 5.17M | { |
157 | 5.17M | sal_uInt64 nMask = 1; nMask <<= nBitCount; --nMask; |
158 | 5.17M | return static_cast< ReturnType >( nMask & (nBitField >> nStartBit) ); |
159 | 5.17M | } Unexecuted instantiation: unsigned short oox::extractValue<unsigned short, unsigned int>(unsigned int, unsigned char, unsigned char) Unexecuted instantiation: unsigned char oox::extractValue<unsigned char, unsigned int>(unsigned int, unsigned char, unsigned char) Unexecuted instantiation: int oox::extractValue<int, unsigned int>(unsigned int, unsigned char, unsigned char) Unexecuted instantiation: unsigned char oox::extractValue<unsigned char, unsigned short>(unsigned short, unsigned char, unsigned char) Unexecuted instantiation: unsigned char oox::extractValue<unsigned char, unsigned char>(unsigned char, unsigned char, unsigned char) Unexecuted instantiation: int oox::extractValue<int, unsigned short>(unsigned short, unsigned char, unsigned char) short oox::extractValue<short, int>(int, unsigned char, unsigned char) Line | Count | Source | 156 | 5.17M | { | 157 | 5.17M | sal_uInt64 nMask = 1; nMask <<= nBitCount; --nMask; | 158 | 5.17M | return static_cast< ReturnType >( nMask & (nBitField >> nStartBit) ); | 159 | 5.17M | } |
unsigned short oox::extractValue<unsigned short, unsigned short>(unsigned short, unsigned char, unsigned char) Line | Count | Source | 156 | 2.25k | { | 157 | 2.25k | sal_uInt64 nMask = 1; nMask <<= nBitCount; --nMask; | 158 | 2.25k | return static_cast< ReturnType >( nMask & (nBitField >> nStartBit) ); | 159 | 2.25k | } |
|
160 | | |
161 | | // Write to bitfields --------------------------------------------------------- |
162 | | |
163 | | /** Sets or clears (according to bSet) all set bits of nMask in ornBitField. */ |
164 | | template< typename Type > |
165 | | inline void setFlag( Type& ornBitField, Type nMask, bool bSet = true ) |
166 | 12.2M | { |
167 | 12.2M | if( bSet ) ornBitField |= nMask; else ornBitField &= ~nMask; |
168 | 12.2M | } void oox::setFlag<unsigned short>(unsigned short&, unsigned short, bool) Line | Count | Source | 166 | 12.2M | { | 167 | 12.2M | if( bSet ) ornBitField |= nMask; else ornBitField &= ~nMask; | 168 | 12.2M | } |
Unexecuted instantiation: void oox::setFlag<int>(int&, int, bool) void oox::setFlag<unsigned int>(unsigned int&, unsigned int, bool) Line | Count | Source | 166 | 2 | { | 167 | 2 | if( bSet ) ornBitField |= nMask; else ornBitField &= ~nMask; | 168 | 2 | } |
void oox::setFlag<AxFontFlags>(AxFontFlags&, AxFontFlags, bool) Line | Count | Source | 166 | 12 | { | 167 | 12 | if( bSet ) ornBitField |= nMask; else ornBitField &= ~nMask; | 168 | 12 | } |
void oox::setFlag<long>(long&, long, bool) Line | Count | Source | 166 | 439 | { | 167 | 439 | if( bSet ) ornBitField |= nMask; else ornBitField &= ~nMask; | 168 | 439 | } |
|
169 | | |
170 | | |
171 | | template< typename Type > |
172 | | void assignIfUsed( std::optional<Type>& rDestValue, const std::optional<Type>& rSourceValue ) |
173 | 433M | { |
174 | 433M | if( rSourceValue.has_value() ) |
175 | 2.99M | rDestValue = rSourceValue.value(); |
176 | 433M | } void oox::assignIfUsed<bool>(std::__1::optional<bool>&, std::__1::optional<bool> const&) Line | Count | Source | 173 | 76.2M | { | 174 | 76.2M | if( rSourceValue.has_value() ) | 175 | 190k | rDestValue = rSourceValue.value(); | 176 | 76.2M | } |
void oox::assignIfUsed<com::sun::star::geometry::IntegerRectangle2D>(std::__1::optional<com::sun::star::geometry::IntegerRectangle2D>&, std::__1::optional<com::sun::star::geometry::IntegerRectangle2D> const&) Line | Count | Source | 173 | 29.1M | { | 174 | 29.1M | if( rSourceValue.has_value() ) | 175 | 43 | rDestValue = rSourceValue.value(); | 176 | 29.1M | } |
void oox::assignIfUsed<int>(std::__1::optional<int>&, std::__1::optional<int> const&) Line | Count | Source | 173 | 223M | { | 174 | 223M | if( rSourceValue.has_value() ) | 175 | 2.64M | rDestValue = rSourceValue.value(); | 176 | 223M | } |
void oox::assignIfUsed<rtl::OUString>(std::__1::optional<rtl::OUString>&, std::__1::optional<rtl::OUString> const&) Line | Count | Source | 173 | 9.38M | { | 174 | 9.38M | if( rSourceValue.has_value() ) | 175 | 152k | rDestValue = rSourceValue.value(); | 176 | 9.38M | } |
void oox::assignIfUsed<double>(std::__1::optional<double>&, std::__1::optional<double> const&) Line | Count | Source | 173 | 9.35M | { | 174 | 9.35M | if( rSourceValue.has_value() ) | 175 | 4.25k | rDestValue = rSourceValue.value(); | 176 | 9.35M | } |
void oox::assignIfUsed<oox::drawingml::LineProperties>(std::__1::optional<oox::drawingml::LineProperties>&, std::__1::optional<oox::drawingml::LineProperties> const&) Line | Count | Source | 173 | 9.33M | { | 174 | 9.33M | if( rSourceValue.has_value() ) | 175 | 1.93k | rDestValue = rSourceValue.value(); | 176 | 9.33M | } |
void oox::assignIfUsed<std::__1::pair<double, double> >(std::__1::optional<std::__1::pair<double, double> >&, std::__1::optional<std::__1::pair<double, double> > const&) Line | Count | Source | 173 | 8.50k | { | 174 | 8.50k | if( rSourceValue.has_value() ) | 175 | 18 | rDestValue = rSourceValue.value(); | 176 | 8.50k | } |
void oox::assignIfUsed<std::__1::pair<int, int> >(std::__1::optional<std::__1::pair<int, int> >&, std::__1::optional<std::__1::pair<int, int> > const&) Line | Count | Source | 173 | 2.83k | { | 174 | 2.83k | if( rSourceValue.has_value() ) | 175 | 1.41k | rDestValue = rSourceValue.value(); | 176 | 2.83k | } |
void oox::assignIfUsed<long>(std::__1::optional<long>&, std::__1::optional<long> const&) Line | Count | Source | 173 | 66.6M | { | 174 | 66.6M | if( rSourceValue.has_value() ) | 175 | 2.09k | rDestValue = rSourceValue.value(); | 176 | 66.6M | } |
void oox::assignIfUsed<model::RectangleAlignment>(std::__1::optional<model::RectangleAlignment>&, std::__1::optional<model::RectangleAlignment> const&) Line | Count | Source | 173 | 9.52M | { | 174 | 9.52M | if( rSourceValue.has_value() ) | 175 | 390 | rDestValue = rSourceValue.value(); | 176 | 9.52M | } |
|
177 | | |
178 | | |
179 | | /** Provides platform independent functions to convert from or to little-endian |
180 | | byte order, e.g. for reading data from or writing data to memory or a |
181 | | binary stream. |
182 | | |
183 | | On big-endian platforms, the byte order in the passed values is swapped, |
184 | | this can be used for converting big-endian to and from little-endian data. |
185 | | |
186 | | On little-endian platforms, the conversion functions are implemented empty, |
187 | | thus compilers should completely optimize away the function call. |
188 | | */ |
189 | | class ByteOrderConverter |
190 | | { |
191 | | public: |
192 | | #ifdef OSL_BIGENDIAN |
193 | | static void convertLittleEndian( sal_Int8& ) {} // present for usage in templates |
194 | | static void convertLittleEndian( sal_uInt8& ) {} // present for usage in templates |
195 | | static void convertLittleEndian( char16_t& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
196 | | static void convertLittleEndian( sal_Int16& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
197 | | static void convertLittleEndian( sal_uInt16& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
198 | | static void convertLittleEndian( sal_Int32& rnValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
199 | | static void convertLittleEndian( sal_uInt32& rnValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
200 | | static void convertLittleEndian( sal_Int64& rnValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
201 | | static void convertLittleEndian( sal_uInt64& rnValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rnValue ) ); } |
202 | | static void convertLittleEndian( float& rfValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rfValue ) ); } |
203 | | static void convertLittleEndian( double& rfValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rfValue ) ); } |
204 | | |
205 | | template< typename Type > |
206 | | inline static void convertLittleEndianArray( Type* pnArray, size_t nElemCount ); |
207 | | |
208 | | static void convertLittleEndianArray( sal_Int8*, size_t ) {} |
209 | | static void convertLittleEndianArray( sal_uInt8*, size_t ) {} |
210 | | |
211 | | #else |
212 | | template< typename Type > |
213 | 2.22M | static void convertLittleEndian( Type& ) {}void oox::ByteOrderConverter::convertLittleEndian<int>(int&) Line | Count | Source | 213 | 2.00M | static void convertLittleEndian( Type& ) {} |
void oox::ByteOrderConverter::convertLittleEndian<unsigned short>(unsigned short&) Line | Count | Source | 213 | 36.3k | static void convertLittleEndian( Type& ) {} |
Unexecuted instantiation: void oox::ByteOrderConverter::convertLittleEndian<signed char>(signed char&) void oox::ByteOrderConverter::convertLittleEndian<unsigned char>(unsigned char&) Line | Count | Source | 213 | 143k | static void convertLittleEndian( Type& ) {} |
Unexecuted instantiation: void oox::ByteOrderConverter::convertLittleEndian<short>(short&) void oox::ByteOrderConverter::convertLittleEndian<unsigned int>(unsigned int&) Line | Count | Source | 213 | 40.9k | static void convertLittleEndian( Type& ) {} |
void oox::ByteOrderConverter::convertLittleEndian<long>(long&) Line | Count | Source | 213 | 7 | static void convertLittleEndian( Type& ) {} |
Unexecuted instantiation: void oox::ByteOrderConverter::convertLittleEndian<float>(float&) Unexecuted instantiation: void oox::ByteOrderConverter::convertLittleEndian<double>(double&) |
214 | | |
215 | | template< typename Type > |
216 | 721 | static void convertLittleEndianArray( Type*, size_t ) {}void oox::ByteOrderConverter::convertLittleEndianArray<unsigned char>(unsigned char*, unsigned long) Line | Count | Source | 216 | 257 | static void convertLittleEndianArray( Type*, size_t ) {} |
void oox::ByteOrderConverter::convertLittleEndianArray<unsigned short>(unsigned short*, unsigned long) Line | Count | Source | 216 | 464 | static void convertLittleEndianArray( Type*, size_t ) {} |
Unexecuted instantiation: void oox::ByteOrderConverter::convertLittleEndianArray<char16_t>(char16_t*, unsigned long) |
217 | | |
218 | | #endif |
219 | | |
220 | | /** Writes a value to memory, while converting it to little-endian. |
221 | | @param pDstBuffer The memory buffer to write the value to. |
222 | | @param nValue The value to be written to memory in little-endian. |
223 | | */ |
224 | | template< typename Type > |
225 | | inline static void writeLittleEndian( void* pDstBuffer, Type nValue ); |
226 | | |
227 | | #ifdef OSL_BIGENDIAN |
228 | | private: |
229 | | inline static void swap2( sal_uInt8* pnData ); |
230 | | inline static void swap4( sal_uInt8* pnData ); |
231 | | inline static void swap8( sal_uInt8* pnData ); |
232 | | #endif |
233 | | }; |
234 | | |
235 | | |
236 | | template< typename Type > |
237 | | inline void ByteOrderConverter::writeLittleEndian( void* pDstBuffer, Type nValue ) |
238 | 2.00M | { |
239 | 2.00M | convertLittleEndian( nValue ); |
240 | 2.00M | memcpy( pDstBuffer, &nValue, sizeof( Type ) ); |
241 | 2.00M | } void oox::ByteOrderConverter::writeLittleEndian<unsigned int>(void*, unsigned int) Line | Count | Source | 238 | 5.28k | { | 239 | 5.28k | convertLittleEndian( nValue ); | 240 | 5.28k | memcpy( pDstBuffer, &nValue, sizeof( Type ) ); | 241 | 5.28k | } |
void oox::ByteOrderConverter::writeLittleEndian<int>(void*, int) Line | Count | Source | 238 | 2.00M | { | 239 | 2.00M | convertLittleEndian( nValue ); | 240 | 2.00M | memcpy( pDstBuffer, &nValue, sizeof( Type ) ); | 241 | 2.00M | } |
|
242 | | |
243 | | #ifdef OSL_BIGENDIAN |
244 | | template< typename Type > |
245 | | inline void ByteOrderConverter::convertLittleEndianArray( Type* pnArray, size_t nElemCount ) |
246 | | { |
247 | | for( Type* pnArrayEnd = pnArray + nElemCount; pnArray != pnArrayEnd; ++pnArray ) |
248 | | convertLittleEndian( *pnArray ); |
249 | | } |
250 | | |
251 | | inline void ByteOrderConverter::swap2( sal_uInt8* pnData ) |
252 | | { |
253 | | ::std::swap( pnData[ 0 ], pnData[ 1 ] ); |
254 | | } |
255 | | |
256 | | inline void ByteOrderConverter::swap4( sal_uInt8* pnData ) |
257 | | { |
258 | | ::std::swap( pnData[ 0 ], pnData[ 3 ] ); |
259 | | ::std::swap( pnData[ 1 ], pnData[ 2 ] ); |
260 | | } |
261 | | |
262 | | inline void ByteOrderConverter::swap8( sal_uInt8* pnData ) |
263 | | { |
264 | | ::std::swap( pnData[ 0 ], pnData[ 7 ] ); |
265 | | ::std::swap( pnData[ 1 ], pnData[ 6 ] ); |
266 | | ::std::swap( pnData[ 2 ], pnData[ 5 ] ); |
267 | | ::std::swap( pnData[ 3 ], pnData[ 4 ] ); |
268 | | } |
269 | | #endif |
270 | | |
271 | | |
272 | | } // namespace oox |
273 | | |
274 | | #endif |
275 | | |
276 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |