Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MY_INTERFACES
- #define MY_INTERFACES
- template<class T>
- class IEnumerator
- {
- public:
- virtual bool MoveNext() = 0;
- virtual void Reset() = 0;
- virtual T Current() = 0;
- virtual ~IEnumerator() {}
- };
- template<class T>
- class IEnumerable
- {
- public:
- virtual IEnumerator<T> GetEnumerator()
- {
- return (IEnumerator<T>)*this;
- }
- };
- template<class T>
- class ICollection : public IEnumerable<T>
- {
- public:
- virtual int Count()
- {
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- int i = 0;
- while(e.MoveNext()) i++;
- return i + 1;
- }
- virtual bool IsReadOnly() = 0;
- virtual void Add(T item) = 0;
- virtual void Clear()
- {
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- do
- {
- Remove(e.Current());
- }
- while(e.MoveNext());
- }
- virtual bool Contains(T item)
- {
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- do
- {
- if(e.Current() == item)
- return true;
- }
- while (e.MoveNext());
- return false;
- }
- virtual void CopyTo(T *arr, int index, int count)
- {
- int i = 0;
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- do
- {
- arr[index + i++] = e.Current();
- }
- while (e.MoveNext() && i < count);
- }
- virtual bool Remove(T item) = 0;
- };
- template<class T>
- class IComparer
- {
- public:
- virtual int Compare(T a, T b) = 0;
- }
- template<class T>
- class IList : public ICollection<T>
- {
- public:
- virtual T &operator[](int index)
- {
- int i = 0;
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- do
- {
- if(i++ == index)
- return e.Current();
- }
- while (e.MoveNext());
- throw "index";
- }
- virtual int IndexOf(T item)
- {
- IEnumerator<T> e = GetEnumerator();
- e.Reset();
- int i = 0;
- do
- {
- if(e.Current() == item)
- return i;
- }
- while (e.MoveNext());
- return -1;
- }
- virtual void Insert(int index, T item) = 0;
- virtual void RemoveAt(int index) = 0;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement