⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adapter

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 3 页
字号:
// adapter stl/clr header
#ifndef _CLI_ADAPTER_
 #define _CLI_ADAPTER_
#include <cliext/iterator>
#include <cliext/utility>

namespace cliext {
//
// TEMPLATE CLASS collection_adapter
//
template<typename _Cont_t>
	ref class collection_adapter;

//
// TEMPLATE REF CLASS Enum_iterator
//
template<typename _Cont_t,
	typename _Enum_t,
	typename _Value_t>
	ref class Enum_iterator
	{	// iterator for read-only one-pass container
public:
	// types
	typedef Enum_iterator<_Cont_t, _Enum_t, _Value_t> _Mytype_t;

	typedef input_iterator_tag iterator_category;
	typedef _Value_t value_type;
	typedef int difference_type;
	typedef value_type% pointer;
	typedef value_type% reference;
	typedef value_type% const_reference;

	// basics
	Enum_iterator()
		:	_Mycont(nullptr), _Myenum(nullptr)
		{	// construct default
		}

	Enum_iterator(Enum_iterator% _Right)
		:	_Mycont(_Right._Mycont), _Myenum(_Right._Myenum)
		{	// construct by copying an iterator
		}

	Enum_iterator% operator=(Enum_iterator% _Right)
		{	// assign an iterator
		_Mycont = _Right._Mycont;
		_Myenum = _Right._Myenum;
		return (*this);
		}

	// constructors
	Enum_iterator(_Cont_t^ _Cont)
		:	_Mycont(_Cont), _Myenum(nullptr)
		{	// construct from container
		}

	Enum_iterator(_Cont_t^ _Cont, _Enum_t^ _Enum)
		:	_Mycont(_Cont), _Myenum(_Enum)
		{	// construct from container and enumerator
		if (!_Myenum->MoveNext())
			_Myenum = nullptr;
		}

	// operators
	static value_type operator->(Enum_iterator% _Left)
		{	// return pointer to class object
		return (_Left._Myenum->Current);
		}

	static value_type operator*(Enum_iterator% _Left)
		{	// return reference to designated element
		return (_Left._Myenum->Current);
		}

	Enum_iterator operator++()
		{	// return incremented
		if (!_Myenum->MoveNext())
			_Myenum = nullptr;
		return (*this);
		}

	Enum_iterator operator++(int)
		{	// return incremented
		Enum_iterator _Iter = *this;

		++*this;
		return (_Iter);
		}

	bool operator==(_Mytype_t% _Right)
		{	// test if *this == _Right
		if (_Mycont != _Right._Mycont)
			throw gcnew System::InvalidOperationException();
		return ((System::Object^)_Myenum == _Right._Myenum);
		}

	bool operator!=(_Mytype_t% _Right)
		{	// test if *this != _Right
		return (!(*this == _Right));
		}

_STLCLR_FIELD_ACCESS:
	// data members
	_Cont_t^ _Mycont;	// stored container handle
	_Enum_t^ _Myenum;	// stored enumerator handle
	};

//
// TEMPLATE CLASS collection_adapter<IEnumerable>
//
template<>
	ref class collection_adapter<
		System::Collections::IEnumerable>
	{	// wrapper for IEnumerable
public:
	// types
	typedef System::Collections::IEnumerable _Mycont_t;
	typedef System::Collections::IEnumerator _Myenum_t;
	typedef System::Object^ _Value_t;
	typedef collection_adapter<_Mycont_t> _Mytype_t;

	typedef Enum_iterator<_Mycont_t, _Myenum_t, _Value_t> iterator;

	typedef int size_type;
	typedef int difference_type;
	typedef _Value_t value_type;
	typedef _Value_t% reference;

	// basics
	collection_adapter()
		:	_Mycont(nullptr)
		{	// construct empty wrapper
		}

	collection_adapter(collection_adapter% _Right)
		:	_Mycont(_Right._Mycont)
		{	// construct by copying _Right
		}

	collection_adapter% operator=(collection_adapter% _Right)
		{	// assign
		_Mycont = _Right._Mycont;
		return (*this);
		}

	collection_adapter% operator=(collection_adapter^ _Right)
		{	// assign
		_Mycont = _Right->_Mycont;
		return (*this);
		}

	// constructors
	collection_adapter(_Mycont_t^ _Right)
		:	_Mycont(_Right)
		{	// construct by wrapping
		}

	// destructor
	~collection_adapter()
		{	// destroy the object
		}

	// accessors
	operator _Mycont_t^()
		{	// convert to base
		return (_Mycont);
		}

	_Mycont_t^ base()
		{	// return base
		return (_Mycont);
		}

	// iterator generators
	iterator begin()
		{	// return iterator for beginning of input sequence
		return (iterator(_Mycont, _Mycont->GetEnumerator()));
		}

	iterator end()
		{	// return iterator for end of input sequence
		return (iterator(_Mycont));
		}

	// size controllers
//	size_type size()
//		{	// return length of sequence
//		return (_Mycont->Count);
//		}

	// mutators
	void swap(collection_adapter% _Right)
		{	// exchange contents with _Right
		if ((Object^)this != %_Right)
			{	// worth doing, swap
			_Mycont_t^ _Tcont = _Mycont;

			_Mycont = _Right._Mycont;
			_Right._Mycont = _Tcont;
			}
		}

_STLCLR_FIELD_ACCESS:
	// data members
	_Mycont_t^ _Mycont;	// the wrapped IEnumerable interface
	};

//
// TEMPLATE CLASS collection_adapter<IEnumerable<T> >
//
template<typename _Value_t>
	ref class collection_adapter<
		System::Collections::Generic::IEnumerable<_Value_t> >
	{	// wrapper for IEnumerable<T>
public:
	// types
	typedef System::Collections::Generic::IEnumerable<_Value_t> _Mycont_t;
	typedef System::Collections::Generic::IEnumerator<_Value_t> _Myenum_t;
	typedef collection_adapter<_Mycont_t> _Mytype_t;

	typedef Enum_iterator<_Mycont_t, _Myenum_t, _Value_t> iterator;

	typedef int size_type;
	typedef int difference_type;
	typedef _Value_t value_type;
	typedef _Value_t% reference;

	// basics
	collection_adapter()
		:	_Mycont(nullptr)
		{	// construct empty wrapper
		}

	collection_adapter(collection_adapter% _Right)
		:	_Mycont(_Right._Mycont)
		{	// construct by copying _Right
		}

	collection_adapter% operator=(collection_adapter% _Right)
		{	// assign
		_Mycont = _Right._Mycont;
		return (*this);
		}

	collection_adapter% operator=(collection_adapter^ _Right)
		{	// assign
		_Mycont = _Right->_Mycont;
		return (*this);
		}

	// constructors
	collection_adapter(_Mycont_t^ _Right)
		:	_Mycont(_Right)
		{	// construct by wrapping
		}

	// destructor
	~collection_adapter()
		{	// destroy the object
		}

	// accessors
	operator _Mycont_t^()
		{	// convert to base
		return (_Mycont);
		}

	_Mycont_t^ base()
		{	// return base
		return (_Mycont);
		}

	// iterator generators
	iterator begin()
		{	// return iterator for beginning of input sequence
		return (iterator(_Mycont, _Mycont->GetEnumerator()));
		}

	iterator end()
		{	// return iterator for end of input sequence
		return (iterator(_Mycont));
		}

	// size controllers
//	size_type size()
//		{	// return length of sequence
//		return (_Mycont->Count);
//		}

	// mutators
	void swap(collection_adapter% _Right)
		{	// exchange contents with _Right
		if ((Object^)this != %_Right)
			{	// worth doing, swap
			_Mycont_t^ _Tcont = _Mycont;

			_Mycont = _Right._Mycont;
			_Right._Mycont = _Tcont;
			}
		}

_STLCLR_FIELD_ACCESS:
	// data members
	_Mycont_t^ _Mycont;	// the wrapped IEnumerable interface
	};

//
// TEMPLATE CLASS collection_adapter<ICollection>
//
template<>
	ref class collection_adapter<
		System::Collections::ICollection>
	{	// wrapper for ICollection
public:
	// types
	typedef System::Collections::ICollection _Mycont_t;
	typedef System::Collections::IEnumerator _Myenum_t;
	typedef System::Object^ _Value_t;
	typedef collection_adapter<_Mycont_t> _Mytype_t;

	typedef Enum_iterator<_Mycont_t, _Myenum_t, _Value_t> iterator;

	typedef int size_type;
	typedef int difference_type;
	typedef _Value_t value_type;
	typedef _Value_t% reference;

	// basics
	collection_adapter()
		:	_Mycont(nullptr)
		{	// construct empty wrapper
		}

	collection_adapter(collection_adapter% _Right)
		:	_Mycont(_Right._Mycont)
		{	// construct by copying _Right
		}

	collection_adapter% operator=(collection_adapter% _Right)
		{	// assign
		_Mycont = _Right._Mycont;
		return (*this);
		}

	collection_adapter% operator=(collection_adapter^ _Right)
		{	// assign
		_Mycont = _Right->_Mycont;
		return (*this);
		}

	// constructors
	collection_adapter(_Mycont_t^ _Right)
		:	_Mycont(_Right)
		{	// construct by wrapping
		}

	// destructor
	~collection_adapter()
		{	// destroy the object
		}

	// accessors
	operator _Mycont_t^()
		{	// convert to base
		return (_Mycont);
		}

	_Mycont_t^ base()
		{	// return base
		return (_Mycont);
		}

	// iterator generators
	iterator begin()
		{	// return iterator for beginning of input sequence
		return (iterator(_Mycont, _Mycont->GetEnumerator()));
		}

	iterator end()
		{	// return iterator for end of input sequence
		return (iterator(_Mycont));
		}

	// size controllers
	size_type size()
		{	// return length of sequence
		return (_Mycont->Count);
		}

	// mutators
	void swap(collection_adapter% _Right)
		{	// exchange contents with _Right
		if ((Object^)this != %_Right)
			{	// worth doing, swap
			_Mycont_t^ _Tcont = _Mycont;

			_Mycont = _Right._Mycont;
			_Right._Mycont = _Tcont;
			}
		}

_STLCLR_FIELD_ACCESS:
	// data members
	_Mycont_t^ _Mycont;	// the wrapped ICollection interface
	};

//
// TEMPLATE CLASS collection_adapter<ICollection<T> >
//
template<typename _Value_t>
	ref class collection_adapter<
		System::Collections::Generic::ICollection<_Value_t> >
	{	// wrapper for ICollection<T>
public:
	// types
	typedef System::Collections::Generic::ICollection<_Value_t> _Mycont_t;
	typedef System::Collections::Generic::IEnumerator<_Value_t> _Myenum_t;
	typedef collection_adapter<_Mycont_t> _Mytype_t;

	typedef Enum_iterator<_Mycont_t, _Myenum_t, _Value_t> iterator;

	typedef int size_type;
	typedef int difference_type;
	typedef _Value_t value_type;
	typedef _Value_t% reference;

	// basics
	collection_adapter()
		:	_Mycont(nullptr)
		{	// construct empty wrapper
		}

	collection_adapter(collection_adapter% _Right)
		:	_Mycont(_Right._Mycont)
		{	// construct by copying _Right
		}

	collection_adapter% operator=(collection_adapter% _Right)
		{	// assign
		_Mycont = _Right._Mycont;
		return (*this);
		}

	collection_adapter% operator=(collection_adapter^ _Right)
		{	// assign
		_Mycont = _Right->_Mycont;
		return (*this);
		}

	// constructors
	collection_adapter(_Mycont_t^ _Right)
		:	_Mycont(_Right)
		{	// construct by wrapping
		}

	// destructor
	~collection_adapter()
		{	// destroy the object
		}

	// accessors
	operator _Mycont_t^()
		{	// convert to base
		return (_Mycont);
		}

	_Mycont_t^ base()
		{	// return base
		return (_Mycont);
		}

	// iterator generators
	iterator begin()
		{	// return iterator for beginning of input sequence
		return (iterator(_Mycont, _Mycont->GetEnumerator()));
		}

	iterator end()
		{	// return iterator for end of input sequence
		return (iterator(_Mycont));
		}

	// size controllers
	size_type size()
		{	// return length of sequence
		return (_Mycont->Count);
		}

	// mutators
	void swap(collection_adapter% _Right)
		{	// exchange contents with _Right
		if ((Object^)this != %_Right)
			{	// worth doing, swap
			_Mycont_t^ _Tcont = _Mycont;

			_Mycont = _Right._Mycont;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -