diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 19:27:15 +0000 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 19:27:15 +0000 |
commit | ad1cadf3512f3dd789151983e5c93af411f929db (patch) | |
tree | d6d25d562617d9bec7b13286cf413ed8f7567275 /omegalib/omega_lib/include/basic/Collection.h | |
parent | cfafd2ffcad803e7bb02b60c085eafd73f28f87a (diff) | |
download | chill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.gz chill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.bz2 chill-ad1cadf3512f3dd789151983e5c93af411f929db.zip |
restructure
Diffstat (limited to 'omegalib/omega_lib/include/basic/Collection.h')
-rw-r--r-- | omegalib/omega_lib/include/basic/Collection.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/omegalib/omega_lib/include/basic/Collection.h b/omegalib/omega_lib/include/basic/Collection.h new file mode 100644 index 0000000..c7e4eef --- /dev/null +++ b/omegalib/omega_lib/include/basic/Collection.h @@ -0,0 +1,47 @@ +#if !defined Already_Included_Collection +#define Already_Included_Collection + +namespace omega { + +template<class T> class Iterator; +template<class T> class Any_Iterator; + + +/* + * protocol for any kind of collection + */ + +template<class T> class Collection { +public: + virtual Iterator<T> *new_iterator() = 0; + virtual Any_Iterator<T> any_iterator() { return Any_Iterator<T>(new_iterator()); } + + virtual int size() const = 0; +}; + + +/* + * protocol for collections whose elements are ordered + * by the way they are entered into the collection, and + * whose elements can be accessed by "index" + * + * note that the implementation need not be a linked list + */ + +template<class T> class Sequence : public Collection<T> { +public: + virtual const T &operator[](int) const = 0; + virtual T &operator[](int) = 0; + + virtual int index(const T &) const = 0; // Y in X --> X[X.index(Y)] == Y +}; + +} // namespace + +#define instantiate_Collection(T) template class Collection<T>; \ + instantiate_Any_Iterator(T) +#define instantiate_Sequence(T) template class Sequence<T>; \ + instantiate_Collection(T) + +#endif + |