Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / util / tt_list.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: tt_list.h /main/3 1995/10/23 10:41:02 rswiston $                                                     */
28 /*-*-C++-*-
29  *
30  * list.h
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  *
34  */
35 #if !defined(_LIST_H)
36 #define _LIST_H
37 #include <util/tt_ptr.h>
38 #include <util/tt_object.h>
39 #include <util/tt_object_list.h>
40 #include <util/tt_assert.h>
41
42 #define list_of(t) name2(t,_list)
43 #define ptr_to_list_of(t) name2(t,_list_ptr)
44 #define cursor_in_list_of(t) name2(t,_list_cursor)
45
46 #define declare_list_of(TYPE) declare_derived_list_of(TYPE,_Tt_object)
47
48 // Note that list_of always declares a append_ordered function, but this
49 // is implemented only for a very few classes.  The implementation
50 // cannot be shared as append_ordered, unlike other functions, actually
51 // needs to understand the contents of the elements of the list.
52
53 #define declare_derived_list_of(TYPE,PARENT)                                 \
54 declare_derived_ptr_to(TYPE,PARENT)                                          \
55 declare_derived_ptr_to(list_of(TYPE),list_of(PARENT))                        \
56                                                                              \
57 class list_of(TYPE) : public list_of(PARENT) {                               \
58     friend class cursor_in_list_of(TYPE);                                    \
59       public:                                                                \
60         list_of(TYPE)();                                                     \
61         list_of(TYPE)(const list_of(TYPE) &t): list_of(PARENT)(t) {}         \
62         ~list_of(TYPE)();                                                    \
63                                                                              \
64         void                            flush()                              \
65         { _Tt_object_list::flush(); }                                        \
66         list_of(TYPE)&                  push(const ptr_to(TYPE) &e)          \
67         { return (list_of(TYPE)&)_Tt_object_list::push(e); }                 \
68         list_of(TYPE)&                  pop()                                \
69         { return (list_of(TYPE)&)_Tt_object_list::pop(); }                   \
70         list_of(TYPE)&                  append(const ptr_to(TYPE) &e)        \
71         { return (list_of(TYPE)&)_Tt_object_list::append(e); }               \
72         list_of(TYPE)&                  append_ordered(const ptr_to(TYPE) &e);\
73         list_of(TYPE)&                  append(ptr_to_list_of(TYPE) l)       \
74         { return (list_of(TYPE)&)_Tt_object_list::append(l); }               \
75         list_of(TYPE)&          append_destructive(ptr_to_list_of(TYPE) l)   \
76         { return (list_of(TYPE)&)_Tt_object_list::append_destructive(l); }   \
77         list_of(TYPE)&                  dequeue()                            \
78         { return (list_of(TYPE)&)_Tt_object_list::dequeue(); }               \
79         ptr_to(TYPE)&                   top() const                          \
80         { return (ptr_to(TYPE)&)_Tt_object_list::top(); }                    \
81         ptr_to(TYPE)&                   bot() const                          \
82         { return (ptr_to(TYPE)&)_Tt_object_list::bot(); }                    \
83         ptr_to(TYPE)&                   operator[] (int n) const             \
84         { return (ptr_to(TYPE)&)_Tt_object_list::operator[](n); }            \
85                                                                              \
86         int                             is_empty() const                     \
87         { return _Tt_object_list::is_empty(); }                              \
88         int                             count() const                        \
89         { return _Tt_object_list::count(); }                                 \
90         bool_t                          xdr(XDR *xdrs);                      \
91 };                                                                           \
92                                                                              \
93 class cursor_in_list_of(TYPE) : public _Tt_object_list_cursor {              \
94       public:                                                                \
95         cursor_in_list_of(TYPE)() {}                                         \
96         cursor_in_list_of(TYPE)(const cursor_in_list_of(TYPE) &c):           \
97                 _Tt_object_list_cursor(c) {}                                 \
98         cursor_in_list_of(TYPE)(const ptr_to_list_of(TYPE) &l):              \
99                 _Tt_object_list_cursor(l) {}                                 \
100         ~cursor_in_list_of(TYPE)();                                          \
101         /* overload * (pointer deref) to mean "get contents of element       \
102          * under cursor".*/                                                  \
103         ptr_to(TYPE)                    &operator*() const                   \
104         { return (ptr_to(TYPE)&)_Tt_object_list_cursor::operator*(); }       \
105         ptr_to(TYPE)                    &operator->() const                  \
106         { return (ptr_to(TYPE)&)_Tt_object_list_cursor::operator*(); }       \
107         cursor_in_list_of(TYPE)&        reset()                              \
108         { return (cursor_in_list_of(TYPE)&)_Tt_object_list_cursor::reset(); }\
109         cursor_in_list_of(TYPE)&        reset(const ptr_to_list_of(TYPE) &l) \
110         { return (cursor_in_list_of(TYPE)&)_Tt_object_list_cursor::reset(l);}\
111         int                             next()                               \
112         { return _Tt_object_list_cursor::next(); }                           \
113         int                             prev()                               \
114         { return _Tt_object_list_cursor::prev(); }                           \
115         cursor_in_list_of(TYPE)&        insert(const ptr_to(TYPE) &p)        \
116         { return (cursor_in_list_of(TYPE)&)_Tt_object_list_cursor::insert(p);}\
117         cursor_in_list_of(TYPE)&        remove()                             \
118         { return (cursor_in_list_of(TYPE)&)_Tt_object_list_cursor::remove();}\
119         int                             is_valid() const                     \
120         { return _Tt_object_list_cursor::is_valid(); }                       \
121 };
122
123 #define implement_list_of(TYPE)                                               \
124 implement_derived_ptr_to(TYPE,_Tt_object)                                     \
125 implement_derived_ptr_to(list_of(TYPE),_Tt_object_list)                       \
126 list_of(TYPE)::                                                               \
127 list_of(TYPE)()                                                               \
128 {                                                                             \
129 }                                                                             \
130 list_of(TYPE)::                                                               \
131 ~list_of(TYPE)()                                                              \
132 {                                                                             \
133 }                                                                             \
134                                                                               \
135 bool_t  list_of(TYPE)::                                                       \
136 xdr(XDR *xdrs)                                                                \
137 {                                                                             \
138         return _Tt_object_list::xdr(xdrs,                                     \
139                                     (_Tt_new_xdrfn)xdrfn_of(TYPE),            \
140                                     (_Tt_object *(*)())                       \
141                                     constructor_of(TYPE));                    \
142 }                                                                             \
143                                                                               \
144 cursor_in_list_of(TYPE)::                                                     \
145 ~cursor_in_list_of(TYPE)()                                                    \
146 {                                                                             \
147 }
148
149 #endif