1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef stackable_collection_h
26 #define stackable_collection_h
28 ////////////////////////////////////////////////////////////////////////////
29 // Stackable collection
30 ////////////////////////////////////////////////////////////////////////////
31 #include <AD/collect/seqcol.h>
33 template <class T
, class S
>
34 class StackableCollection
: SequenceableCollection
<T
> {
36 S stack
; // implementation
39 ////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////
42 typedef SequenceableCollection
<T
> Super
;
43 typedef Super::Element Element
;
45 ////////////////////////////////////////////////////////////////
46 // Constructor and destructor
47 ////////////////////////////////////////////////////////////////
48 StackableCollection(int initial_size
) : stack(initial_size
) {}
49 StackableCollection(const Collection
<T
>& C
)
50 : stack(initial_size
) { *this = C
; }
51 StackableCollection(const StackableCollection
& C
)
52 : stack(initial_size
) { *this = C
; }
53 ~StackableCollection() {}
55 ////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////
58 // void operator = (const Collection<T>&); // inherited
60 ////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////
63 int size() const { return stack
.size(); }
64 int capacity() const { return stack
.capacity(); }
65 // virtual Bool is_empty() const; // inherited
66 // virtual Bool is_full() const; // inherited
67 // virtual Bool contains(const T&) const; // inherited
68 virtual T
& top() const { return stack
.top(); }
70 ////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////
73 virtual void clear() { return stack
.clear(); }
74 virtual Ix
insert(const T
& e
) { stack
.push(e
); return &top(); }
75 virtual Bool
remove(const T
& e
) { should_not_implement("remove"); }
76 virtual void push(const T
& e
) { stack
.push(e
); }
77 virtual T
& pop() { return stack
.pop(e
); }
79 ////////////////////////////////////////////////////////////////
81 ////////////////////////////////////////////////////////////////
82 Ix
first() const { return size() == 0 ? 0 : 0; }
84 { return i
>= (Ix
)((T
*)stack
+ size()) ? 0 : (((T
*)i
)+1); }
85 T
& operator () (Ix i
) const { return *(T
*)i
; }
87 ////////////////////////////////////////////////////////////////
89 ////////////////////////////////////////////////////////////////
90 const char * myName() const { return "StackableCollection"; }