20#ifndef INCLUDED_OOX_HELPER_HELPER_HXX
21#define INCLUDED_OOX_HELPER_HELPER_HXX
30#include <osl/endian.h>
31#include <rtl/math.hxx>
45template<
typename T>
constexpr std::make_unsigned_t<T>
make_unsigned(T value) {
46 if constexpr (std::is_signed_v<T>) {
57#define STATIC_ARRAY_SELECT( array, index, def ) \
58 ((detail::make_unsigned(index) < SAL_N_ELEMENTS(array)) ? ((array)[static_cast<size_t>(index)]) : (def))
110template<
typename ReturnType,
typename Type >
113 return static_cast< ReturnType
>( ::std::clamp(
nValue, nMin, nMax ) );
116template<
typename ReturnType,
typename Type >
119 static_assert(::std::numeric_limits< Type >::is_integer,
"is integer");
120 Type nInterval = nEnd - nBegin;
122 return static_cast< ReturnType
>(
nValue -
nCount * nInterval );
125template<
typename ReturnType >
128 double fInterval = fEnd - fBegin;
129 double fCount = (fValue < fBegin) ? -(::rtl::math::approxFloor( (fBegin - fValue - 1.0) / fInterval ) + 1.0) : ::rtl::math::approxFloor( (fValue - fBegin) / fInterval );
130 return static_cast< ReturnType
>( fValue - fCount * fInterval );
136template<
typename Type >
139 return (nBitField & nMask) != 0;
143template<
typename ReturnType,
typename Type >
146 return getFlag( nBitField, nMask ) ? nSet : nUnset;
156template<
typename ReturnType,
typename Type >
159 sal_uInt64 nMask = 1; nMask <<=
nBitCount; --nMask;
160 return static_cast< ReturnType
>( nMask & (nBitField >> nStartBit) );
166template<
typename Type >
169 if( bSet ) ornBitField |= nMask;
else ornBitField &= ~nMask;
173template<
typename Type >
174void assignIfUsed( std::optional<Type>& rDestValue,
const std::optional<Type>& rSourceValue )
176 if( rSourceValue.has_value() )
177 rDestValue = rSourceValue.value();
207 template<
typename Type >
214 template<
typename Type >
217 template<
typename Type >
226 template<
typename Type >
231 inline static void swap2(
sal_uInt8* pnData );
232 inline static void swap4(
sal_uInt8* pnData );
233 inline static void swap8(
sal_uInt8* pnData );
238template<
typename Type >
242 memcpy( pDstBuffer, &
nValue,
sizeof(
Type ) );
246template<
typename Type >
249 for(
Type* pnArrayEnd = pnArray + nElemCount; pnArray != pnArrayEnd; ++pnArray )
253inline void ByteOrderConverter::swap2(
sal_uInt8* pnData )
255 ::std::swap( pnData[ 0 ], pnData[ 1 ] );
258inline void ByteOrderConverter::swap4(
sal_uInt8* pnData )
260 ::std::swap( pnData[ 0 ], pnData[ 3 ] );
261 ::std::swap( pnData[ 1 ], pnData[ 2 ] );
264inline void ByteOrderConverter::swap8(
sal_uInt8* pnData )
266 ::std::swap( pnData[ 0 ], pnData[ 7 ] );
267 ::std::swap( pnData[ 1 ], pnData[ 6 ] );
268 ::std::swap( pnData[ 2 ], pnData[ 5 ] );
269 ::std::swap( pnData[ 3 ], pnData[ 4 ] );
Provides platform independent functions to convert from or to little-endian byte order,...
static void convertLittleEndianArray(Type *, size_t)
static void convertLittleEndian(Type &)
static void writeLittleEndian(void *pDstBuffer, Type nValue)
Writes a value to memory, while converting it to little-endian.
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
constexpr std::make_unsigned_t< T > make_unsigned(T value)
const sal_Int16 API_ESCAPE_SUBSCRIPT
Subscript: lower characters automatically (magic value -101).
const sal_uInt8 WINDOWS_CHARSET_VIETNAMESE
void assignIfUsed(std::optional< Type > &rDestValue, const std::optional< Type > &rSourceValue)
const sal_uInt8 WINDOWS_CHARSET_ANSI
const sal_Int16 API_LINE_MEDIUM
const sal_uInt8 WINDOWS_CHARSET_BALTIC
const sal_uInt32 UNSIGNED_RGB_TRANSPARENT
Transparent color for unsigned int32 places.
ReturnType getFlagValue(Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset)
Returns nSet, if at least one bit of nMask is set in nBitField, otherwise nUnset.
const sal_Int16 API_ESCAPE_NONE
No escapement.
const sal_uInt8 WINDOWS_CHARSET_HEBREW
const sal_uInt8 WINDOWS_CHARSET_GB2312
const sal_Int16 API_LINE_DOTTED
const ::Color API_RGB_WHITE(0xFFFFFF)
White color for API calls.
void setFlag(Type &ornBitField, Type nMask, bool bSet=true)
Sets or clears (according to bSet) all set bits of nMask in ornBitField.
const sal_uInt8 WINDOWS_CHARSET_SHIFTJIS
const sal_uInt8 WINDOWS_CHARSET_TURKISH
const ::Color API_RGB_GRAY(0x808080)
Gray color for API calls.
const sal_Int16 API_LINE_NONE
const sal_uInt8 WINDOWS_CHARSET_JOHAB
const sal_Int16 API_LINE_THICK
const sal_uInt8 WINDOWS_CHARSET_OEM
const sal_Int16 API_LINE_THIN
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
ReturnType getIntervalValue(Type nValue, Type nBegin, Type nEnd)
const sal_Int16 API_LINE_SOLID
const ::Color API_RGB_BLACK(0x000000)
Black color for API calls.
bool getFlag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
const sal_uInt8 WINDOWS_CHARSET_APPLE_ROMAN
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
const sal_uInt8 WINDOWS_CHARSET_HANGEUL
const sal_uInt8 WINDOWS_CHARSET_ARABIC
const sal_uInt8 WINDOWS_CHARSET_THAI
const sal_Int16 API_FINE_LINE_DASHED
const sal_Int16 API_LINE_DASHED
const sal_Int8 API_ESCAPEHEIGHT_NONE
Relative character height if not escaped.
const sal_Int16 API_ESCAPE_SUPERSCRIPT
Superscript: raise characters automatically (magic value 101).
const sal_Int16 API_LINE_HAIR
const sal_uInt8 WINDOWS_CHARSET_BIG5
const sal_uInt8 WINDOWS_CHARSET_SYMBOL
const sal_uInt8 WINDOWS_CHARSET_GREEK
ReturnType extractValue(Type nBitField, sal_uInt8 nStartBit, sal_uInt8 nBitCount)
Extracts a value from a bit field.
const sal_uInt8 WINDOWS_CHARSET_EASTERN
const sal_uInt8 WINDOWS_CHARSET_RUSSIAN
ReturnType getLimitedValue(Type nValue, Type nMin, Type nMax)
const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
Relative character height if escaped.
ReturnType getDoubleIntervalValue(double fValue, double fBegin, double fEnd)