2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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 $ */
32 * Copyright (c) 1990 by Sun Microsystems, Inc.
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>
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)
46 #define declare_list_of(TYPE) declare_derived_list_of(TYPE,_Tt_object)
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.
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)) \
57 class list_of(TYPE) : public list_of(PARENT) { \
58 friend class cursor_in_list_of(TYPE); \
61 list_of(TYPE)(const list_of(TYPE) &t): list_of(PARENT)(t) {} \
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); } \
86 int is_empty() const \
87 { return _Tt_object_list::is_empty(); } \
89 { return _Tt_object_list::count(); } \
90 bool_t xdr(XDR *xdrs); \
93 class cursor_in_list_of(TYPE) : public _Tt_object_list_cursor { \
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 \
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);}\
112 { return _Tt_object_list_cursor::next(); } \
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(); } \
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) \
135 bool_t list_of(TYPE):: \
138 return _Tt_object_list::xdr(xdrs, \
139 (_Tt_new_xdrfn)xdrfn_of(TYPE), \
140 (_Tt_object *(*)()) \
141 constructor_of(TYPE)); \
144 cursor_in_list_of(TYPE):: \
145 ~cursor_in_list_of(TYPE)() \