gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdbsupport / gdb_vecs.h
CommitLineData
fa864999
TT
1/* Some commonly-used VEC types.
2
b811d2c2 3 Copyright (C) 2012-2020 Free Software Foundation, Inc.
fa864999
TT
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
1a5c2598
TT
20#ifndef COMMON_GDB_VECS_H
21#define COMMON_GDB_VECS_H
fa864999 22
e80aaf61 23/* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
e4ab2fad 24
e80aaf61 25 You may modify the returned strings. */
749234e5 26
e80aaf61
SM
27extern std::vector<gdb::unique_xmalloc_ptr<char>>
28 delim_string_to_char_ptr_vec (const char *str, char delimiter);
e4ab2fad 29
e80aaf61
SM
30/* Like dirnames_to_char_ptr_vec, but append the directories to *VECP. */
31
32extern void dirnames_to_char_ptr_vec_append
33 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames);
34
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.
38
39 You may modify the returned strings. */
40
41extern std::vector<gdb::unique_xmalloc_ptr<char>>
42 dirnames_to_char_ptr_vec (const char *dirnames);
e4ab2fad 43
b24531ed
SM
44/* Remove the element pointed by iterator IT from VEC, not preserving the order
45 of the remaining elements. Return the removed element. */
46
47template <typename T>
48T
49unordered_remove (std::vector<T> &vec, typename std::vector<T>::iterator it)
50{
51 gdb_assert (it >= vec.begin () && it < vec.end ());
52
53 T removed = std::move (*it);
cf57ad6d
AB
54 if (it != vec.end () - 1)
55 *it = std::move (vec.back ());
b24531ed
SM
56 vec.pop_back ();
57
58 return removed;
59}
60
53127008
SM
61/* Remove the element at position IX from VEC, not preserving the order of the
62 remaining elements. Return the removed element. */
63
64template <typename T>
65T
66unordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
67{
68 gdb_assert (ix < vec.size ());
69
b24531ed 70 return unordered_remove (vec, vec.begin () + ix);
53127008
SM
71}
72
73/* Remove the element at position IX from VEC, preserving the order the
74 remaining elements. Return the removed element. */
75
76template <typename T>
77T
78ordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
79{
80 gdb_assert (ix < vec.size ());
81
82 T removed = std::move (vec[ix]);
83 vec.erase (vec.begin () + ix);
84
85 return removed;
86}
87
1a5c2598 88#endif /* COMMON_GDB_VECS_H */
This page took 0.576647 seconds and 4 git commands to generate.