📄 generics.h
字号:
if (!_Mycont->valid_bias(_Myoffset + 1))
throw gcnew System::InvalidOperationException();
++_Myoffset;
}
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(ConstContainerRandomAccessIterator% _Right)
{ // test if *this == _Right
if (container() == nullptr
|| container() != _Right._Mycont)
throw gcnew System::ArgumentException();
return (_Myoffset == _Right._Myoffset);
}
virtual const_reference get_cref()
{ // return const reference to designated element
return (_Mycont->at_bias(_Myoffset));
}
virtual reference get_ref()
{ // return reference to designated element
#pragma warning(push)
#pragma warning(disable: 4715)
throw gcnew System::InvalidOperationException();
#pragma warning(pop)
}
virtual void prev()
{ // decrement
if (!_Mycont->valid_bias(_Myoffset - 1))
throw gcnew System::InvalidOperationException();
--_Myoffset;
}
virtual difference_type move(difference_type _Offset)
{ // incremented by integer
difference_type _Newoffset = _Myoffset + _Offset; // can overflow
if (!_Mycont->valid_bias(_Newoffset))
throw gcnew System::InvalidOperationException();
_Myoffset = _Newoffset;
return (_Myoffset);
}
virtual difference_type distance(
Generic::IRandomAccessIterator<TValue>^ _Right)
{ // return difference of two iterators
if (container() == nullptr
|| container() != _Right->container())
throw gcnew System::ArgumentException();
return (get_bias() - _Right->get_bias());
}
difference_type distance(
_Mytype_t% _Right)
{ // return difference of two iterators
if (container() == nullptr
|| container() != _Right.container())
throw gcnew System::ArgumentException();
return (get_bias() - _Right.get_bias());
}
virtual bool less_than(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this < _Right
if (container() == nullptr
|| container() != _Right->container())
throw gcnew System::ArgumentException();
return (get_bias() < _Right->get_bias());
}
bool less_than(_Mytype_t% _Right)
{ // test if *this < _Right
if (container() == nullptr
|| container() != _Right.container())
throw gcnew System::ArgumentException();
return (get_bias() < _Right.get_bias());
}
// operators
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static const_reference operator->(
ConstContainerRandomAccessIterator% _Left)
{ // return pointer to class object
return (_Left.get_cref());
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static const_reference operator*(
ConstContainerRandomAccessIterator% _Left)
{ // return const reference to designated element
return (_Left.get_cref());
}
ConstContainerRandomAccessIterator operator++()
{ // return incremented
next();
return (*this);
}
ConstContainerRandomAccessIterator operator++(int)
{ // return incremented
ConstContainerRandomAccessIterator _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));
}
ConstContainerRandomAccessIterator operator--()
{ // return decremented
prev();
return (*this);
}
ConstContainerRandomAccessIterator operator--(int)
{ // return decremented
ConstContainerRandomAccessIterator _Iter = *this;
--*this;
return (_Iter);
}
ConstContainerRandomAccessIterator operator+(difference_type _Right)
{ // return incremented by integer
ConstContainerRandomAccessIterator _Iter = *this;
_Iter.move(_Right);
return (_Iter);
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static ConstContainerRandomAccessIterator operator+(
difference_type _Left, ConstContainerRandomAccessIterator _Right)
{ // return incremented by integer
ConstContainerRandomAccessIterator _Iter = _Right;
_Iter.move(_Left);
return (_Iter);
}
ConstContainerRandomAccessIterator operator-(difference_type _Right)
{ // return decremented by integer
ConstContainerRandomAccessIterator _Iter = *this;
_Iter.move(-_Right); // can overflow
return (_Iter);
}
difference_type operator-(
Generic::IRandomAccessIterator<TValue>^ _Right)
{ // return difference of two iterators
return (distance(_Right));
}
bool operator<(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator<(_Mytype_t% _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator>=(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
bool operator>=(_Mytype_t% _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static bool operator>(Generic::IRandomAccessIterator<TValue>^ _Left,
_Mytype_t% _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
bool operator>(_Mytype_t%_Right)
{ // test if *this > _Right
return (_Right < *this);
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static bool operator<=(Generic::IRandomAccessIterator<TValue>^ _Left,
_Mytype_t% _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
bool operator<=(_Mytype_t%_Right)
{ // test if *this <= _Right
return (!(_Right < *this));
}
property const_reference default[difference_type]
{ // get subscripted element
const_reference get(difference_type _Pos)
{ // get _Pos element
ConstContainerRandomAccessIterator _Where = *this + _Pos;
return (*_Where);
}
};
_STLCLR_FIELD_ACCESS:
// data members
TCont^ _Mycont; // owning container
difference_type _Myoffset; // offset into container
};
} // namespace Generic
// GENERICS FOR deque //
//
// GENERIC INTERFACE CLASS IDeque
//
generic<typename TValue>
public interface class IDeque
: public Generic::IRandomAccessContainer<TValue>,
System::ICloneable,
System::Collections::ICollection,
System::Collections::IEnumerable
{ // interface for a deque
typedef IDeque<TValue> _Mycont_it;
typedef System::Collections::IEnumerable _Myenum_it;
typedef Generic::ContainerRandomAccessIterator<TValue>
iterator;
typedef Generic::ReverseRandomAccessIterator<TValue>
reverse_iterator;
typedef int size_type;
typedef TValue value_type;
typedef value_type% reference;
// accessors
reference at(size_type _Pos);
property value_type front_item;
property value_type back_item;
reference front();
reference back();
property value_type default[size_type]
{ // subscript
value_type get(size_type _Pos);
void set(size_type _Pos, value_type _Val);
}
// iterator generators
iterator begin();
iterator end();
reverse_iterator rbegin();
reverse_iterator rend();
// size controllers
// void reserve(size_type _Capacity);
// size_type capacity();
void resize(size_type _Newsize);
void resize(size_type _Newsize, value_type _Val);
size_type size();
bool empty();
// mutators
void push_front(value_type _Val);
void pop_front();
void push_back(value_type _Val);
void pop_back();
void assign(size_type _Count, value_type _Val);
void assign(Generic::IInputIterator<TValue>^ _First,
Generic::IInputIterator<TValue>^ _Last);
void assign(_Myenum_it^ _Right);
iterator insert(iterator _Where, value_type _Val);
void insert(iterator _Where,
size_type _Count, value_type _Val);
void insert(iterator _Where,
Generic::IInputIterator<TValue>^ _First,
Generic::IInputIterator<TValue>^ _Last);
void insert(iterator _Where_iter,
_Myenum_it^ _Right);
iterator erase(iterator _Where);
iterator erase(iterator _First_iter, iterator _Last_iter);
void clear();
void swap(_Mycont_it^);
//_STLCLR_FIELD_ACCESS:
//
size_type begin_bias();
size_type end_bias();
// reference at_bias(size_type);
// bool valid_bias(size_type);
unsigned long get_generation();
};
//
// GENERIC REF CLASS DequeEnumeratorBase
//
generic<typename TValue>
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1038")]
public ref class DequeEnumeratorBase
: public System::Collections::IEnumerator
{ // enumerator for a deque
public:
typedef DequeEnumeratorBase<TValue> _Mytype_t;
typedef IDeque<TValue> _Mycont_it;
typedef int difference_type;
typedef TValue value_type;
DequeEnumeratorBase(_Mycont_it^ _Cont, difference_type _First)
: _Mycont(_Cont), _Myfirst(_First), _Is_reset(true)
{ // construct from container and bias
_Mygen = _Mycont->get_generation();
}
virtual bool MoveNext()
{ // move to next element and test if done
_Validate();
if (_Is_reset)
{ // starting, point to front and clear flag
_Is_reset = false;
_Mybias = _Myfirst;
}
else if ((unsigned int)_Mybias - _Mycont->begin_bias()
< (unsigned int)_Mycont->size())
++_Mybias;
return ((unsigned int)_Mybias - _Mycont->begin_bias()
< (unsigned int)_Mycont->size());
}
property System::Object^ Current
{ // get or set next element
virtual System::Object^ get()
{ // get next element
return (_Getval());
}
virtual void set(System::Object^)
{ // set next element
throw gcnew System::InvalidOperationException();
}
};
virtual void Reset()
{ // restart enumerator
_Validate();
_Is_reset = true;
}
_STLCLR_FIELD_ACCESS:
value_type _Getval()
{ // get next element
_Validate();
if (_Is_reset)
throw gcnew System::InvalidOperationException();
return (_Mycont->at_bias(_Mybias));
}
void _Validate()
{ // test if container has been modified
if (_Mycont->get_generation() != _Mygen)
throw gcnew System::InvalidOperationException();
}
bool _Is_reset; // true when starting/reset
difference_type _Myfirst; // initial bias
difference_type _Mybias; // current bias
_Mycont_it^ _Mycont; // owning container
unsigned long _Mygen; // container generation
};
//
// GENERIC REF CLASS DequeEnumerator
//
generic<typename TValue>
public ref class DequeEnumerator
: public DequeEnumeratorBase<TValue>,
System::Collections::Generic::IEnumerator<TValue>
{ // enumerator for a deque
public:
typedef DequeEnumerator<TValue> _Mytype_t;
typedef DequeEnumeratorBase<TValue> _Mybase_t;
typedef int difference_type;
typedef TValue value_type;
DequeEnumerator(_Mycont_it^ _Cont, difference_type _First)
: _Mybase_t(_Cont, _First)
{ // construct from container and bias
}
~DequeEnumerator()
{ // destroy the object
}
virtual bool MoveNext() override
{ // move to next element and test if done
return (_Mybase_t::MoveNext());
}
property value_type Current
{ // get or set next element
virtual value_type get() new
{ // get next element
return (_Mybase_t::_Getval());
}
virtual void set(value_type)
{ // set next element
throw gcnew System::InvalidOperationException();
}
};
virtual void Reset() override
{ // restart enumerator
_Mybase_t::Reset();
}
};
// GENERICS FOR functional //
//
// GENERIC DELEGATE UnaryDelegate
//
generic<typename TArg,
typename TResult>
public delegate TResult UnaryDelegate(TArg);
//
// GENERIC DELEGATE BinaryDelegate
//
generic<typename TArg1,
typename TArg2,
typename TResult>
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1005")]
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Naming", "CA1708")]
public delegate TResult BinaryDelegate(TArg1, TArg2);
// GENERICS FOR list //
//
// GENERIC INTERFACE CLASS IList
//
generic<typename TValue>
public interface class IList
: public Generic::IBidirectionalContainer<TValue>,
System::ICloneable,
System::Collections::ICollection,
System::Collections::IEnumerable
{ // interface for a list
typedef IList<TValue> _Mycont_it;
typedef System::Collections::IEnumerable _Myenum_it;
typedef Generic::ContainerBidirectionalIterator<TValue>
iterator;
typedef Generic::ReverseBidirectionalIterator<T
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -