Commit | Line | Data |
---|---|---|
fa864999 TT |
1 | /* Some commonly-used VEC types. |
2 | ||
e2882c85 | 3 | Copyright (C) 2012-2018 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 | ||
fa864999 TT |
20 | #ifndef GDB_VECS_H |
21 | #define GDB_VECS_H | |
22 | ||
23 | #include "vec.h" | |
24 | ||
48faced0 | 25 | typedef const char *const_char_ptr; |
55aa24fb | 26 | |
111dfaae SDJ |
27 | DEF_VEC_P (const_char_ptr); |
28 | ||
e80aaf61 | 29 | /* Split STR, a list of DELIMITER-separated fields, into a char pointer vector. |
e4ab2fad | 30 | |
e80aaf61 | 31 | You may modify the returned strings. */ |
749234e5 | 32 | |
e80aaf61 SM |
33 | extern std::vector<gdb::unique_xmalloc_ptr<char>> |
34 | delim_string_to_char_ptr_vec (const char *str, char delimiter); | |
e4ab2fad | 35 | |
e80aaf61 SM |
36 | /* Like dirnames_to_char_ptr_vec, but append the directories to *VECP. */ |
37 | ||
38 | extern void dirnames_to_char_ptr_vec_append | |
39 | (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames); | |
40 | ||
41 | /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the | |
42 | elements in their original order. For empty string ("") DIRNAMES return | |
43 | list of one empty string ("") element. | |
44 | ||
45 | You may modify the returned strings. */ | |
46 | ||
47 | extern std::vector<gdb::unique_xmalloc_ptr<char>> | |
48 | dirnames_to_char_ptr_vec (const char *dirnames); | |
e4ab2fad | 49 | |
53127008 SM |
50 | /* Remove the element at position IX from VEC, not preserving the order of the |
51 | remaining elements. Return the removed element. */ | |
52 | ||
53 | template <typename T> | |
54 | T | |
55 | unordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix) | |
56 | { | |
57 | gdb_assert (ix < vec.size ()); | |
58 | ||
59 | T removed = std::move (vec[ix]); | |
60 | vec[ix] = std::move (vec.back ()); | |
61 | vec.pop_back (); | |
62 | ||
63 | return removed; | |
64 | } | |
65 | ||
66 | /* Remove the element at position IX from VEC, preserving the order the | |
67 | remaining elements. Return the removed element. */ | |
68 | ||
69 | template <typename T> | |
70 | T | |
71 | ordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix) | |
72 | { | |
73 | gdb_assert (ix < vec.size ()); | |
74 | ||
75 | T removed = std::move (vec[ix]); | |
76 | vec.erase (vec.begin () + ix); | |
77 | ||
78 | return removed; | |
79 | } | |
80 | ||
fa864999 | 81 | #endif /* GDB_VECS_H */ |