LLDB  mainline
FileSpecList.h
Go to the documentation of this file.
1 //===-- FileSpecList.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_FileSpecList_h_
10 #define liblldb_FileSpecList_h_
11 #if defined(__cplusplus)
12 
13 #include "lldb/Utility/FileSpec.h"
14 
15 #include <vector>
16 
17 #include <stddef.h>
18 
19 namespace lldb_private {
20 class Stream;
21 }
22 
23 namespace lldb_private {
24 
25 /// \class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
26 /// A file collection class.
27 ///
28 /// A class that contains a mutable list of FileSpec objects.
29 class FileSpecList {
30 public:
31  /// Default constructor.
32  ///
33  /// Initialize this object with an empty file list.
34  FileSpecList();
35 
36  /// Copy constructor.
37  FileSpecList(const FileSpecList &rhs) = default;
38 
39  /// Move constructor
40  FileSpecList(FileSpecList &&rhs) = default;
41 
42  /// Initialize this object from a vector of FileSpecs
43  FileSpecList(std::vector<FileSpec> &&rhs) : m_files(std::move(rhs)) {}
44 
45  /// Destructor.
46  ~FileSpecList();
47 
48  /// Assignment operator.
49  ///
50  /// Replace the file list in this object with the file list from \a rhs.
51  ///
52  /// \param[in] rhs
53  /// A file list object to copy.
54  ///
55  /// \return
56  /// A const reference to this object.
57  FileSpecList &operator=(const FileSpecList &rhs) = default;
58 
59  /// Move-assignment operator.
60  FileSpecList &operator=(FileSpecList &&rhs) = default;
61 
62  /// Append a FileSpec object to the list.
63  ///
64  /// Appends \a file to the end of the file list.
65  ///
66  /// \param[in] file
67  /// A new file to append to this file list.
68  void Append(const FileSpec &file);
69 
70  /// Append a FileSpec object if unique.
71  ///
72  /// Appends \a file to the end of the file list if it doesn't already exist
73  /// in the file list.
74  ///
75  /// \param[in] file
76  /// A new file to append to this file list.
77  ///
78  /// \return
79  /// \b true if the file was appended, \b false otherwise.
80  bool AppendIfUnique(const FileSpec &file);
81 
82  /// Clears the file list.
83  void Clear();
84 
85  /// Dumps the file list to the supplied stream pointer "s".
86  ///
87  /// \param[in] s
88  /// The stream that will be used to dump the object description.
89  void Dump(Stream *s, const char *separator_cstr = "\n") const;
90 
91  /// Find a file index.
92  ///
93  /// Find the index of the file in the file spec list that matches \a file
94  /// starting \a idx entries into the file spec list.
95  ///
96  /// \param[in] idx
97  /// An index into the file list.
98  ///
99  /// \param[in] file
100  /// The file specification to search for.
101  ///
102  /// \param[in] full
103  /// Should FileSpec::Equal be called with "full" true or false.
104  ///
105  /// \return
106  /// The index of the file that matches \a file if it is found,
107  /// else UINT32_MAX is returned.
108  size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const;
109 
110  /// Get file at index.
111  ///
112  /// Gets a file from the file list. If \a idx is not a valid index, an empty
113  /// FileSpec object will be returned. The file objects that are returned can
114  /// be tested using FileSpec::operator void*().
115  ///
116  /// \param[in] idx
117  /// An index into the file list.
118  ///
119  /// \return
120  /// A copy of the FileSpec object at index \a idx. If \a idx
121  /// is out of range, then an empty FileSpec object will be
122  /// returned.
123  const FileSpec &GetFileSpecAtIndex(size_t idx) const;
124 
125  /// Get file specification pointer at index.
126  ///
127  /// Gets a file from the file list. The file objects that are returned can
128  /// be tested using FileSpec::operator void*().
129  ///
130  /// \param[in] idx
131  /// An index into the file list.
132  ///
133  /// \return
134  /// A pointer to a contained FileSpec object at index \a idx.
135  /// If \a idx is out of range, then an NULL is returned.
136  const FileSpec *GetFileSpecPointerAtIndex(size_t idx) const;
137 
138  /// Get the memory cost of this object.
139  ///
140  /// Return the size in bytes that this object takes in memory. This returns
141  /// the size in bytes of this object, not any shared string values it may
142  /// refer to.
143  ///
144  /// \return
145  /// The number of bytes that this object occupies in memory.
146  ///
147  /// \see ConstString::StaticMemorySize ()
148  size_t MemorySize() const;
149 
150  bool IsEmpty() const { return m_files.empty(); }
151 
152  /// Get the number of files in the file list.
153  ///
154  /// \return
155  /// The number of files in the file spec list.
156  size_t GetSize() const;
157 
158  bool Insert(size_t idx, const FileSpec &file) {
159  if (idx < m_files.size()) {
160  m_files.insert(m_files.begin() + idx, file);
161  return true;
162  } else if (idx == m_files.size()) {
163  m_files.push_back(file);
164  return true;
165  }
166  return false;
167  }
168 
169  bool Replace(size_t idx, const FileSpec &file) {
170  if (idx < m_files.size()) {
171  m_files[idx] = file;
172  return true;
173  }
174  return false;
175  }
176 
177  bool Remove(size_t idx) {
178  if (idx < m_files.size()) {
179  m_files.erase(m_files.begin() + idx);
180  return true;
181  }
182  return false;
183  }
184 
185  static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
186  FileSpecList &matches);
187 
188 protected:
189  typedef std::vector<FileSpec>
190  collection; ///< The collection type for the file list.
191  collection m_files; ///< A collection of FileSpec objects.
192 };
193 
194 } // namespace lldb_private
195 
196 #endif // #if defined(__cplusplus)
197 #endif // liblldb_FileSpecList_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14