namespace comphelper
{ /** Search the given value within the given sequence, return the position of the first occurrence. Returns-1ifnothingfound.
*/ template <class T1, class T2> inline sal_Int32 findValue(const css::uno::Sequence<T1>& _rList, const T2& _rValue)
{ // at which position do I find the value? for (sal_Int32 i = 0; i < _rList.getLength(); ++i)
{ if (_rList[i] == _rValue) return i;
}
return -1;
}
/// concat several sequences template <class T, class... Ss> inline css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& rS1, const Ss&... rSn)
{ // unary fold to disallow empty parameter pack: at least have one sequence in rSn
css::uno::Sequence<T> aReturn(std::size(rS1) + (... + std::size(rSn)));
T* pReturn = std::copy(std::begin(rS1), std::end(rS1), aReturn.getArray());
(..., (pReturn = std::copy(std::begin(rSn), std::end(rSn), pReturn))); return aReturn;
}
/// concat additional elements from right sequence to left sequence /// /// be aware that this takes time O(|left| * |right|) template<typename T> inline css::uno::Sequence<T> combineSequences(
css::uno::Sequence<T> const & left, css::uno::Sequence<T> const & right)
{
sal_Int32 n1 = left.getLength();
css::uno::Sequence<T> ret(n1 + right.getLength()); //TODO: check for overflow auto pRet = ret.getArray();
std::copy_n(left.getConstArray(), n1, pRet);
sal_Int32 n2 = n1; for (sal_Int32 i = 0; i != right.getLength(); ++i) { bool found = false; for (sal_Int32 j = 0; j != n1; ++j) { if (right[i] == left[j]) {
found = true; break;
}
} if (!found) {
pRet[n2++] = right[i];
}
}
ret.realloc(n2); return ret;
}
/// remove a specified element from a sequences template<class T> inlinevoid removeElementAt(css::uno::Sequence<T>& _rSeq, sal_Int32 _nPos)
{
sal_Int32 nLength = _rSeq.getLength();
// this one does better type deduction, but does not allow us to copy into a different element type template < typename SrcType > inline css::uno::Sequence< typename SrcType::value_type > containerToSequence( const SrcType& i_Container )
{ return containerToSequence<typename SrcType::value_type, SrcType>(i_Container);
}
// this one does better type deduction, but does not allow us to copy into a different element type template < typename DstType > inline DstType sequenceToContainer( const css::uno::Sequence< typename DstType::value_type >& i_Sequence )
{ return DstType(i_Sequence.begin(), i_Sequence.end());
}
/** Copy from a Sequence into an existing container
Thispotentiallysavesaneedlessextracopyoperationover thewholecontainer,asitpassesthetargetobjectby reference.
@tplSrcType Sequenceelementtype.MustbeassignabletoSrcType's elements
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.