From ad1cadf3512f3dd789151983e5c93af411f929db Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 19:27:15 +0000 Subject: restructure --- omegalib/omega_lib/include/basic/Bag.h | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 omegalib/omega_lib/include/basic/Bag.h (limited to 'omegalib/omega_lib/include/basic/Bag.h') diff --git a/omegalib/omega_lib/include/basic/Bag.h b/omegalib/omega_lib/include/basic/Bag.h new file mode 100644 index 0000000..42285d0 --- /dev/null +++ b/omegalib/omega_lib/include/basic/Bag.h @@ -0,0 +1,78 @@ +#if ! defined _Bag_h +#define _Bag_h 1 + +#include +#include +#include +#include + +namespace omega { + +template class Bag : public Collection { +public: +virtual ~Bag(); + Bag(); + Bag(const Bag&); + Bag & operator=(const Bag&); +virtual void operator |= (const Bag & b); // add elements in b + Iterator *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* contents; +}; + + +template class Ordered_Bag : public Bag { +public: + Ordered_Bag(); +// virtual ~Ordered_Bag(); + Ordered_Bag(const Ordered_Bag& B) : Bag(B) {} + void insert(T); +virtual void operator |= (const Ordered_Bag & b); // add elements in b + void operator |= (const Bag & b); + bool contains(T) const; + bool operator == (const Ordered_Bag&) const; + bool operator != (const Ordered_Bag&) const; + bool operator < (const Ordered_Bag&) const; +}; + +template class Set : public Ordered_Bag { +public: + Set(); +// virtual ~Set(); + Set(T); + Set(const Set& S) : Ordered_Bag(S) {} + + bool contains (const Set& b) const; + bool contains (T t) const { return Ordered_Bag::contains(t); } + // the above makes "standard" C++ happy + +virtual void operator |= (const Set & b); // add elements in b + void operator |= (const Ordered_Bag & b); + void operator |= (const Bag & b); + + void operator -= (const Set & b); // delete items also in b + void operator &= (const Set & b); // delete items not in b + bool operator & (const Set &) const; // check for elements in common +}; + +} // namespace + +#if ! defined DONT_INCLUDE_TEMPLATE_CODE +#include +#endif + +#define instantiate_Bag(T) template class Bag; \ + instantiate_List_Element(T); +#define instantiate_Ordered_Bag(T) template class Ordered_Bag; \ + instantiate_Bag(T) +#define instantiate_Set(T) template class Set; \ + instantiate_Ordered_Bag(T) + +#endif -- cgit v1.2.3-70-g09d2