diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-08-02 16:51:14 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-08-02 16:51:14 +0000 |
commit | fe9dfe9725314d19a36228dac9279b56a42bbf5a (patch) | |
tree | 4eabc966cc79e770163fa954c75ad7253615af18 /comphelper | |
parent | 5ffab11bf748d69a485085b282723f07c4037b49 (diff) |
INTEGRATION: CWS insight01 (1.3.138); FILE MERGED
2004/05/28 10:01:23 oj 1.3.138.2: RESYNC: (1.3-1.4); FILE MERGED
2003/12/17 11:23:53 oj 1.3.138.1: #111075# new helper to iterate through a sequence
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/sequence.hxx | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/comphelper/inc/comphelper/sequence.hxx b/comphelper/inc/comphelper/sequence.hxx index 281469606a76..51e652476016 100644 --- a/comphelper/inc/comphelper/sequence.hxx +++ b/comphelper/inc/comphelper/sequence.hxx @@ -2,9 +2,9 @@ * * $RCSfile: sequence.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: kz $ $Date: 2004-07-30 15:34:56 $ + * last change: $Author: hr $ $Date: 2004-08-02 17:51:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -152,6 +152,90 @@ namespace comphelper _rSeq.realloc(nLength-1); } + //===================================================================== + //= iterating through sequences + //===================================================================== + class SAL_NO_VTABLE IIterator + { + public: + virtual sal_Bool hasMoreElements() const = 0; + virtual ::com::sun::star::uno::Any nextElement() = 0; + }; + /** a helper class for iterating through a sequence + */ + template <class TYPE> + class OSequenceIterator : public IIterator + { + const TYPE* m_pElements; + sal_Int32 m_nLen; + const TYPE* m_pCurrent; + + public: + /** contrcuct a sequence iterator from a sequence + */ + OSequenceIterator(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq); + /** contrcuct a sequence iterator from a Any containing a sequence + */ + OSequenceIterator(const ::com::sun::star::uno::Any& _rSequenceAny); + + virtual sal_Bool hasMoreElements() const; + virtual ::com::sun::star::uno::Any nextElement(); + + protected: + void construct(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq); + }; + + //--------------------------------------------------------------------- + template <class TYPE> + OSequenceIterator<TYPE>::OSequenceIterator(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq) + :m_pElements(NULL) + ,m_nLen(0) + ,m_pCurrent(NULL) + { + construct(_rSeq); + } + + //--------------------------------------------------------------------- + template <class TYPE> + OSequenceIterator<TYPE>::OSequenceIterator(const ::com::sun::star::uno::Any& _rSequenceAny) + :m_pElements(NULL) + ,m_nLen(0) + ,m_pCurrent(NULL) + { + ::com::sun::star::uno::Sequence< TYPE > aContainer; + #ifdef DBG_UTIL + sal_Bool bSuccess = + #endif + _rSequenceAny >>= aContainer; + #ifdef DBG_UTIL + OSL_ENSURE(bSuccess, "OSequenceIterator::OSequenceIterator: invalid Any!"); + #endif + construct(aContainer); + } + + //--------------------------------------------------------------------- + template <class TYPE> + void OSequenceIterator<TYPE>::construct(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq) + { + m_pElements = _rSeq.getConstArray(); + m_nLen = _rSeq.getLength(); + m_pCurrent = m_pElements; + } + + //--------------------------------------------------------------------- + template <class TYPE> + sal_Bool OSequenceIterator<TYPE>::hasMoreElements() const + { + return m_pCurrent - m_pElements < m_nLen; + } + + //--------------------------------------------------------------------- + template <class TYPE> + ::com::sun::star::uno::Any OSequenceIterator<TYPE>::nextElement() + { + return ::com::sun::star::uno::makeAny(*m_pCurrent++); + } + //------------------------------------------------------------------------- /** Copy from a plain C/C++ array into a Sequence |