Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / common / gdb_vecs.h
CommitLineData
fa864999
TT
1/* Some commonly-used VEC types.
2
42a4f53d 3 Copyright (C) 2012-2019 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
e80aaf61 25/* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
e4ab2fad 26
e80aaf61 27 You may modify the returned strings. */
749234e5 28
e80aaf61
SM
29extern std::vector<gdb::unique_xmalloc_ptr<char>>
30 delim_string_to_char_ptr_vec (const char *str, char delimiter);
e4ab2fad 31
e80aaf61
SM
32/* Like dirnames_to_char_ptr_vec, but append the directories to *VECP. */
33
34extern void dirnames_to_char_ptr_vec_append
35 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames);
36
37/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
38 elements in their original order. For empty string ("") DIRNAMES return
39 list of one empty string ("") element.
40
41 You may modify the returned strings. */
42
43extern std::vector<gdb::unique_xmalloc_ptr<char>>
44 dirnames_to_char_ptr_vec (const char *dirnames);
e4ab2fad 45
b24531ed
SM
46/* Remove the element pointed by iterator IT from VEC, not preserving the order
47 of the remaining elements. Return the removed element. */
48
49template <typename T>
50T
51unordered_remove (std::vector<T> &vec, typename std::vector<T>::iterator it)
52{
53 gdb_assert (it >= vec.begin () && it < vec.end ());
54
55 T removed = std::move (*it);
56 *it = std::move (vec.back ());
57 vec.pop_back ();
58
59 return removed;
60}
61
53127008
SM
62/* Remove the element at position IX from VEC, not preserving the order of the
63 remaining elements. Return the removed element. */
64
65template <typename T>
66T
67unordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
68{
69 gdb_assert (ix < vec.size ());
70
b24531ed 71 return unordered_remove (vec, vec.begin () + ix);
53127008
SM
72}
73
74/* Remove the element at position IX from VEC, preserving the order the
75 remaining elements. Return the removed element. */
76
77template <typename T>
78T
79ordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
80{
81 gdb_assert (ix < vec.size ());
82
83 T removed = std::move (vec[ix]);
84 vec.erase (vec.begin () + ix);
85
86 return removed;
87}
88
fa864999 89#endif /* GDB_VECS_H */
This page took 0.477575 seconds and 4 git commands to generate.