////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2008
//
// The following code is supplied "as-is" and
// is given without warranty of any kind.
// It may be freely distributed and used.
// The user holds author blameless from any complications or
// problems that may arise from the use of this code.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// $Workfile: $ created: 04/05/2008 11:52
////////////////////////////////////////////////////////////////////////////////
// $Revision: $ $Modtime: $
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Author: steveb
//
// History:
//
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include < boost/iterator/iterator_facade.hpp >
/*
//
// Iterator skeleton
//
template < typename _Type >
class mfc_iterator :
public boost::iterator_facade < mfc_iterator, _Type, boost::forward_traversal_tag
// boost::bidirectional_traversal_tag
>
{
public:
///////////////////////////////////////////////
/// TODO: Write begin code logic here
///////////////////////////////////////////////
mfc_iterator & begin()
{
//....
return *this;
}
///////////////////////////////////////////////
/// just call default private contructor.
/// end is a state when everything in this iterator is set to NULL
/// or whatever variables values you choose for that
///////////////////////////////////////////////
mfc_iterator end()
{
return mfc_iterator ();
}
private:
friend class boost::iterator_core_access;
///////////////////////////////////////////////
/// TODO: Write end() constructor here. See end()
///////////////////////////////////////////////
mfc_iterator ():m_node(0)
{}
///////////////////////////////////////////////
/// TODO: Write increment code here
///////////////////////////////////////////////
void increment()
{
//....
}
///////////////////////////////////////////////
/// TODO: Write decrement code here
///////////////////////////////////////////////
void decrement()
{
//....
}
///////////////////////////////////////////////
/// TODO white compare criteria here
///////////////////////////////////////////////
bool equal(mfc_cview_iterator const & other) const
{
//....
}
///////////////////////////////////////////////
///
///////////////////////////////////////////////
_Type& dereference() const
{
return *m_node;
}
_Type* m_node;
};
*/
template < typename _Type, typename _Tcontainer = CArray<_Type>>
class mfc_carray_iterator :
public boost::iterator_facade < mfc_carray_iterator < _Type, _Tcontainer >, _Type, boost::bidirectional_traversal_tag >
{
_Type m_node; // element type
_Tcontainer* m_pCont; // Pointer to underlying CArray container
INT_PTR m_nIndex; // current CArray index
public:
///////////////////////////////////////////////
///
///////////////////////////////////////////////
explicit mfc_carray_iterator(_Tcontainer* pCont)
: m_node(0)
, m_nIndex(0)
, m_pCont(pCont)
{}
///////////////////////////////////////////////
/// Point to first element in CArray
///////////////////////////////////////////////
mfc_carray_iterator& begin()
{
m_nIndex = 0;
if(m_pCont->GetSize() == 0) // safety checks
*this = end();
else
m_node = m_pCont->GetAt(m_nIndex);
return *this;
}
///////////////////////////////////////////////
/// just call private conrtuctor
///////////////////////////////////////////////
mfc_carray_iterator end()
{
return mfc_carray_iterator();
}
private:
friend class boost::iterator_core_access;
///////////////////////////////////////////////
/// constructs end()
///////////////////////////////////////////////
mfc_carray_iterator():
m_node(0)
, m_nIndex(0)
, m_pCont(0)
{
}
///////////////////////////////////////////////
/// Increment CArray
///////////////////////////////////////////////
void increment()
{
// CArray specific increment code
m_nIndex++;
if(m_nIndex >= m_pCont->GetSize())// safety checks
{
*this = end();
return;
}
m_node = m_pCont->GetAt(m_nIndex);
}
///////////////////////////////////////////////
/// Decrement CArray
///////////////////////////////////////////////
void decrement()
{
// CArray specific decrement code
m_nIndex--;
if(m_nIndex >= m_pCont->GetSize()) // safety checks
return;
m_node = m_pCont->GetAt(m_nIndex);
}
///////////////////////////////////////////////
///
///////////////////////////////////////////////
bool equal(mfc_carray_iterator const& other) const
{
return m_pCont == other.m_pCont && m_node == other.m_node && m_nIndex == other.m_nIndex;
}
_Type& dereference() const
{
return (_Type&) m_node;
}
};
//
// CList iterator
//
#include < boost/iterator/iterator_facade.hpp >
template < typename _Type, typename _Tcontainer = CList<_Type> >
class mfc_clist_iterator :
public boost::iterator_facade < mfc_clist_iterator < _Type, _Tcontainer >, _Type, boost::bidirectional_traversal_tag >
{
_Type m_node; // element type
_Tcontainer* m_pCont; // Pointer to underlying CList container
POSITION m_pos; // current CList position
public:
///////////////////////////////////////////////
///
///////////////////////////////////////////////
explicit mfc_clist_iterator(_Tcontainer* pCont)
: m_node(0)
, m_pos(0)
, m_pCont(pCont)
{}
///////////////////////////////////////////////
/// Point to first element in CList
///////////////////////////////////////////////
mfc_clist_iterator& begin()
{
m_pos = m_pCont->GetHeadPosition();
if(m_pos == 0) // safety checks
*this = end();
else
m_node = m_pCont->GetNext(m_pos);
return *this;
}
///////////////////////////////////////////////
/// just call private constructor
///////////////////////////////////////////////
mfc_clist_iterator end()
{
return mfc_clist_iterator();
}
private:
friend class boost::iterator_core_access;
///////////////////////////////////////////////
/// constructs end()
///////////////////////////////////////////////
mfc_clist_iterator():
m_node(0)
, m_pos(0)
, m_pCont(0)
{
}
///////////////////////////////////////////////
/// Increment CList
///////////////////////////////////////////////
void increment()
{
if(m_pos == NULL)// safety checks
{
*this = end();
return;
}
m_node = m_pCont->GetNext(m_pos);
}
///////////////////////////////////////////////
/// Decrement CList
///////////////////////////////////////////////
void decrement()
{
if(m_pos == NULL)// safety checks
{
*this = end();
return;
}
m_node = m_pCont->GetPrev(m_pos);
}
///////////////////////////////////////////////
///
///////////////////////////////////////////////
bool equal(mfc_clist_iterator const & other) const
{
return m_pCont == other.m_pCont && m_node == other.m_node && m_po
没有合适的资源?快使用搜索试试~ 我知道了~
How to wrap an MFC collection into an STL compliant iterator
共1个文件
h:1个
需积分: 9 3 下载量 17 浏览量
2008-12-27
12:09:24
上传
评论
收藏 32KB RAR 举报
温馨提示
How to wrap an MFC collection into an STL compliant iterator with the Boost iterator_facade。
资源推荐
资源详情
资源评论
收起资源包目录
How to wrap an MFC collection into an STL compliant iterator with the Boost iterator_facade.rar (1个子文件)
mfc_iters.h 12KB
共 1 条
- 1
资源评论
领君2018
- 粉丝: 204
- 资源: 1527
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功