1 /* Some commonly-used VEC types.
3 Copyright (C) 2012-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef COMMON_GDB_VECS_H
21 #define COMMON_GDB_VECS_H
23 /* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
25 You may modify the returned strings. */
27 extern std::vector
<gdb::unique_xmalloc_ptr
<char>>
28 delim_string_to_char_ptr_vec (const char *str
, char delimiter
);
30 /* Like dirnames_to_char_ptr_vec, but append the directories to *VECP. */
32 extern void dirnames_to_char_ptr_vec_append
33 (std::vector
<gdb::unique_xmalloc_ptr
<char>> *vecp
, const char *dirnames
);
35 /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
36 elements in their original order. For empty string ("") DIRNAMES return
37 list of one empty string ("") element.
39 You may modify the returned strings. */
41 extern std::vector
<gdb::unique_xmalloc_ptr
<char>>
42 dirnames_to_char_ptr_vec (const char *dirnames
);
44 /* Remove the element pointed by iterator IT from VEC, not preserving the order
45 of the remaining elements. Return the removed element. */
49 unordered_remove (std::vector
<T
> &vec
, typename
std::vector
<T
>::iterator it
)
51 gdb_assert (it
>= vec
.begin () && it
< vec
.end ());
53 T removed
= std::move (*it
);
54 if (it
!= vec
.end () - 1)
55 *it
= std::move (vec
.back ());
61 /* Remove the element at position IX from VEC, not preserving the order of the
62 remaining elements. Return the removed element. */
66 unordered_remove (std::vector
<T
> &vec
, typename
std::vector
<T
>::size_type ix
)
68 gdb_assert (ix
< vec
.size ());
70 return unordered_remove (vec
, vec
.begin () + ix
);
73 /* Remove the element at position IX from VEC, preserving the order the
74 remaining elements. Return the removed element. */
78 ordered_remove (std::vector
<T
> &vec
, typename
std::vector
<T
>::size_type ix
)
80 gdb_assert (ix
< vec
.size ());
82 T removed
= std::move (vec
[ix
]);
83 vec
.erase (vec
.begin () + ix
);
88 #endif /* COMMON_GDB_VECS_H */