summaryrefslogtreecommitdiff
path: root/omegalib/omega/include/basic/Bag.h
blob: 3bd7143f832b94c1c67f698b2d2661a2c41e9a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#if ! defined _Bag_h
#define _Bag_h 1

#include <stdio.h>
#include <basic/Iterator.h>
#include <basic/Collection.h>
#include <basic/Link.h>

namespace omega {

template<class T> class Bag : public Collection<T> { 
public:
virtual ~Bag();
	Bag();
	Bag(const Bag<T>&);
	Bag & operator=(const Bag<T>&);
    //! add elements in b
    virtual	void operator |= (const Bag<T> & b);
	Iterator<T> *new_iterator();
	bool empty() const;
	void remove(T);
    virtual	void insert(T);
	void clear();
    virtual	bool contains(T) const;
	int size() const;
	T extract();
// protected:  breaks g++ 261
	List_Element<T>* contents;
};


template<class T> class Ordered_Bag : public Bag<T> { 
public:
	Ordered_Bag();
	Ordered_Bag(const Ordered_Bag<T>& B) : Bag<T>(B) {}
	void insert(T);
    //! add elements in b
    virtual	void operator |= (const Ordered_Bag<T> & b);
    //! add elements in b
	void operator |= (const Bag<T> & b);
	bool  contains(T) const;
        bool  operator == (const Ordered_Bag<T>&) const;
        bool  operator != (const Ordered_Bag<T>&) const;
        bool  operator <  (const Ordered_Bag<T>&) const;
};

template <class T> class Set : public Ordered_Bag <T> { 
public:
	Set();
	Set(T);
	Set(const Set<T>& S) : Ordered_Bag<T>(S) {}

        bool  contains (const Set<T>& b) const;
        bool  contains (T t) const { return Ordered_Bag<T>::contains(t); }
	// the above makes "standard" C++ happy
    
    //! add elements in b
    virtual	void operator |= (const Set<T> & b);
    //! add elements in b
	void operator |= (const Ordered_Bag<T> & b);
    //! add elements in b
	void operator |= (const Bag<T> & b);

    //! delete items also in b
    void operator -= (const Set<T> & b);
    //! delete items not in b
    void operator &= (const Set<T> & b);
    //! check for elements in common
    bool operator & (const Set<T> &) const;
};

} // namespace

#if ! defined DONT_INCLUDE_TEMPLATE_CODE
#include <basic/Bag.c>
#endif

#define instantiate_Bag(T)		template class Bag<T>; \
					instantiate_List_Element(T);
#define instantiate_Ordered_Bag(T)	template class Ordered_Bag<T>; \
					instantiate_Bag(T)
#define instantiate_Set(T)		template class Set<T>; \
					instantiate_Ordered_Bag(T)

#endif