Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
AbstractCollection.h
1 /*
2  * $Id$
3  * AbstractCollection class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2004-08, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_DYNDATA_ABSTRACTCOLLECTION_H
23 #define ELM_DYNDATA_ABSTRACTCOLLECTION_H
24 
25 #include <elm/PreIterator.h>
26 #include <elm/ptr.h>
27 
28 namespace elm { namespace dyndata {
29 
30 // IteratorInst class
31 template <class T>
32 class AbstractIter: public Lock {
33 public:
34  virtual ~AbstractIter(void) { }
35  virtual bool ended(void) const = 0;
36  virtual T item(void) const = 0;
37  virtual void next(void) = 0;
38 };
39 
40 
41 // Iterator class
42 template <class T>
43 class Iter: public PreIterator<Iter<T>, T> {
44 public:
45  inline Iter(AbstractIter<T> *iter): i(iter) { }
46  inline Iter(const Iter<T>& iter): i(iter.i) { }
47  inline AbstractIter<T> *instance(void) const { return &i; }
48  inline bool ended(void) const { return i->ended(); }
49  inline T item(void) const { return i->item(); }
50  inline void next(void) { i->next(); }
51  inline Iter<T>& operator=(const Iter<T>& iter) { i = iter.i; return *this; }
52 protected:
54 };
55 
56 // AbstractCollection class
57 template <class T>
59 public:
60  virtual ~AbstractCollection(void) { }
61  virtual int count(void) = 0;
62  virtual bool contains(const T& item) const = 0;
63  virtual bool isEmpty(void) const = 0;
64  inline operator bool(void) const { return !isEmpty(); }
65  virtual Iter<T> items(void) const = 0;
66  inline Iter<T> operator*(void) const { return items(); }
67 };
68 
69 // MutableAbstractCollection class
70 template <class T>
72 public:
73  virtual ~MutableAbstractCollection(void) { }
74  virtual void clear(void) = 0;
75  virtual void add(const T& item) = 0;
76  virtual void addAll(const AbstractCollection<T>& items) = 0;
77  virtual void remove(const T& item) = 0;
78  virtual void removeAll(const AbstractCollection<T>& items) = 0;
79  virtual void remove(const Iter<T>& iter) = 0;
80 };
81 
82 } } // elm::dyndata
83 
84 #endif // ELM_DYNDATA_ABSTRACTCOLLECTION_H
elm::dyndata::AbstractIter::next
virtual void next(void)=0
elm::dyndata::Iter::Iter
Iter(AbstractIter< T > *iter)
Definition: AbstractCollection.h:45
elm::iter
Definition: util_WAHVector.cpp:157
elm::dyndata::AbstractIter
Definition: AbstractCollection.h:32
elm::dyndata::MutableAbstractCollection::add
virtual void add(const T &item)=0
elm::Lock
Definition: LockPtr.h:29
elm::dyndata::Iter::item
T item(void) const
Definition: AbstractCollection.h:49
elm::dyndata::AbstractIter::ended
virtual bool ended(void) const =0
elm::dyndata::AbstractCollection
Definition: AbstractCollection.h:58
elm::dyndata::AbstractIter::~AbstractIter
virtual ~AbstractIter(void)
Definition: AbstractCollection.h:34
elm::dyndata::AbstractCollection::items
virtual Iter< T > items(void) const =0
elm::dyndata::AbstractCollection::contains
virtual bool contains(const T &item) const =0
elm::dyndata::AbstractCollection::~AbstractCollection
virtual ~AbstractCollection(void)
Definition: AbstractCollection.h:60
elm::dyndata::MutableAbstractCollection::~MutableAbstractCollection
virtual ~MutableAbstractCollection(void)
Definition: AbstractCollection.h:73
elm::dyndata::Iter
Definition: AbstractCollection.h:43
elm::dyndata::Iter::i
LockPtr< AbstractIter< T > > i
Definition: AbstractCollection.h:53
bool
elm::dyndata::Iter::operator=
Iter< T > & operator=(const Iter< T > &iter)
Definition: AbstractCollection.h:51
elm::dyndata::MutableAbstractCollection::removeAll
virtual void removeAll(const AbstractCollection< T > &items)=0
elm::dyndata::AbstractIter::item
virtual T item(void) const =0
elm::dyndata::AbstractCollection::count
virtual int count(void)=0
elm
Definition: adapter.h:26
elm::dyndata::MutableAbstractCollection
Definition: AbstractCollection.h:71
elm::dyndata::Iter::instance
AbstractIter< T > * instance(void) const
Definition: AbstractCollection.h:47
elm::dyndata::AbstractCollection::isEmpty
virtual bool isEmpty(void) const =0
elm::dyndata::AbstractCollection::operator*
Iter< T > operator*(void) const
Definition: AbstractCollection.h:66
elm::LockPtr
Definition: LockPtr.h:40
elm::dyndata::Iter::ended
bool ended(void) const
Definition: AbstractCollection.h:48
elm::PreIterator
Definition: iter.h:28
elm::dyndata::MutableAbstractCollection::clear
virtual void clear(void)=0
elm::dyndata::MutableAbstractCollection::remove
virtual void remove(const T &item)=0
elm::dyndata::Iter::next
void next(void)
Definition: AbstractCollection.h:50
elm::dyndata::Iter::Iter
Iter(const Iter< T > &iter)
Definition: AbstractCollection.h:46
elm::dyndata::MutableAbstractCollection::addAll
virtual void addAll(const AbstractCollection< T > &items)=0