implementation changed to use boost::function instead of own

virtualizer


[SVN r22658]
This commit is contained in:
Pavol Droba
2004-04-18 18:36:35 +00:00
parent 2b30a1063b
commit d88e251f39
2 changed files with 17 additions and 75 deletions

View File

@ -10,70 +10,16 @@
#ifndef BOOST_STRING_FIND_ITERATOR_DETAIL_HPP
#define BOOST_STRING_FIND_ITERATOR_DETAIL_HPP
#include <boost/algorithm/string/config.hpp>
#include <boost/algorithm/string/iterator_range.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/function.hpp>
namespace boost {
namespace algorithm {
namespace detail {
// finder virtualizer -----------------------------------------------//
template<typename IteratorT>
struct virtual_finder
{
// typedefs
typedef IteratorT input_iterator_type;
typedef iterator_range<IteratorT> match_type;
// virtual destructor
virtual ~virtual_finder() {}
// clone
virtual virtual_finder* clone() const=0;
// operation
virtual match_type do_find(
input_iterator_type Begin,
input_iterator_type End ) const=0;
};
template<typename IteratorT, typename FinderT>
struct virtual_finder_typed : public virtual_finder<IteratorT>
{
// typedefs
typedef virtual_finder<IteratorT> base_type;
typedef BOOST_STRING_TYPENAME
base_type::input_iterator_type input_iterator_type;
typedef BOOST_STRING_TYPENAME
base_type::match_type match_type;
// constuction
virtual_finder_typed( FinderT Finder ) : m_Finder(Finder) {}
// clone
virtual_finder_typed* clone() const
{
return new virtual_finder_typed(m_Finder);
}
// operation
virtual match_type do_find(
input_iterator_type Begin,
input_iterator_type End ) const
{
return m_Finder(Begin,End);
}
private:
// Finder
FinderT m_Finder;
};
// find_iterator base -----------------------------------------------//
// Find iterator base
@ -84,40 +30,36 @@ namespace boost {
// typedefs
typedef IteratorT input_iterator_type;
typedef iterator_range<IteratorT> match_type;
typedef function2<
match_type,
input_iterator_type,
input_iterator_type> finder_type;
protected:
// Protected construction/destruction
// Default constructor
find_iterator_base() : m_pFinder(0) {};
find_iterator_base() {};
// Copy construction
find_iterator_base( const find_iterator_base& Other ) :
m_pFinder(0)
{
if ( Other.m_pFinder )
{
m_pFinder=Other.m_pFinder->clone();
}
}
m_Finder(Other.m_Finder) {}
// Constructor
template<typename FinderT>
find_iterator_base( FinderT Finder, int ) :
m_pFinder( new virtual_finder_typed<IteratorT,FinderT>(Finder) ) {}
m_Finder(Finder) {}
// Destructor
~find_iterator_base()
{
if (m_pFinder) delete m_pFinder;
}
~find_iterator_base() {}
// Find operation
match_type do_find(
input_iterator_type Begin,
input_iterator_type End ) const
{
if (m_pFinder)
if (!m_Finder.empty())
{
return m_pFinder->do_find(Begin,End);
return m_Finder(Begin,End);
}
else
{
@ -128,12 +70,12 @@ namespace boost {
// Check
bool is_null() const
{
return !m_pFinder;
return m_Finder.empty();
}
private:
// Finder
virtual_finder<IteratorT>* m_pFinder;
finder_type m_Finder;
};
} // namespace detail

View File

@ -154,7 +154,7 @@ namespace boost {
/*!
* Construct a find iterator to iterate through the specified collection
*/
template<typename CollectionT, typename FinderT>
template<typename CollectionT, typename FinderT>
inline find_iterator<
BOOST_STRING_TYPENAME result_iterator_of<CollectionT>::type>
make_find_iterator(
@ -304,7 +304,7 @@ namespace boost {
/*!
* Construct a split iterator to iterate through the specified collection
*/
template<typename CollectionT, typename FinderT>
template<typename CollectionT, typename FinderT>
inline split_iterator<
BOOST_STRING_TYPENAME result_iterator_of<CollectionT>::type>
make_split_iterator(