20#ifndef INCLUDED_OOX_HELPER_CONTAINERHELPER_HXX
21#define INCLUDED_OOX_HELPER_CONTAINERHELPER_HXX
26#include <com/sun/star/uno/Reference.hxx>
27#include <com/sun/star/uno/Sequence.hxx>
29#include <rtl/ustring.hxx>
33 namespace container {
class XNameAccess; }
34 namespace container {
class XNameContainer; }
35 namespace uno {
class Any; }
84template<
typename Type >
88 typedef ::std::vector< Type > container_type;
89 typedef typename container_type::value_type value_type;
90 typedef typename container_type::pointer pointer;
91 typedef typename container_type::reference reference;
92 typedef typename container_type::const_reference const_reference;
93 typedef typename container_type::size_type size_type;
94 typedef typename container_type::iterator iterator;
95 typedef typename container_type::const_iterator const_iterator;
98 explicit Matrix( size_type nWidth, size_type nHeight ) { resize( nWidth, nHeight ); }
99 explicit Matrix( size_type nWidth, size_type nHeight, const_reference rData ) { resize( nWidth, nHeight, rData ); }
101 bool empty()
const {
return maData.empty(); }
102 size_type size()
const {
return maData.size(); }
103 size_type width()
const {
return mnWidth; }
104 size_type height()
const {
return empty() ? 0 : (size() / width()); }
106 void clear() { resize( 0, 0 ); }
107 void resize( size_type nWidth, size_type nHeight ) { mnWidth = nWidth; maData.resize( nWidth * nHeight ); }
108 void resize( size_type nWidth, size_type nHeight, const_reference rData ) { mnWidth = nWidth; maData.resize( nWidth * nHeight, rData ); }
110 iterator at( size_type nX, size_type nY ) {
return maData.begin() + mnWidth * nY + nX; }
111 const_iterator at( size_type nX, size_type nY )
const {
return maData.begin() + mnWidth * nY + nX; }
113 reference operator()( size_type nX, size_type nY ) {
return *at( nX, nY ); }
114 const_reference operator()( size_type nX, size_type nY )
const {
return *at( nX, nY ); }
116 iterator begin() {
return maData.begin(); }
117 const_iterator begin()
const {
return maData.begin(); }
118 iterator end() {
return maData.end(); }
119 const_iterator end()
const {
return maData.end(); }
121 iterator row_begin( size_type nY ) {
return at( 0, nY ); }
122 const_iterator row_begin( size_type nY )
const {
return at( 0, nY ); }
123 iterator row_end( size_type nY ) {
return at( mnWidth, nY ); }
124 const_iterator row_end( size_type nY )
const {
return at( mnWidth, nY ); }
126 reference row_front( size_type nY ) {
return (*
this)( 0, nY ); }
127 const_reference row_front( size_type nY )
const {
return (*
this)( 0, nY ); }
130 container_type maData;
150 static OUString getUnusedName(
151 const css::uno::Reference< css::container::XNameAccess >& rxNameAccess,
152 const OUString& rSuggestedName,
166 static bool insertByName(
167 const css::uno::Reference< css::container::XNameContainer >& rxNameContainer,
168 const OUString& rName,
169 const css::uno::Any& rObject );
193 static OUString insertByUnusedName(
194 const css::uno::Reference< css::container::XNameContainer >& rxNameContainer,
195 const OUString& rSuggestedName,
197 const css::uno::Any& rObject );
203 template<
typename VectorType >
204 static const typename VectorType::value_type*
205 getVectorElement(
const VectorType& rVector, sal_Int32
nIndex );
209 template<
typename VectorType >
210 static typename VectorType::value_type*
211 getVectorElementAccess( VectorType& rVector, sal_Int32
nIndex );
215 template<
typename VectorType >
216 static const typename VectorType::value_type&
217 getVectorElement(
const VectorType& rVector, sal_Int32
nIndex,
const typename VectorType::value_type& rDefault );
221 template<
typename MapType >
222 static const typename MapType::mapped_type*
223 getMapElement(
const MapType& rMap,
const typename MapType::key_type& rKey );
227 template<
typename MapType >
228 static const typename MapType::mapped_type&
229 getMapElement(
const MapType& rMap,
const typename MapType::key_type& rKey,
const typename MapType::mapped_type& rDefault );
239 template<
typename MatrixType >
240 static css::uno::Sequence< css::uno::Sequence< typename MatrixType::value_type > >
241 matrixToSequenceSequence(
const MatrixType& rMatrix );
245template<
typename VectorType >
248 return ((0 <=
nIndex) && (
static_cast< size_t >(
nIndex ) < rVector.size())) ? &rVector[
static_cast< size_t >(
nIndex ) ] :
nullptr;
251template<
typename VectorType >
254 return ((0 <=
nIndex) && (
static_cast< size_t >(
nIndex ) < rVector.size())) ? &rVector[
static_cast< size_t >(
nIndex ) ] :
nullptr;
257template<
typename VectorType >
260 return ((0 <=
nIndex) && (
static_cast< size_t >(
nIndex ) < rVector.size())) ? rVector[
static_cast< size_t >(
nIndex ) ] : rDefault;
263template<
typename MapType >
266 typename MapType::const_iterator aIt = rMap.find( rKey );
267 return (aIt == rMap.end()) ? nullptr : &aIt->second;
270template<
typename MapType >
271 const typename MapType::mapped_type&
ContainerHelper::getMapElement(
const MapType& rMap,
const typename MapType::key_type& rKey,
const typename MapType::mapped_type& rDefault )
273 typename MapType::const_iterator aIt = rMap.find( rKey );
274 return (aIt == rMap.end()) ? rDefault : aIt->second;
277template<
typename MatrixType >
280 typedef typename MatrixType::value_type
ValueType;
281 css::uno::Sequence< css::uno::Sequence< ValueType > >
aSeq;
282 if( !rMatrix.empty() )
284 aSeq.realloc(
static_cast< sal_Int32
>( rMatrix.height() ) );
285 auto pSeq =
aSeq.getArray();
286 for(
size_t nRow = 0, nHeight = rMatrix.height(); nRow < nHeight; ++nRow )
287 pSeq[
static_cast< sal_Int32
>( nRow ) ] =
288 css::uno::Sequence< ValueType >( &rMatrix.row_front( nRow ),
static_cast< sal_Int32
>( rMatrix.width() ) );
Static helper functions for improved API container handling.
static VectorType::value_type * getVectorElementAccess(VectorType &rVector, sal_Int32 nIndex)
Returns the pointer to an existing element of the passed vector, or a null pointer,...
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
Returns the pointer to an existing element of the passed map, or a null pointer, if an element with t...
static css::uno::Sequence< css::uno::Sequence< typename MatrixType::value_type > > matrixToSequenceSequence(const MatrixType &rMatrix)
Creates a UNO sequence of sequences from a matrix with copies of all elements.
static const VectorType::value_type * getVectorElement(const VectorType &rVector, sal_Int32 nIndex)
Returns the pointer to an existing element of the passed vector, or a null pointer,...
An ordered list of value ranges.
const ValueRangeVector & getRanges() const
Returns the ordered list of all value ranges.
ValueRangeVector maRanges
Sequence< sal_Int8 > aSeq
::std::vector< ValueRange > ValueRangeVector
A range of signed 32-bit integer values.
bool operator!=(const ValueRange &rRange) const
ValueRange(sal_Int32 nFirst, sal_Int32 nLast)
bool contains(const ValueRange &rRange) const
ValueRange(sal_Int32 nValue)
bool intersects(const ValueRange &rRange) const
bool operator==(const ValueRange &rRange) const