Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
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 "../include/elm/equiv.h"
24 
25 namespace elm { namespace concept {
26 
74 template <class T>
75 class Iter {
76 public:
77 
82  bool ended(void);
83 
87  void next(void);
88 
94  T item(void);
95 
99  operator bool(void);
100 
104  operator T (void);
105 
110 
116  Iter& operator=(const Iter& iterator);
117 
123  bool equals(const Iter& iterator) const;
124 
128  bool operator==(const Iter& iterator) const;
129 
133  bool operator!=(const Iter& iterator) const;
134 };
135 
136 
151 template <class T>
152 class MutableIter {
153 public:
154 
159  bool ended(void);
160 
164  void next(void);
165 
171  T& item(void);
172 
176  operator bool(void);
177 
182 
188  MutableIter& operator=(const MutableIter& iterator);
189 
195  bool equals(const MutableIter& iterator) const;
196 
200  bool operator==(const MutableIter& iterator) const;
201 
205  bool operator!=(const MutableIter& iterator) const;
206 };
207 
208 
227 template <class T>
228 class Collection {
229 public:
230 
234  typedef T t;
235 
240 
245  int count(void);
246 
252  bool contains(const T& item);
253 
260  template <template <class _> class C>
261  bool containsAll(const C<T>& collection);
262 
267  bool isEmpty(void);
268 
272  operator bool(void);
273 
278  class Iter: public concept::Iter<T> {
279  public:
280 
285  Iter(const Collection<T>& collection);
286 
287  };
288 
293  Iter begin(void) const;
294 
299  Iter end(void) const;
300 
304  static const Collection null;
305 
306 
312  bool equals(const Collection& coll);
313 
317  bool operator==(const Collection& coll);
318 
322  bool operator!=(const Collection& coll);
323 
327  static const Collection<T> null;
328 };
329 
330 
347 template <class T>
348 class MutableCollection: public Collection<T> {
349 public:
350 
356 
362 
366  void clear(void);
367 
372  void add(const T& item);
373 
378  void addAll(const Collection<T>& items);
379 
384  void remove(const T& item);
385 
390  void removeAll(const Collection<T>& items);
391 
396  void remove(const Iterator<T>& iter);
397 
402 
407 
412  void copy(const Collection<T>& items);
413 
420 
421 };
422 
423 
442 template <class T>
443 class Set: public MutableCollection<T> {
444 public:
445 
451  void insert(const T& item);
452 
458  bool subsetOf(const Set& coll);
459 
463  bool operator>=(const Set& coll);
464 
468  bool operator<=(const Set& coll);
469 
473  bool operator>(const Set& coll);
474 
478  bool operator<(const Collection& coll);
479 
483  bool operator<=(const T& item);
484 
485 
490  void join(const Set<T>& set);
491 
496  void meet(const Set<T>& set);
497 
502  void diff(const Set<T>& set);
503 
508 
513 
518 
523 
528 
533  Set<T> operator+(const Set& set);
534 
539  Set<T> operator|(const Set& set);
540 
545  Set<T> operator*(const Set& set);
546 
551  Set<T> operator&(const Set& set);
552 
557  Set<T> operator-(const Set& set);
558 
559 };
560 
561 
573 template <class T>
574 class Array: public Collection<T> {
575 public:
576 
580  int length(void);
581 
588  const T& get(int index) const;
589 
596  int indexOf(const T& value, int start = 0) const;
597 
604  int lastIndexOf(const T& value, int start = -1) const;
605 
609  const T& operator[](int index) const;
610 };
611 
612 
624 template <class T>
625 class MutableArray: public Array<T>, public MutableCollection<T> {
626 public:
627 
632  void shrink(int length);
633 
639  void set(int index, const T& item);
640 
646  void set(const Iterator& iter, const T& item);
647 
653  T& get(int index);
654 
658  T& operator[](int index);
659 
660 };
661 
662 
674 template <class T>
675 class ExpandableArray: public MutableArray<T>, public MutableCollection<T> {
676 public:
677 
682  void shrink(int length);
683 
690  void insert(int index, const T& item);
691 
698  void insert(const Iterator& iter, const T& item);
699 
705  void removeAt(int index);
706 
712  void removeAt(const Iterator& iter);
713 };
714 
715 
728 template <class T>
729 class Stack {
730 public:
731 
736  bool isEmpty(void) const;
737 
742  const T& top(void) const;
743 
749  T& top();
750 
755  T pop(void);
756 
761  void push(const T& item);
762 
766  void reset(void);
767 };
768 
769 
783 template <class T>
784 class Queue {
785 public:
786 
791  bool isEmpty(void) const;
792 
797  const T& head(void) const;
798 
803  T get(void);
804 
809  void put(const T& item);
810 
814  void reset(void);
815 
816 };
817 
818 
835 template <class T>
836 class Hash {
837 public:
838 
845  static t::uint32 hash(const T& object);
846 
854  static bool equals(const T& object1, const T& object2);
855 
861  t::uint32 computeHash(const T& object);
862 
870  bool isEqual(const T& object1, const T& object2);
871 
872 };
873 
874 
892 template <class T>
893 class Comparator {
894 public:
895 
904  static int compare(const T& object1, const T& object2);
905 
914  int doCompare(const T& object1, const T& object2);
915 
916 };
917 
918 
930 template <class T>
931 class Equiv {
932 public:
933 
941  static bool equals(const T& val1, const T& val2);
942 
950  static bool isEqual(const T& val1, const T& val2);
951 };
952 
953 
959 template <class T>
961 public:
962 
966  static const int EQUAL = 0x001;
967 
971  static const int LESS = 0x010;
972 
976  static const int GREATER = 0x100;
977 
981  static const int UNCOMP = 0x000;
982 
989  static bool equals(const T& v1, const T& v2);
990 
997  static bool greaterThan(const T& v1, const T& v2);
998 
1005  static bool lessThan(const T& v1, const T& v2);
1006 
1013  static int compare(const T& v1, const T& v2);
1014 };
1015 
1016 
1026 template <class K, class T>
1027 class Map: public Collection<T> {
1028 public:
1029 
1035  Option<const T&> get(const K& key) const;
1036 
1043  const T& get(const K& key, const T& def) const;
1044 
1050  bool hasKey(const K& key) const;
1051 
1055  class KeyIter: public Iter<K> {
1056  public:
1057 
1063 
1069  };
1070 
1075 
1079  class PairIterator: public Iter<Pair<K, T> > {
1080  public:
1081 
1087 
1093  };
1094 
1099 
1106  const T& operator[](const K& k) const;
1107 
1108 };
1109 
1110 
1120 template <class K, class T>
1121 class MutableMap: public Map<K, T> {
1122 public:
1123 
1127  void clear();
1128 
1134  void put(const K& key, const T& value);
1135 
1140  void removeByKey(const K& key);
1141 
1147 
1155  T& operator[](const K& k);
1156 };
1157 
1158 
1169 template <class T>
1170 class List: public Collection<T> {
1171 public:
1172 
1177  const T& first(void) const;
1178 
1183  const T& last(void) const;
1184 
1190  Iter<T> find(const T& item);
1191 
1198  Iter<T> find(const T& item, const Iterator& start);
1199 
1206  Iter<T> nth(int i);
1207 
1214  const T& operator[](int i) const;
1215 
1216 };
1217 
1218 
1229 template <class T>
1230 class MutableList: public List<T>, public MutableCollection<T> {
1231 public:
1232 
1237  T& first(void);
1238 
1243  T& last(void);
1244 
1249  void addFirst(const T& item);
1250 
1255  void addLast(const T& item);
1256 
1260  void removeFirst(void);
1261 
1265  void removeLast(void);
1266 
1272  void addAfter(const Iter<T>& pos, const T& item);
1273 
1279  void addBefore(const Iter<T>& pos, const T& item);
1280 
1286  void removeBefore(const Iter<T>& pos);
1287 
1292  void removeAfter(const Iter<T>& pos);
1293 
1299  void set(const Iterator<T>& pos, const T& item);
1300 
1307  T& operator[](int i);
1308 
1309 };
1310 
1311 
1322 template <class T>
1323 class BiDiList: public List<T> {
1324 public:
1325 
1329  class Iterator: public List<T>::Iterator {
1330  public:
1331  Iterator(const BiDiList<T>& list);
1335  };
1336 
1340  class BackIterator: public Iterator<T> {
1341  public:
1347  };
1348 };
1349 
1350 
1361 template <class K, class T>
1362 class Key {
1363 public:
1364 
1368  typedef K key_t;
1369 
1375  static const K& key(const T& value);
1376 };
1377 
1378 
1388 template <class T>
1389 class Compare {
1390 public:
1391  int compare(T v1, T v2);
1392 };
1393 
1394 
1402 template <class T>
1403 class Predicate {
1404 public:
1405 
1411  bool test(const T& item);
1412 };
1413 
1414 } } // elm::concept
Definition: util.h:220
Definition: Option.h:35
Definition: concepts.h:574
const T & get(int index) const
int lastIndexOf(const T &value, int start=-1) const
const T & operator[](int index) const
int indexOf(const T &value, int start=0) const
Definition: concepts.h:1340
BackIterator & operator=(const BackIterator< T > &iter)
BackIterator(const BackIterator< T > &iter)
BackIterator(const BiDiList< T > &list)
BackIterator & operator=(const Iterator< T > &iter)
BackIterator(const Iterator< T > &iter)
Definition: concepts.h:1329
Iterator(const Iterator< T > &iter)
Iterator(const BiDiList< T > &list)
Iterator(const BackIterator< T > &iter)
Iterator & operator=(const BackIterator< T > &iter)
Definition: concepts.h:1323
Definition: concepts.h:278
Iter(const Collection< T > &collection)
Definition: concepts.h:228
T t
Definition: concepts.h:234
bool operator==(const Collection &coll)
Iter end(void) const
Iter begin(void) const
bool containsAll(const C< T > &collection)
bool equals(const Collection &coll)
bool operator!=(const Collection &coll)
Collection< T > self_t
Definition: concepts.h:239
bool contains(const T &item)
Definition: concepts.h:893
static int compare(const T &object1, const T &object2)
int doCompare(const T &object1, const T &object2)
Definition: concepts.h:1389
int compare(T v1, T v2)
Definition: concepts.h:931
static bool equals(const T &val1, const T &val2)
static bool isEqual(const T &val1, const T &val2)
Definition: concepts.h:675
void removeAt(const Iterator &iter)
void insert(int index, const T &item)
void insert(const Iterator &iter, const T &item)
Definition: concepts.h:836
t::uint32 computeHash(const T &object)
static t::uint32 hash(const T &object)
bool isEqual(const T &object1, const T &object2)
static bool equals(const T &object1, const T &object2)
Definition: concepts.h:75
bool equals(const Iter &iterator) const
Iter & operator++(int)
bool operator!=(const Iter &iterator) const
Iter & operator=(const Iter &iterator)
bool operator==(const Iter &iterator) const
Definition: concepts.h:1362
K key_t
Definition: concepts.h:1368
static const K & key(const T &value)
Definition: concepts.h:1170
const T & operator[](int i) const
const T & last(void) const
Iter< T > nth(int i)
Iter< T > find(const T &item)
Iter< T > find(const T &item, const Iterator &start)
const T & first(void) const
Definition: concepts.h:1055
KeyIter(const KeyIter &iter)
KeyIter(const Map< K, T > &map)
Definition: concepts.h:1079
PairIterator(const ValueIterator &iter)
PairIterator(const Map< K, T > &map)
Definition: concepts.h:1027
Option< const T & > get(const K &key) const
const T & get(const K &key, const T &def) const
Iterable< PairIter > pairs() const
Iterable< KeyIter > keys() const
const T & operator[](const K &k) const
bool hasKey(const K &key) const
Definition: concepts.h:625
void shrink(int length)
void set(const Iterator &iter, const T &item)
void set(int index, const T &item)
Definition: concepts.h:348
MutableCollection< T > & operator-=(const T &item)
void copy(const Collection< T > &items)
void removeAll(const Collection< T > &items)
void remove(const T &item)
MutableCollection & operator=(const Collection< T > &c)
void remove(const Iterator< T > &iter)
void addAll(const Collection< T > &items)
MutableCollection< T > & operator+=(const T &item)
Definition: concepts.h:152
MutableIter & operator=(const MutableIter &iterator)
MutableIter & operator++(int)
bool equals(const MutableIter &iterator) const
bool operator!=(const MutableIter &iterator) const
bool operator==(const MutableIter &iterator) const
Definition: concepts.h:1230
void addBefore(const Iter< T > &pos, const T &item)
void addFirst(const T &item)
void removeAfter(const Iter< T > &pos)
void set(const Iterator< T > &pos, const T &item)
void addLast(const T &item)
void removeBefore(const Iter< T > &pos)
void addAfter(const Iter< T > &pos, const T &item)
Definition: concepts.h:1121
void remove(const Collection< T >::Iter &iter)
void put(const K &key, const T &value)
void removeByKey(const K &key)
T & operator[](const K &k)
Definition: concepts.h:960
static const int LESS
Definition: concepts.h:971
static const int GREATER
Definition: concepts.h:976
static int compare(const T &v1, const T &v2)
static bool greaterThan(const T &v1, const T &v2)
static const int UNCOMP
Definition: concepts.h:981
static bool equals(const T &v1, const T &v2)
static bool lessThan(const T &v1, const T &v2)
static const int EQUAL
Definition: concepts.h:966
Definition: concepts.h:1403
bool test(const T &item)
Definition: concepts.h:784
const T & head(void) const
void put(const T &item)
bool isEmpty(void) const
Definition: concepts.h:443
Set< T > operator*(const Set &set)
bool operator>(const Set &coll)
Set< T > operator|=(const Set< T > set)
bool subsetOf(const Set &coll)
bool operator>=(const Set &coll)
Set< T > operator*=(const Set< T > set)
Set< T > operator&=(const Set< T > set)
Set< T > operator+(const Set &set)
Set< T > operator-=(const Set< T > set)
Set< T > operator-(const Set &set)
void diff(const Set< T > &set)
Set< T > operator|(const Set &set)
bool operator<=(const T &item)
bool operator<(const Collection &coll)
Set< T > operator&(const Set &set)
void join(const Set< T > &set)
Set< T > operator+=(const Set< T > set)
bool operator<=(const Set &coll)
void meet(const Set< T > &set)
void insert(const T &item)
Definition: concepts.h:729
void push(const T &item)
const T & top(void) const
bool isEmpty(void) const
Definition: util_WAHVector.cpp:157
void map(const C &c, const F &f, D &d)
Definition: util.h:89
unsigned int uint32
Definition: arch.h:31
Definition: adapter.h:26