initial
[prop.git] / include / AD / contain / basiccol.h
blobae6cd49a9d4c0cc8052f6f8675038e4a54c74e5d
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
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
9 // your programs.
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
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef basic_collection_h
26 #define basic_collection_h
28 ///////////////////////////////////////////////////////////////////////////
29 // Collection is the base class at the root of the collection hierarchy.
30 // Its purpose is to factor out some of the common method and implement
31 // them once.
32 ///////////////////////////////////////////////////////////////////////////
33 #include <AD/generic/generic.h>
35 ////////////////////////////////////////////////////////////////////////////
36 // Collection class
37 ////////////////////////////////////////////////////////////////////////////
38 class BasicCollection {
39 public:
41 /////////////////////////////////////////////////////
42 // Parameters used by all subclasses
43 /////////////////////////////////////////////////////
44 // const int default_size = 32;
45 // const int default_growth = 64;
46 #define Collection_default_size 32
47 #define Collection_default_growth 64
49 /////////////////////////////////////////////////////
50 // Constructor and destructor
51 /////////////////////////////////////////////////////
52 BasicCollection() {} // do nothing
53 virtual ~BasicCollection() {} // do nothing
55 ////////////////////////////////////////////////////////
56 // Selectors:
57 // size() --- number of elements in collection
58 // capacity() --- current capacity(may change)
59 // is_empty() --- is it empty??
60 // is_full() --- is it full??
61 // contains() --- does it contain a specific element
62 /////////////////////////////////////////////////////////
63 virtual int size() const;
64 virtual int capacity() const = 0;
65 virtual Bool is_empty() const { return first() == 0; }
66 virtual Bool is_full() const { return capacity() == size(); }
68 ////////////////////////////////////////////////////////
69 // Mutators:
70 // empties the collection
71 ////////////////////////////////////////////////////////
72 virtual void clear() = 0; // empties the collection
74 ////////////////////////////////////////////////////////
75 // Iteration:
76 // first() --- returns the index of the first
77 // element(notice the position maybe
78 // arbitrary).
79 // next() --- get the next element.
80 // These two functions will return 0 if we have
81 // exhausted the elements.
82 ////////////////////////////////////////////////////////
83 virtual Ix first() const = 0;
84 virtual Ix next(Ix) const = 0;
86 ////////////////////////////////////////////////////////
87 // Each concrete subclass should define this method
88 ////////////////////////////////////////////////////////
89 virtual const char * myName() const = 0;
91 protected:
93 /////////////////////////////////////////////////////
94 // Miscellaneous
95 /////////////////////////////////////////////////////
96 void should_not_implement(const char method_name[]) const;
99 #endif