]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/lists.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / tools / build / src / engine / lists.h
1 /*
2 * Copyright 1993, 1995 Christopher Seiwald.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7 /* This file is ALSO:
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)
12 */
13
14 /*
15 * lists.h - the LIST structure and routines to manipulate them
16 *
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.
19 *
20 * Structures defined:
21 *
22 * LIST - list of OBJECTs
23 * LOL - list of LISTs
24 *
25 * External routines:
26 *
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
34 *
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 ":"
40 */
41
42 #ifndef LISTS_DWA20011022_H
43 #define LISTS_DWA20011022_H
44
45 #include "config.h"
46 #include "object.h"
47
48 #ifdef HAVE_PYTHON
49 # include <Python.h>
50 #endif
51
52 /*
53 * LIST - list of strings
54 */
55
56 struct LIST {
57 union {
58 int32_t size;
59 struct LIST * next;
60 OBJECT * align;
61 } impl;
62
63 LIST()
64 {
65 this->impl.next = nullptr;
66 }
67 };
68
69 typedef LIST * list_ptr;
70 typedef OBJECT * * LISTITER;
71
72 /*
73 * LOL - list of LISTs
74 */
75
76 #define LOL_MAX 19
77 typedef struct _lol {
78 int32_t count;
79 LIST * list[ LOL_MAX ];
80 } LOL;
81
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 );
98 void list_done();
99
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 ) )
106
107 #define L0 ((LIST *)0)
108
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 );
115
116 #ifdef HAVE_PYTHON
117 PyObject * list_to_python( LIST * );
118 LIST * list_from_python( PyObject * );
119 #endif
120
121 namespace b2 { namespace jam {
122 struct list
123 {
124 struct iterator
125 {
126 inline explicit iterator(LISTITER i) : list_i(i) {}
127
128 inline iterator operator++()
129 {
130 list_i = list_next(list_i);
131 return *this;
132 }
133 inline iterator operator++(int)
134 {
135 iterator result{*this};
136 list_i = list_next(list_i);
137 return result;
138 }
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); }
143
144 private:
145
146 LISTITER list_i;
147 };
148
149 friend struct iterator;
150
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)) {}
157
158 inline ~list() { if (list_obj) list_free(list_obj); }
159 inline LIST* release()
160 {
161 LIST* r = list_obj;
162 list_obj = nullptr;
163 return r;
164 }
165
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)
171 {
172 list_obj = list_append(list_obj, list_copy(other.list_obj));
173 return *this;
174 }
175
176 private:
177
178 LIST *list_obj = nullptr;
179 };
180 }}
181
182 #endif