simple.cc - generated code example
[prop.git] / include / AD / contain / slist.h
blob337f55fcbb25f3734829f862593ae1529f540c0a
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 singly_linked_list_h
26 #define singly_linked_list_h
28 #include <AD/generic/generic.h>
29 #include <AD/contain/slink.h>
31 class SList {
33 int len; // current length of list
34 SLink * front; // front of the list
36 SList(const SList&); // no copy constructor
37 void operator = (const SList&); // no assignment
39 public:
41 ///////////////////////////////////////////////////////////////
42 // Constructors and destructor
43 ///////////////////////////////////////////////////////////////
44 SList() : len(0), front(0) {}
45 ~SList() { clear(); }
47 ///////////////////////////////////////////////////////////////
48 // Selectors
49 ///////////////////////////////////////////////////////////////
50 int length() const { return len; }
51 int capacity() const { return len; }
52 Bool is_empty() const { return len == 0; }
53 Bool is_full() const { return false; }
55 ///////////////////////////////////////////////////////////////
56 // Mutators
57 ///////////////////////////////////////////////////////////////
58 void clear();
59 void insert_head(SLink *);
60 SLink * delete_head();
61 void insert_after(SLink *, SLink *);
63 ///////////////////////////////////////////////////////////////
64 // Iterators
65 ///////////////////////////////////////////////////////////////
66 SLink * first() const { return front; }
67 SLink * next(SLink * l) const { return l->next; }
68 SLink * circ_next(SLink * l) const { return l->next ? l->next : front; }
71 #endif