Click here to Skip to main content
15,891,864 members
Articles / Desktop Programming / WTL

Boost.Range support for ATL/WTL CString

Rate me:
Please Sign up or sign in to vote.
4.12/5 (9 votes)
2 Sep 20052 min read 36.1K   262   11  
Consistent interfaces to CString using Boost.Range.
#pragma once

// See: boost/range/detail/mfc/cstring.hpp

#if (_ATL_VER >= 0x0700)

#include <cstddef>
#include <atlstr.h>
#include "../range/range_metafunctions_fwd.hpp"

namespace boost {

// range_iterator
template< class BaseT, class TraitsT >
struct range_iterator< ATL::CStringT<BaseT, TraitsT> >
{
	typedef typename ATL::CStringT<BaseT, TraitsT>::PXSTR type;
};

template< class BaseT, class TraitsT >
struct range_iterator< ATL::CStringT<BaseT, TraitsT> const > :
	range_iterator< ATL::CStringT<BaseT, TraitsT> >
{
};

// range_const_iterator
template< class BaseT, class TraitsT >
struct range_const_iterator< ATL::CStringT<BaseT, TraitsT> >
{
	typedef typename ATL::CStringT<BaseT, TraitsT>::PCXSTR type;
};

template< class BaseT, class TraitsT >
struct range_const_iterator< ATL::CStringT<BaseT, TraitsT> const > :
	range_const_iterator< ATL::CStringT<BaseT, TraitsT> >
{
};

// range_difference
template< class BaseT, class TraitsT >
struct range_difference< ATL::CStringT<BaseT, TraitsT> >
{
	typedef std::ptrdiff_t type;
};

template< class BaseT, class TraitsT >
struct range_difference< ATL::CStringT<BaseT, TraitsT> const > :
	range_difference< ATL::CStringT<BaseT, TraitsT> >
{
};

// range_size
template< class BaseT, class TraitsT >
struct range_size< ATL::CStringT<BaseT, TraitsT> >
{
	typedef int type;
};

template< class BaseT, class TraitsT >
struct range_size< ATL::CStringT<BaseT, TraitsT> const > :
	range_size< ATL::CStringT<BaseT, TraitsT> >
{
};

// range_value
template< class BaseT, class TraitsT >
struct range_value< ATL::CStringT<BaseT, TraitsT> >
{
	typedef typename ATL::CStringT<BaseT, TraitsT>::XCHAR type;
};

template< class BaseT, class TraitsT >
struct range_value< ATL::CStringT<BaseT, TraitsT> const > :
	range_value< ATL::CStringT<BaseT, TraitsT> >
{
};

// Note: The followings are required because primary templates eat CSimpleStringT's.

// begin
template< class BaseT, class TraitsT >
inline
typename range_iterator< ATL::CStringT<BaseT, TraitsT> >::type
begin(ATL::CStringT<BaseT, TraitsT>& rng)
{
	return rng.GetBuffer(0);
}

template< class BaseT, class TraitsT >
inline
typename range_const_iterator< ATL::CStringT<BaseT, TraitsT> >::type
begin(ATL::CStringT<BaseT, TraitsT> const& rng)
{
	return rng.GetString();
}

// size
template< class BaseT, class TraitsT >
inline
typename range_size< ATL::CStringT<BaseT, TraitsT> >::type
size(ATL::CStringT<BaseT, TraitsT> const& rng)
{
	return rng.GetLength();
}

// end
template< class BaseT, class TraitsT >
inline
typename range_iterator< ATL::CStringT<BaseT, TraitsT> >::type
end(ATL::CStringT<BaseT, TraitsT>& rng)
{
	return begin(rng) + size(rng);
}

template< class BaseT, class TraitsT >
inline
typename range_const_iterator< ATL::CStringT<BaseT, TraitsT> >::type
end(ATL::CStringT<BaseT, TraitsT> const& rng)
{
	return begin(rng) + size(rng);
}

// default 'empty()' ok

} // namespace boost

#endif // (_ATL_VER >= 0x0700)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions