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

📄 generics.h

📁 C语言库函数的原型,有用的拿去
💻 H
📖 第 1 页 / 共 5 页
字号:
// generics STL.net header
#ifndef _CLI_GENERICS_
 #define _CLI_GENERICS_

#define _STLCLR_FIELD_ACCESS	internal

namespace Microsoft {
	namespace VisualC {
		namespace StlClr {

	namespace Generic {
//
// GENERIC INTERFACES
//

//
// GENERIC INTERFACE CLASS IBidirectionalContainer
//
generic<typename TValue>
	public interface class IBidirectionalContainer
	{	// interface for a bidirectional container
	unsigned long get_generation();
	};

//
// GENERIC INTERFACE CLASS IRandomAccessContainer
//
generic<typename TValue>
	public interface class IRandomAccessContainer
	{	// interface for a random-access container
	typedef int size_type;
//	typedef int difference_type;
	typedef TValue value_type;
	typedef value_type% reference;
//	typedef value_type% const_reference;

	bool valid_bias(size_type);
	reference at_bias(size_type);
	};

//
// GENERIC INTERFACE CLASS INode
//
generic<typename TValue>
	public interface class INode
	{	// interface for a node
	typedef INode<TValue> _Mynode_it;
	typedef IBidirectionalContainer<TValue> _Mycont_it;

	_Mycont_it^ container();
	bool is_head();
	_Mynode_it^ next_node();
	_Mynode_it^ prev_node();

	property TValue% _Value;
	};

//
// GENERIC INTERFACE CLASS IBaseIterator
//
generic<typename TValue>
	public interface class IBaseIterator
	:	public System::ICloneable
	{	// interface for base of all iterators, generic
	int get_bias();
	System::Object^ get_node();

	bool valid();
	System::Object^ container();
	void next();
	};

//
// GENERIC INTERFACE CLASS IInputIterator
//
generic<typename TValue>
	public interface class IInputIterator
	:	public IBaseIterator<TValue>
	{	// interface for an input iterator, generic
	typedef IInputIterator<TValue> _Mytype_t;
	typedef TValue value_type;

	bool equal_to(IInputIterator<TValue>^);
	value_type% get_cref();
	};

//
// GENERIC INTERFACE CLASS IOutputIterator
//
generic<typename TValue>
	public interface class IOutputIterator
	:	public IBaseIterator<TValue>
	{	// interface for an output iterator, generic
	typedef TValue value_type;

	value_type% get_ref();
	};

//
// GENERIC INTERFACE CLASS IForwardIterator
//
generic<typename TValue>
	public interface class IForwardIterator
	:	public IInputIterator<TValue>,
		public IOutputIterator<TValue>
	{	// interface for a forward iterator, generic
	};

//
// GENERIC INTERFACE CLASS IBidirectionalIterator
//
generic<typename TValue>
	public interface class IBidirectionalIterator
	:	public IForwardIterator<TValue>
	{	// interface for a bidirectional iterator, generic
	void prev();
	};

//
// GENERIC INTERFACE CLASS IRandomAccessIterator
//
generic<typename TValue>
	public interface class IRandomAccessIterator
	:	public IBidirectionalIterator<TValue>
	{	// interface for a random-access iterator, generic
	typedef IRandomAccessIterator<TValue> _Mytype_t;
	typedef int difference_type;

	difference_type move(difference_type _Offset);
	difference_type distance(IRandomAccessIterator<TValue>^ _Right);
	bool less_than(IRandomAccessIterator<TValue>^ _Right);
	};

//
// GENERIC ITERATOR CLASSES
//

//
// GENERIC REF CLASS ReverseBidirectionalIterator
//
generic<typename TValue>
	public ref class ReverseBidirectionalIterator
	:	public Generic::IBidirectionalIterator<TValue>
	{	// mutable reverse bidirectional iterator, generic
public:
	// types
	typedef ReverseBidirectionalIterator<TValue> _Mytype_t;
	typedef Generic::IBidirectionalIterator<TValue> _Myiter_t;

	typedef TValue value_type;
	typedef int difference_type;
	typedef value_type% pointer;
	typedef value_type% reference;
	typedef value_type% const_reference;

	// basics
	ReverseBidirectionalIterator()
		:	_Myiter(nullptr)
		{	// construct default
		}

	ReverseBidirectionalIterator(ReverseBidirectionalIterator% _Right)
		:	_Myiter((_Myiter_t^)_Right._Myiter->Clone())
		{	// construct by copying an iterator
		}

	ReverseBidirectionalIterator% operator=(
		ReverseBidirectionalIterator% _Right)
		{	// assign an iterator
		if ((Object^)this != %_Right)
			_Myiter = (_Myiter_t^)_Right._Myiter->Clone();
		return (*this);
		}

	operator _Myiter_t^()
		{	// convert to interface
		return (this);
		}

	// constructors and special member functions
	ReverseBidirectionalIterator(_Myiter_t^ _Iter)
		:	_Myiter((_Myiter_t^)_Iter->Clone())
		{	// construct from wrapped iterator
		}

	_Myiter_t^ base()
		{	// get underlying base iterator
		return (_Myiter);
		}

	// member functions
	virtual System::Object^ Clone()
		{	// return a copy
		return (gcnew ReverseBidirectionalIterator(
			(_Myiter_t^)_Myiter->Clone()));
		}

	virtual int get_bias()
		{	// get offset from wrapped iterator
		return (0);
		}

	virtual System::Object^ get_node()
		{	// get node from wrapped iterator
		return (_Myiter->get_node());
		}

	virtual bool valid()
		{	// test if wrapped iterator valid
		return (_Myiter->valid());
		}

	virtual System::Object^ container()
		{	// return container for wrapped iterator
		return (_Myiter->container());
		}

	virtual void next()
		{	// decrement wrapped iterator
		_Myiter->prev();
		}

	[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1011")]
	virtual bool equal_to(Generic::IInputIterator<TValue>^ _Right)
		{	// test if *this == _Right
		if (container() == nullptr
			|| container() != _Right->container())
			throw gcnew System::ArgumentException();
		return (get_bias() == _Right->get_bias()
			&& get_node() == _Right->get_node());
		}

	bool equal_to(ReverseBidirectionalIterator% _Right)
		{	// test if wrapped iterators are equal, class specific
		return (_Myiter->equal_to(_Right._Myiter));
		}

	virtual const_reference get_cref()
		{	// return const reference from wrapped iterator
		_Myiter->prev();
		const_reference _Ref = _Myiter->get_cref();
		_Myiter->next();
		return (_Ref);
		}

	virtual reference get_ref()
		{	// return reference from wrapped iterator
		_Myiter->prev();
		reference _Ref = _Myiter->get_ref();
		_Myiter->next();
		return (_Ref);
		}

	virtual void prev()
		{	// increment wrapped iterator
		_Myiter->next();
		}

//	difference_type move(difference_type _Offset);
//	difference_type distance(
//		Generic::IRandomAccessIterator<TValue>^ _Right);
//	difference_type distance(ReverseBidirectionalIterator^ _Right);
//	bool less_than(Generic::IRandomAccessIterator<TValue>^ _Right);
//	bool less_than(ReverseBidirectionalIterator^ _Right);

	// operators
	[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
	static reference operator->(ReverseBidirectionalIterator% _Left)
		{	// return pointer to class object
		return (_Left.get_ref());
		}

	[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
	static reference operator*(ReverseBidirectionalIterator% _Left)
		{	// return reference to designated element
		return (_Left.get_ref());
		}

	ReverseBidirectionalIterator operator++()
		{	// return incremented
		next();
		return (*this);
		}

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

		++*this;
		return (_Iter);
		}

	bool operator==(Generic::IInputIterator<TValue>^ _Right)
		{	// test if *this == _Right
		return (equal_to(_Right));
		}

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

	bool operator!=(Generic::IInputIterator<TValue>^ _Right)
		{	// test if *this != _Right
		return (!(*this == _Right));
		}

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

	ReverseBidirectionalIterator operator--()
		{	// return decremented
		prev();
		return (*this);
		}

	ReverseBidirectionalIterator operator--(int)
		{	// return decremented
		ReverseBidirectionalIterator _Iter = *this;

		--*this;
		return (_Iter);
		}

//	ReverseBidirectionalIterator^ operator+(difference_type _Right);
//	static ReverseBidirectionalIterator^
//		operator+(difference_type _Left, ReverseBidirectionalIterator _Right);
//	ReverseBidirectionalIterator^ operator-(difference_type _Right);
//	difference_type operator-(ReverseBidirectionalIterator^ _Right);
//	bool operator<(ReverseBidirectionalIterator^ _Right);
//	bool operator>=(ReverseBidirectionalIterator^ _Right);
//	bool operator>(ReverseBidirectionalIterator^ _Right);
//	bool operator<=(ReverseBidirectionalIterator^ _Right);

_STLCLR_FIELD_ACCESS:
	_Myiter_t^ _Myiter;	// wrapped iterator
	};

//
// GENERIC REF CLASS ConstReverseBidirectionalIterator
//
generic<typename TValue>
	public ref class ConstReverseBidirectionalIterator
	:	public Generic::IBidirectionalIterator<TValue>
	{	// nonmutable reverse bidirectional iterator, generic
public:
	// types
	typedef ConstReverseBidirectionalIterator<TValue> _Mytype_t;
	typedef Generic::IBidirectionalIterator<TValue> _Myiter_t;

	typedef TValue value_type;
	typedef int difference_type;
	typedef value_type% pointer;
	typedef value_type% reference;
	typedef value_type% const_reference;

	// basics
	ConstReverseBidirectionalIterator()
		:	_Myiter(nullptr)
		{	// construct default
		}

	ConstReverseBidirectionalIterator(
		ConstReverseBidirectionalIterator% _Right)
		:	_Myiter((_Myiter_t^)_Right._Myiter->Clone())
		{	// construct by copying an iterator
		}

	ConstReverseBidirectionalIterator% operator=(
		ConstReverseBidirectionalIterator% _Right)
		{	// assign an iterator
		if ((Object^)this != %_Right)
			_Myiter = (_Myiter_t^)_Right._Myiter->Clone();
		return (*this);
		}

	operator _Myiter_t^()
		{	// convert to interface
		return (this);
		}

	// constructors and special member functions
	ConstReverseBidirectionalIterator(_Myiter_t^ _Iter)
		:	_Myiter((_Myiter_t^)_Iter->Clone())
		{	// construct from wrapped iterator
		}

	ConstReverseBidirectionalIterator(
		ReverseBidirectionalIterator<TValue>% _Iter)
		:	_Myiter((_Myiter_t^)_Iter.base()->Clone())
		{	// construct from mutable iterator
		}

	ConstReverseBidirectionalIterator%
		operator=(ReverseBidirectionalIterator<TValue>% _Right)
		{	// assign from mutable iterator
		_Myiter = (_Myiter_t^)_Right.base()->Clone();
		return (*this);
		}

	_Myiter_t^ base()
		{	// get underlying base iterator
		return (_Myiter);
		}

	// member functions
	virtual System::Object^ Clone()
		{	// return a copy
		return (gcnew ConstReverseBidirectionalIterator(
			(_Myiter_t^)_Myiter->Clone()));
		}

	virtual int get_bias()
		{	// get offset from wrapped iterator
		return (0);
		}

	virtual System::Object^ get_node()
		{	// get node from wrapped iterator
		return (_Myiter->get_node());
		}

	virtual bool valid()
		{	// test if wrapped iterator valid
		return (_Myiter->valid());
		}

	virtual System::Object^ container()
		{	// return container for wrapped iterator
		return (_Myiter->container());
		}

	virtual void next()
		{	// decrement wrapped iterator
		_Myiter->prev();
		}

	virtual bool equal_to(Generic::IInputIterator<TValue>^ _Right)
		{	// test if *this == _Right
		if (container() == nullptr
			|| container() != _Right->container())
			throw gcnew System::ArgumentException();
		return (get_bias() == _Right->get_bias()
			&& get_node() == _Right->get_node());
		}

	bool equal_to(ConstReverseBidirectionalIterator% _Right)
		{	// test if wrapped iterators are equal, class specific
		return (_Myiter->equal_to(_Right._Myiter));
		}

	virtual const_reference get_cref()
		{	// return const reference from wrapped iterator
		_Myiter->prev();
		const_reference _Ref = _Myiter->get_cref();
		_Myiter->next();
		return (_Ref);
		}

	virtual reference get_ref()
		{	// return reference from wrapped iterator
#pragma warning(push)
#pragma warning(disable: 4715)
		throw gcnew System::InvalidOperationException();
#pragma warning(pop)
		}

	virtual void prev()
		{	// increment wrapped iterator
		_Myiter->next();
		}

//	difference_type move(difference_type _Offset);
//	difference_type distance(
//		Generic::IRandomAccessIterator<TValue>^ _Right);
//	difference_type distance(ConstReverseBidirectionalIterator^ _Right);
//	bool less_than(Generic::IRandomAccessIterator<TValue>^ _Right);
//	bool less_than(ConstReverseBidirectionalIterator^ _Right);

	// operators
	[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
	static const_reference operator->(
		ConstReverseBidirectionalIterator% _Left)
		{	// return pointer to class object
		return (_Left.get_cref());
		}

	[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
	static const_reference operator*(

⌨️ 快捷键说明

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