]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/lists.h
2 * Copyright 1993, 1995 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2022 René Ferdinand Rivera Morell
9 * Copyright 2001-2004 David Abrahams.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
15 * lists.h - the LIST structure and routines to manipulate them
17 * The whole of jam relies on lists of objects as a datatype. This module, in
18 * conjunction with object.c, handles these relatively efficiently.
22 * LIST - list of OBJECTs
27 * list_append() - append a list onto another one, returning total
28 * list_new() - tack an object onto the end of a list of objects
29 * list_copy() - copy a whole list of objects
30 * list_sublist() - copy a subset of a list of objects
31 * list_free() - free a list of objects
32 * list_print() - print a list of objects to stdout
33 * list_length() - return the number of items in the list
35 * lol_init() - initialize a LOL (list of lists)
36 * lol_add() - append a LIST onto an LOL
37 * lol_free() - free the LOL and its LISTs
38 * lol_get() - return one of the LISTs in the LOL
39 * lol_print() - debug print LISTS separated by ":"
42 #ifndef LISTS_DWA20011022_H
43 #define LISTS_DWA20011022_H
53 * LIST - list of strings
65 this->impl
.next
= nullptr;
69 typedef LIST
* list_ptr
;
70 typedef OBJECT
* * LISTITER
;
79 LIST
* list
[ LOL_MAX
];
82 LIST
* list_new( OBJECT
* value
);
83 LIST
* list_append( LIST
* destination
, LIST
* source
);
84 LIST
* list_copy( LIST
* );
85 LIST
* list_copy_range( LIST
* destination
, LISTITER first
, LISTITER last
);
86 void list_free( LIST
* head
);
87 LIST
* list_push_back( LIST
* head
, OBJECT
* value
);
88 void list_print( LIST
* );
89 int32_t list_length( LIST
* );
90 LIST
* list_sublist( LIST
*, int32_t start
, int32_t count
);
91 LIST
* list_pop_front( LIST
* );
92 LIST
* list_sort( LIST
* );
93 LIST
* list_unique( LIST
* sorted_list
);
94 int32_t list_in( LIST
*, OBJECT
* value
);
95 LIST
* list_reverse( LIST
* );
96 int32_t list_cmp( LIST
* lhs
, LIST
* rhs
);
97 int32_t list_is_sublist( LIST
* sub
, LIST
* l
);
100 LISTITER
list_begin( LIST
* );
101 LISTITER
list_end( LIST
* );
102 #define list_next( it ) ((it) + 1)
103 #define list_item( it ) (*(it))
104 #define list_empty( l ) ((l) == L0)
105 #define list_front( l ) list_item( list_begin( l ) )
107 #define L0 ((LIST *)0)
109 void lol_add( LOL
*, LIST
* );
110 void lol_init( LOL
* );
111 void lol_free( LOL
* );
112 LIST
* lol_get( LOL
*, int i
);
113 void lol_print( LOL
* );
114 void lol_build( LOL
*, char const * * elements
);
117 PyObject
* list_to_python( LIST
* );
118 LIST
* list_from_python( PyObject
* );
121 namespace b2
{ namespace jam
{
126 inline explicit iterator(LISTITER i
) : list_i(i
) {}
128 inline iterator
operator++()
130 list_i
= list_next(list_i
);
133 inline iterator
operator++(int)
135 iterator result
{*this};
136 list_i
= list_next(list_i
);
139 inline bool operator==(iterator other
) const { return list_i
== other
.list_i
; }
140 inline bool operator!=(iterator other
) const { return list_i
!= other
.list_i
; }
141 inline OBJECT
*& operator*() const { return list_item(list_i
); }
142 inline OBJECT
** operator->() const { return &list_item(list_i
); }
149 friend struct iterator
;
151 inline list(const list
&other
)
152 : list_obj(list_copy(other
.list_obj
)) {}
153 inline explicit list(const object
&o
)
154 : list_obj(list_new(object_copy(o
))) {}
155 inline explicit list(LIST
*l
)
156 : list_obj(list_copy(l
)) {}
158 inline ~list() { if (list_obj
) list_free(list_obj
); }
159 inline LIST
* release()
166 inline iterator
begin() { return iterator(list_begin(list_obj
)); }
167 inline iterator
end() { return iterator(list_end(list_obj
)); }
168 inline bool empty() const { return list_empty(list_obj
) || length() == 0; }
169 inline int32_t length() const { return list_length(list_obj
); }
170 inline list
&append(const list
&other
)
172 list_obj
= list_append(list_obj
, list_copy(other
.list_obj
));
178 LIST
*list_obj
= nullptr;