Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
concepts.h
1 /*
2  * $Id$
3  * Concepts documentation
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007-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 
23 #include <elm/util/Equiv.h>
24 
25 namespace elm { namespace concept {
26 
73 template <class T>
74 class Iterator {
75 public:
76 
81  Iterator(const Iterator& iterator);
82 
87  bool ended(void);
88 
92  void next(void);
93 
99  const T& item(void);
100 
104  operator bool(void);
105 
109  operator const T& (void);
110 
114  Iterator& operator++(int);
115 
121  Iterator& operator=(const Iterator& iterator);
122 };
123 
124 
138 template <class T, template <class _> class E = Equiv<T> >
139 class Collection {
140 public:
141 
146  int count(void);
147 
153  bool contains(const T& item);
154 
161  template <template <class _> class C>
162  bool containsAll(const C<T>& collection);
163 
168  bool isEmpty(void);
169 
173  operator bool(void);
174 
179  class Iterator: public concept::Iterator<T> {
180  public:
181 
186  Iter(const Collection<T>& collection);
187 
192  Iter(const Collection<T> *collection);
193  };
194 };
195 
196 
203 template <class T>
204 class MutableCollection: public Collection<T> {
205 public:
206 
210  void clear(void);
211 
216  void add(const T& item);
217 
222  void addAll(const Collection<T>& items);
223 
228  void remove(const T& item);
229 
234  void removeAll(const Collection<T>& items);
235 
240  void remove(const Iterator<T>& iter);
241 };
242 
243 
255 template <class T>
256 class Set: public MutableCollection<T> {
257 public:
258 
264  void insert(const T& item);
265 };
266 
267 
273 template <class T>
274 class Array: public Collection<T> {
275 public:
276 
280  int length(void);
281 
288  const T& get(int index) const;
289 
296  int indexOf(const T& value, int start = 0) const;
297 
304  int lastIndexOf(const T& value, int start = -1) const;
305 
309  const T& operator[](int index) const;
310 };
311 
312 
318 template <class T>
319 class MutableArray: public Array<T>, public MutableCollection<T> {
320 public:
321 
326  void shrink(int length);
327 
333  void set(int index, const T& item);
334 
340  void set(const Iterator& iter, const T& item);
341 
347  T& get(int index);
348 
352  T& operator[](int index);
353 
360  void insert(int index, const T& item);
361 
368  void insert(const Iterator& iter, const T& item);
369 
375  void removeAt(int index);
376 
382  void removeAt(const Iterator& iter);
383 };
384 
385 
391 template <class T>
392 class Stack {
393 public:
394 
399  bool isEmpty(void) const;
400 
405  const T& top(void) const;
406 
411  T pop(void);
412 
417  void push(const T& item);
418 
422  void reset(void);
423 };
424 
425 
431 template <class T>
432 class Queue {
433 public:
434 
439  bool isEmpty(void) const;
440 
445  const T& head(void) const;
446 
451  T get(void);
452 
457  void put(const T& item);
458 
462  void reset(void);
463 
464 };
465 
466 
472 template <class T>
473 class Hash {
474 public:
475 
481  static unsigned long hash(const T& object);
482 
489  static inline bool equals(const T& object1, const T& object2);
490 };
491 
492 
507 template <class T>
508 class Comparator {
509 public:
510 
518  static int compare(const T& object1, const T& object2);
519 };
520 
521 
533 template <class T>
534 class Equiv {
535 public:
536 
543  static bool equals(const T& val1, const T& val2);
544 };
545 
546 
552 template <class T>
554 public:
555 
559  static const int EQUAL = 0x001;
560 
564  static const int LESS = 0x010;
565 
569  static const int GREATER = 0x100;
570 
574  static const int UNCOMP = 0x000;
575 
582  static bool equals(const T& v1, const T& v2);
583 
590  static bool greaterThan(const T& v1, const T& v2);
591 
598  static bool lessThan(const T& v1, const T& v2);
599 
606  static int compare(const T& v1, const T& v2);
607 };
608 
609 
620 template <class K, class T>
621 class Map: public Collection<Pair<K, T> > {
622 public:
623 
629  Option<const T&> get(const K& key) const;
630 
637  const T& get(const K& key, const T& def) const;
638 
644  bool hasKey(const K& key) const;
645 
649  class KeyIterator: public Iterator<K> {
650  public:
651 
656  KeyIterator(const Map<K, T>& map);
657 
662  KeyIterator(const KeyIterator& iter);
663  };
664 
668  class PairIterator: public Iterator<Pair<K, T> > {
669  public:
670 
675  PairIterator(const Map<K, T>& map);
676 
681  PairIterator(const ValueIterator& iter);
682  };
683 };
684 
685 
696 template <class K, class T>
697 class MutableMap: public Map<K, T>, public Collection<Pair<K, T> > {
698 public:
699 
705  void put(const K& key, const T& value);
706 
711  void remove(const K& key);
712 
717  void remove(const PairIterator& iter);
718 };
719 
720 
731 template <class T>
732 class List: public Collection<T> {
733 public:
734 
739  const T& first(void);
740 
745  const T& last(void);
746 
752  Iterator<T> find(const T& item);
753 
760  Iterator<T> find(const T& item, const Iterator& start);
761 };
762 
763 
774 template <class T>
775 class MutableList: public List<T>, public MutableCollection<T> {
776 public:
777 
782  void addFirst(const T& item);
783 
788  void addLast(const T& item);
789 
793  void removeFirst(void);
794 
798  void removeLast(void);
799 
805  void addAfter(const Iterator<T>& pos, const T& item);
806 
812  void addBefore(const Iterator<T>& pos, const T& item);
813 
819  void set(const Iterator<T>& pos, const T& item);
820 };
821 
822 
833 template <class T>
834 class BiDiList: public List<T> {
835 public:
836 
840  class Iterator: public List<T>::Iterator {
841  public:
842  Iterator(const BiDiList<T>& list);
843  Iterator(const Iterator<T>& iter);
844  Iterator(const BackIterator<T>& iter);
845  Iterator& operator=(const BackIterator<T>& iter);
846  };
847 
851  class BackIterator: public Iterator<T> {
852  public:
853  BackIterator(const BiDiList<T>& list);
854  BackIterator(const BackIterator<T>& iter);
855  BackIterator(const Iterator<T>& iter);
856  BackIterator& operator=(const BackIterator<T>& iter);
857  BackIterator& operator=(const Iterator<T>& iter);
858  };
859 };
860 
861 
872 template <class K, class T>
873 class Key {
874 public:
875 
879  typedef K key_t;
880 
886  static const K& key(const T& value);
887 };
888 
889 } } // elm::concept
Iterator & operator=(const BackIterator< T > &iter)
static const int UNCOMP
Definition: concepts.h:574
bool isEmpty(void) const
const T & head(void) const
BackIterator(const BiDiList< T > &list)
void addBefore(const Iterator< T > &pos, const T &item)
void addFirst(const T &item)
Definition: concepts.h:668
Definition: concepts.h:256
void push(const T &item)
KeyIterator(const Map< K, T > &map)
void insert(const T &item)
void put(const K &key, const T &value)
static bool greaterThan(const T &v1, const T &v2)
Definition: concepts.h:873
static bool equals(const T &val1, const T &val2)
Definition: concepts.h:851
Definition: concepts.h:508
bool hasKey(const K &key) const
const T & top(void) const
void insert(int index, const T &item)
static bool equals(const T &object1, const T &object2)
void set(const Iterator< T > &pos, const T &item)
Definition: concepts.h:649
Definition: concepts.h:840
PairIterator(const Map< K, T > &map)
static bool lessThan(const T &v1, const T &v2)
void addAfter(const Iterator< T > &pos, const T &item)
const T & operator[](int index) const
Definition: concepts.h:534
Definition: concepts.h:432
value_t value(CString name, int value)
Definition: rtti.h:40
Definition: concepts.h:274
void removeAll(const Collection< T > &items)
void removeAt(int index)
Definition: concepts.h:621
Definition: concepts.h:834
Definition: Option.h:22
Definition: concepts.h:775
K key_t
Definition: concepts.h:879
void addLast(const T &item)
Iterator & operator=(const Iterator &iterator)
Iterator(const BiDiList< T > &list)
Definition: concepts.h:553
static const int LESS
Definition: concepts.h:564
void put(const T &item)
bool isEmpty(void) const
void shrink(int length)
static int compare(const T &v1, const T &v2)
const T & last(void)
Definition: concepts.h:179
static const int EQUAL
Definition: concepts.h:559
Definition: concepts.h:732
void addAll(const Collection< T > &items)
Definition: concepts.h:139
Iter(const Collection< T > &collection)
Definition: concepts.h:204
Iterator(const Iterator &iterator)
Definition: concepts.h:697
const T & item(void)
static int compare(const T &object1, const T &object2)
bool containsAll(const C< T > &collection)
static unsigned long hash(const T &object)
int indexOf(const T &value, int start=0) const
static const K & key(const T &value)
Definition: concepts.h:473
Definition: concepts.h:74
Iterator & operator++(int)
bool contains(const T &item)
Iterator< T > find(const T &item)
Definition: concepts.h:319
BackIterator & operator=(const BackIterator< T > &iter)
static const int GREATER
Definition: concepts.h:569
static bool equals(const T &v1, const T &v2)
int lastIndexOf(const T &value, int start=-1) const
const T & first(void)
void set(int index, const T &item)
Definition: concepts.h:392