20 #ifndef INCLUDED_OOX_HELPER_HELPER_HXX
21 #define INCLUDED_OOX_HELPER_HELPER_HXX
29 #include <osl/endian.h>
30 #include <rtl/math.hxx>
43 template<
typename T> constexpr std::make_unsigned_t<T>
make_unsigned(T value) {
44 if constexpr (std::is_signed_v<T>) {
55 #define STATIC_ARRAY_SELECT( array, index, def ) \
56 ((detail::make_unsigned(index) < SAL_N_ELEMENTS(array)) ? ((array)[static_cast<size_t>(index)]) : (def))
108 template<
typename ReturnType,
typename Type >
111 return static_cast< ReturnType
>( ::std::clamp( nValue, nMin, nMax ) );
114 template<
typename ReturnType,
typename Type >
117 static_assert(::std::numeric_limits< Type >::is_integer,
"is integer");
118 Type nInterval = nEnd - nBegin;
119 Type nCount = (nValue < nBegin) ? -((nBegin - nValue - 1) / nInterval + 1) : ((nValue - nBegin) / nInterval);
120 return static_cast< ReturnType
>( nValue - nCount * nInterval );
123 template<
typename ReturnType >
126 double fInterval = fEnd - fBegin;
127 double fCount = (fValue < fBegin) ? -(::rtl::math::approxFloor( (fBegin - fValue - 1.0) / fInterval ) + 1.0) : ::rtl::math::approxFloor( (fValue - fBegin) / fInterval );
128 return static_cast< ReturnType
>( fValue - fCount * fInterval );
134 template<
typename Type >
137 return (nBitField & nMask) != 0;
141 template<
typename ReturnType,
typename Type >
144 return getFlag( nBitField, nMask ) ? nSet : nUnset;
154 template<
typename ReturnType,
typename Type >
157 sal_uInt64 nMask = 1; nMask <<= nBitCount; --nMask;
158 return static_cast< ReturnType
>( nMask & (nBitField >> nStartBit) );
164 template<
typename Type >
167 if( bSet ) ornBitField |= nMask;
else ornBitField &= ~nMask;
173 template<
typename Type >
220 static void convertLittleEndian( char16_t& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
221 static void convertLittleEndian( sal_Int16& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
222 static void convertLittleEndian( sal_uInt16& rnValue ) { swap2( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
223 static void convertLittleEndian( sal_Int32& rnValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
224 static void convertLittleEndian( sal_uInt32& rnValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
225 static void convertLittleEndian( sal_Int64& rnValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
226 static void convertLittleEndian( sal_uInt64& rnValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rnValue ) ); }
227 static void convertLittleEndian(
float& rfValue ) { swap4( reinterpret_cast< sal_uInt8* >( &rfValue ) ); }
228 static void convertLittleEndian(
double& rfValue ) { swap8( reinterpret_cast< sal_uInt8* >( &rfValue ) ); }
230 template<
typename Type >
237 template<
typename Type >
240 template<
typename Type >
249 template<
typename Type >
254 inline static void swap2(
sal_uInt8* pnData );
255 inline static void swap4(
sal_uInt8* pnData );
256 inline static void swap8(
sal_uInt8* pnData );
261 template<
typename Type >
265 memcpy( pDstBuffer, &nValue,
sizeof(
Type ) );
269 template<
typename Type >
272 for(
Type* pnArrayEnd = pnArray + nElemCount; pnArray != pnArrayEnd; ++pnArray )
276 inline void ByteOrderConverter::swap2(
sal_uInt8* pnData )
278 ::std::swap( pnData[ 0 ], pnData[ 1 ] );
281 inline void ByteOrderConverter::swap4(
sal_uInt8* pnData )
283 ::std::swap( pnData[ 0 ], pnData[ 3 ] );
284 ::std::swap( pnData[ 1 ], pnData[ 2 ] );
287 inline void ByteOrderConverter::swap8(
sal_uInt8* pnData )
289 ::std::swap( pnData[ 0 ], pnData[ 7 ] );
290 ::std::swap( pnData[ 1 ], pnData[ 6 ] );
291 ::std::swap( pnData[ 2 ], pnData[ 5 ] );
292 ::std::swap( pnData[ 3 ], pnData[ 4 ] );
Provides platform independent functions to convert from or to little-endian byte order, e.g.
const sal_Int16 API_LINE_THIN
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
const sal_Int16 API_LINE_HAIR
OptValue(const Type &rValue)
const sal_Int16 API_LINE_SOLID
const sal_uInt32 UNSIGNED_RGB_TRANSPARENT
Transparent color for unsigned int32 places.
const sal_uInt8 WINDOWS_CHARSET_APPLE_ROMAN
const sal_Int16 API_LINE_MEDIUM
bool operator==(const OptValue &rValue) const
const sal_uInt8 WINDOWS_CHARSET_VIETNAMESE
const sal_Int16 API_LINE_THICK
const sal_Int16 API_ESCAPE_SUPERSCRIPT
Superscript: raise characters automatically (magic value 101).
OptValue(bool bHasValue, const Type &rValue)
ReturnType extractValue(Type nBitField, sal_uInt8 nStartBit, sal_uInt8 nBitCount)
Extracts a value from a bit field.
const sal_Int16 API_ESCAPE_NONE
No escapement.
const sal_Int8 API_ESCAPEHEIGHT_NONE
Relative character height if not escaped.
void set(const Type &rValue)
const sal_uInt8 WINDOWS_CHARSET_EASTERN
const sal_uInt8 WINDOWS_CHARSET_JOHAB
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
const sal_uInt8 WINDOWS_CHARSET_TURKISH
bool getFlag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
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_HANGEUL
const sal_Int16 API_LINE_DASHED
const sal_uInt8 WINDOWS_CHARSET_SYMBOL
void assignIfUsed(const OptValue &rValue)
const sal_uInt8 WINDOWS_CHARSET_BIG5
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const sal_uInt8 WINDOWS_CHARSET_SHIFTJIS
const sal_Int16 API_LINE_DOTTED
const sal_Int16 API_ESCAPE_SUBSCRIPT
Subscript: lower characters automatically (magic value -101).
ReturnType getLimitedValue(Type nValue, Type nMin, Type nMax)
const ::Color API_RGB_BLACK(0x000000)
Black color for API calls.
static void writeLittleEndian(void *pDstBuffer, Type nValue)
Writes a value to memory, while converting it to little-endian.
static void convertLittleEndianArray(Type *, size_t)
const sal_uInt8 WINDOWS_CHARSET_HEBREW
const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
Relative character height if escaped.
const sal_uInt8 WINDOWS_CHARSET_THAI
const sal_uInt8 WINDOWS_CHARSET_RUSSIAN
const sal_uInt8 WINDOWS_CHARSET_BALTIC
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_uInt8 WINDOWS_CHARSET_GB2312
const sal_uInt8 WINDOWS_CHARSET_ARABIC
ReturnType getIntervalValue(Type nValue, Type nBegin, Type nEnd)
const sal_Int16 API_FINE_LINE_DASHED
const sal_Int16 API_LINE_NONE
const sal_uInt8 WINDOWS_CHARSET_OEM
const sal_uInt8 WINDOWS_CHARSET_GREEK
const ::Color API_RGB_GRAY(0x808080)
Gray color for API calls.
Optional value, similar to ::std::optional<>, with convenience accessors.
ReturnType getDoubleIntervalValue(double fValue, double fBegin, double fEnd)
OptValue & operator=(const Type &rValue)
const sal_uInt8 WINDOWS_CHARSET_ANSI
constexpr std::make_unsigned_t< T > make_unsigned(T value)
const ::Color API_RGB_WHITE(0xFFFFFF)
White color for API calls.
bool differsFrom(const Type &rValue) const
static void convertLittleEndian(Type &)
bool m_bDetectedRangeSegmentation false