2000-11-28 07:45:33 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
2008-04-11 00:47:13 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-11-28 07:45:33 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __FRAMEWORK_CLASSES_CHECKEDITERATOR_HXX_
|
|
|
|
#define __FRAMEWORK_CLASSES_CHECKEDITERATOR_HXX_
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// my own includes
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
#include <macros/debug.hxx>
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// interface includes
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// other includes
|
|
|
|
//_________________________________________________________________________________________________________________
|
2000-11-30 23:58:51 -06:00
|
|
|
#include <sal/types.h>
|
|
|
|
|
2000-11-28 07:45:33 -06:00
|
|
|
#ifndef __SGI_STL_ITERATOR
|
2001-02-12 06:12:34 -06:00
|
|
|
#include <iterator>
|
2000-11-28 07:45:33 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// namespace
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
namespace framework{
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// exported const
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// exported definitions
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
/*-************************************************************************************************************//**
|
|
|
|
@short implement a iterator which support 2 end states!
|
|
|
|
@descr For our search methods we need a "walking" iterator object with special functionality!
|
|
|
|
We must check for 3 different states of an iterator - normal position, exact end, after end.
|
|
|
|
It's neccessary to detect if we have not found a entry and must return our default or
|
|
|
|
default already returned and we must break loop!
|
|
|
|
see using in class FilterCache too for further informations!
|
|
|
|
|
|
|
|
@Attention If your wish to debug this inline code ...
|
|
|
|
under windows and msdev you can use "set ENVCFLAGS=/Ob0" to do that!
|
|
|
|
|
|
|
|
@implements -
|
|
|
|
@base -
|
|
|
|
|
|
|
|
@devstatus ready to use
|
2001-03-29 06:17:17 -06:00
|
|
|
@threadsafe no
|
2000-11-28 07:45:33 -06:00
|
|
|
*//*-*************************************************************************************************************/
|
|
|
|
|
2000-11-30 02:54:52 -06:00
|
|
|
template< class TContainer >
|
2000-11-28 07:45:33 -06:00
|
|
|
class CheckedIterator
|
|
|
|
{
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
// public methods
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
// constructor / destructor
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short standard constructor
|
2001-04-04 07:28:35 -05:00
|
|
|
@descr Set default values on members.
|
|
|
|
We set it internal to E_UNKNOWN to detect uninitialized instances of this class.
|
|
|
|
If we found one - we know: "We must call initialize first!"
|
2000-11-28 07:45:33 -06:00
|
|
|
|
|
|
|
@seealso -
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return -
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline CheckedIterator()
|
2002-07-29 02:22:14 -05:00
|
|
|
: m_eEndState ( E_UNKNOWN )
|
|
|
|
, m_pContainer( NULL )
|
2000-11-28 07:45:33 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
// interface methods
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short initialize instance with valid container
|
|
|
|
@descr Set new container at an instance of this class. The other member will set automaticly!
|
|
|
|
m_pPosition = first element in container
|
|
|
|
m_eEndState = BEFOREEND
|
|
|
|
|
|
|
|
@seealso -
|
|
|
|
|
2001-05-21 00:13:00 -05:00
|
|
|
@param "rContainer", must be a valid reference to an existing container.
|
2000-11-28 07:45:33 -06:00
|
|
|
@return -
|
|
|
|
|
|
|
|
@onerror An assertion is thrown.
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
2001-07-20 02:04:58 -05:00
|
|
|
inline void initialize( const TContainer& rContainer )
|
2000-11-28 07:45:33 -06:00
|
|
|
{
|
|
|
|
// Check incoming parameter. We don't accept all!
|
2001-05-21 00:13:00 -05:00
|
|
|
LOG_ASSERT2( &rContainer==NULL , "CheckedIterator::initialize()", "Invalid parameter detected!" )
|
2001-04-04 07:28:35 -05:00
|
|
|
LOG_ASSERT2( m_eEndState!=E_UNKNOWN , "CheckedIterator::initialize()", "Instance already initialized! Don't do it again." )
|
|
|
|
|
|
|
|
if( m_eEndState == E_UNKNOWN )
|
|
|
|
{
|
2010-01-06 07:14:21 -06:00
|
|
|
// Set new container and update other member.
|
2001-07-20 02:04:58 -05:00
|
|
|
m_pContainer = &rContainer ;
|
|
|
|
m_eEndState = E_BEFOREEND ;
|
|
|
|
m_pPosition = m_pContainer->begin();
|
2001-04-04 07:28:35 -05:00
|
|
|
}
|
2000-11-28 07:45:33 -06:00
|
|
|
}
|
|
|
|
|
2001-04-11 05:25:50 -05:00
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short set internal states to E_END
|
|
|
|
@descr Sometimes we need a "walking" check-iterator which is initialized with the END-state!
|
|
|
|
We need it to return one default value if no other ones exist ...
|
|
|
|
|
|
|
|
@seealso using in class FilterCache!
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return -
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline void setEnd()
|
|
|
|
{
|
2001-07-20 02:04:58 -05:00
|
|
|
m_pContainer = NULL ;
|
|
|
|
m_eEndState = E_END ;
|
2001-04-11 05:25:50 -05:00
|
|
|
}
|
|
|
|
|
2000-11-28 07:45:33 -06:00
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short set internal states to E_AFTEREND
|
|
|
|
@descr Sometimes we need a "walking" check-iterator which is initialized with AFTEREND-state!
|
|
|
|
We need it if we don't have a container but must prevent us against further searching!
|
|
|
|
|
|
|
|
@seealso using in class FilterCache!
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return -
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline void setAfterEnd()
|
|
|
|
{
|
2001-07-20 02:04:58 -05:00
|
|
|
m_pContainer = NULL ;
|
|
|
|
m_eEndState = E_AFTEREND ;
|
2000-11-28 07:45:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
2002-07-29 02:22:14 -05:00
|
|
|
@short reset this iterator
|
|
|
|
@descr It must be called on an already initialized iterator.
|
|
|
|
Means the member m_pContainer must be valid. Otherwhise the reaction
|
|
|
|
isn't defined.
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return -
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline void reset()
|
|
|
|
{
|
|
|
|
m_eEndState = E_UNKNOWN;
|
|
|
|
m_pContainer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
2000-11-28 07:45:33 -06:00
|
|
|
@short step to next element in container.
|
|
|
|
@descr If end of container is reached we change our internal "m_eEndState".
|
|
|
|
If end reached for first time; we set it to E_END;
|
|
|
|
If you step to next element again; we set it to E_AFTEREND.
|
|
|
|
So you have a chance to differ between "exact end" and "after end"!
|
|
|
|
|
|
|
|
@seealso method isEnd()
|
|
|
|
@seealso method isAfterEnd()
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return A reference to our changed object himself.
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline CheckedIterator& operator++()
|
|
|
|
{
|
|
|
|
// Warn programmer if he forget to initailize object!
|
2001-07-20 02:04:58 -05:00
|
|
|
LOG_ASSERT2( m_pContainer==NULL, "CheckedIterator::operator++()", "Object not initialized!" )
|
2000-11-28 07:45:33 -06:00
|
|
|
// Step to next element if any exist or set our end states.
|
|
|
|
switch( m_eEndState )
|
|
|
|
{
|
|
|
|
case E_BEFOREEND: {
|
2001-07-20 02:04:58 -05:00
|
|
|
++m_pPosition;
|
|
|
|
// If iterator reaching end ... set right state!
|
|
|
|
if( m_pPosition == m_pContainer->end() )
|
2000-11-28 07:45:33 -06:00
|
|
|
{
|
|
|
|
m_eEndState = E_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_END : {
|
2001-07-20 02:04:58 -05:00
|
|
|
// Set state only ... iterator already points to end of container!
|
2000-11-28 07:45:33 -06:00
|
|
|
m_eEndState = E_AFTEREND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-04-04 07:28:35 -05:00
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short return true if internal iterator was not initialized before
|
|
|
|
@descr These will be true, if use start a new search by using these iterator mechanism!
|
|
|
|
|
|
|
|
@seealso class FilterCache
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return True if internalk state E_UNKNOWN - false otherwise.
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline sal_Bool isUninitialized()
|
|
|
|
{
|
2001-04-11 05:25:50 -05:00
|
|
|
return( m_eEndState == E_UNKNOWN );
|
2001-04-04 07:28:35 -05:00
|
|
|
}
|
|
|
|
|
2000-11-28 07:45:33 -06:00
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short return true if internal iterator reached end of container
|
|
|
|
@descr These will be true if you step to the end of internal container.
|
|
|
|
|
|
|
|
@seealso method isAfterEnd()
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return True if end reached; false otherwise.
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline sal_Bool isEnd()
|
|
|
|
{
|
|
|
|
// Is true if one end state is set!
|
|
|
|
return (
|
2000-11-30 04:07:51 -06:00
|
|
|
( m_eEndState == E_END ) ||
|
2000-11-28 07:45:33 -06:00
|
|
|
( m_eEndState == E_AFTEREND )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short return true if you call operator++ again and end already reached
|
|
|
|
@descr These indicate, that end already reached but you call operator++ again and again!
|
|
|
|
|
|
|
|
@seealso method isEnd()
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return True if end multiple reached; false otherwise.
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
|
|
|
inline sal_Bool isAfterEnd()
|
|
|
|
{
|
|
|
|
// Is true only, if special end state is set!
|
|
|
|
return( m_eEndState == E_AFTEREND );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-****************************************************************************************************//**
|
|
|
|
@short support readonly access to container entry
|
|
|
|
@descr Use it to get the value of current container item.
|
|
|
|
|
|
|
|
@seealso -
|
|
|
|
|
|
|
|
@param -
|
|
|
|
@return A reference to value of container entry.
|
|
|
|
|
|
|
|
@onerror -
|
|
|
|
*//*-*****************************************************************************************************/
|
|
|
|
|
2000-12-15 07:48:10 -06:00
|
|
|
inline typename TContainer::const_iterator getEntry()
|
2000-11-28 07:45:33 -06:00
|
|
|
{
|
|
|
|
// Warn programmer if he forget to initialize these object ...
|
2001-07-20 02:04:58 -05:00
|
|
|
LOG_ASSERT2( m_pContainer==NULL, "CheckedIterator::getEntry()", "Object not initialized!" )
|
2000-11-28 07:45:33 -06:00
|
|
|
// or try to read a non existing element!
|
2001-07-20 02:04:58 -05:00
|
|
|
LOG_ASSERT2( m_eEndState!=E_BEFOREEND, "CheckedIterator::getEntry()", "Wrong using of class detected!" )
|
2000-11-30 02:54:52 -06:00
|
|
|
|
2001-07-20 02:04:58 -05:00
|
|
|
return m_pPosition;
|
2000-11-28 07:45:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
// private member
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2001-04-04 07:28:35 -05:00
|
|
|
// These enum defines our four states for an iterator position in curent container.
|
|
|
|
enum EEndState
|
|
|
|
{
|
|
|
|
E_UNKNOWN ,
|
|
|
|
E_BEFOREEND ,
|
|
|
|
E_END ,
|
|
|
|
E_AFTEREND
|
|
|
|
};
|
2000-11-28 07:45:33 -06:00
|
|
|
|
2001-07-20 02:04:58 -05:00
|
|
|
const TContainer* m_pContainer ; // pointer to current container
|
|
|
|
EEndState m_eEndState ; // "position state" of iterator!
|
2001-07-23 04:07:13 -05:00
|
|
|
typename TContainer::const_iterator m_pPosition ; // point to actual element in container
|
2000-11-28 07:45:33 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
|
|
|
|
#endif // #ifndef __FRAMEWORK_CLASSES_CHECKEDITERATOR_HXX_
|