1 //===-- FileSpecList.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_FileSpecList_h_
11 #define liblldb_FileSpecList_h_
12 #if defined(__cplusplus)
14 #include "lldb/Host/FileSpec.h"
15 #include "lldb/lldb-private.h"
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 /// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
22 /// @brief A file collection class.
24 /// A class that contains a mutable list of FileSpec objects.
25 //----------------------------------------------------------------------
28 //------------------------------------------------------------------
29 /// Default constructor.
31 /// Initialize this object with an empty file list.
32 //------------------------------------------------------------------
35 //------------------------------------------------------------------
38 /// Initialize this object with a copy of the file list from \a rhs.
41 /// A const reference to another file list object.
42 //------------------------------------------------------------------
43 FileSpecList(const FileSpecList &rhs);
45 //------------------------------------------------------------------
47 //------------------------------------------------------------------
50 //------------------------------------------------------------------
51 /// Assignment operator.
53 /// Replace the file list in this object with the file list from
57 /// A file list object to copy.
60 /// A const reference to this object.
61 //------------------------------------------------------------------
62 const FileSpecList &operator=(const FileSpecList &rhs);
64 //------------------------------------------------------------------
65 /// Append a FileSpec object to the list.
67 /// Appends \a file to the end of the file list.
70 /// A new file to append to this file list.
71 //------------------------------------------------------------------
72 void Append(const FileSpec &file);
74 //------------------------------------------------------------------
75 /// Append a FileSpec object if unique.
77 /// Appends \a file to the end of the file list if it doesn't
78 /// already exist in the file list.
81 /// A new file to append to this file list.
84 /// \b true if the file was appended, \b false otherwise.
85 //------------------------------------------------------------------
86 bool AppendIfUnique(const FileSpec &file);
88 //------------------------------------------------------------------
89 /// Clears the file list.
90 //------------------------------------------------------------------
93 //------------------------------------------------------------------
94 /// Dumps the file list to the supplied stream pointer "s".
97 /// The stream that will be used to dump the object description.
98 //------------------------------------------------------------------
99 void Dump(Stream *s, const char *separator_cstr = "\n") const;
101 //------------------------------------------------------------------
102 /// Find a file index.
104 /// Find the index of the file in the file spec list that matches
105 /// \a file starting \a idx entries into the file spec list.
108 /// An index into the file list.
111 /// The file specification to search for.
114 /// Should FileSpec::Equal be called with "full" true or false.
116 /// @param[in] remove_backup_dots
117 /// Should FileSpec::Equal be called with "remove_backup_dots" true or
121 /// The index of the file that matches \a file if it is found,
122 /// else UINT32_MAX is returned.
123 //------------------------------------------------------------------
124 size_t FindFileIndex(size_t idx, const FileSpec &file, bool full,
125 bool remove_backup_dots = false) const;
127 //------------------------------------------------------------------
128 /// Get file at index.
130 /// Gets a file from the file list. If \a idx is not a valid index,
131 /// an empty FileSpec object will be returned. The file objects
132 /// that are returned can be tested using
133 /// FileSpec::operator void*().
136 /// An index into the file list.
139 /// A copy of the FileSpec object at index \a idx. If \a idx
140 /// is out of range, then an empty FileSpec object will be
142 //------------------------------------------------------------------
143 const FileSpec &GetFileSpecAtIndex(size_t idx) const;
145 //------------------------------------------------------------------
146 /// Get file specification pointer at index.
148 /// Gets a file from the file list. The file objects that are
149 /// returned can be tested using FileSpec::operator void*().
152 /// An index into the file list.
155 /// A pointer to a contained FileSpec object at index \a idx.
156 /// If \a idx is out of range, then an NULL is returned.
157 //------------------------------------------------------------------
158 const FileSpec *GetFileSpecPointerAtIndex(size_t idx) const;
160 //------------------------------------------------------------------
161 /// Get the memory cost of this object.
163 /// Return the size in bytes that this object takes in memory. This
164 /// returns the size in bytes of this object, not any shared string
165 /// values it may refer to.
168 /// The number of bytes that this object occupies in memory.
170 /// @see ConstString::StaticMemorySize ()
171 //------------------------------------------------------------------
172 size_t MemorySize() const;
174 bool IsEmpty() const { return m_files.empty(); }
176 //------------------------------------------------------------------
177 /// Get the number of files in the file list.
180 /// The number of files in the file spec list.
181 //------------------------------------------------------------------
182 size_t GetSize() const;
184 bool Insert(size_t idx, const FileSpec &file) {
185 if (idx < m_files.size()) {
186 m_files.insert(m_files.begin() + idx, file);
188 } else if (idx == m_files.size()) {
189 m_files.push_back(file);
195 bool Replace(size_t idx, const FileSpec &file) {
196 if (idx < m_files.size()) {
203 bool Remove(size_t idx) {
204 if (idx < m_files.size()) {
205 m_files.erase(m_files.begin() + idx);
211 static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
212 FileSpecList &matches);
215 typedef std::vector<FileSpec>
216 collection; ///< The collection type for the file list.
217 collection m_files; ///< A collection of FileSpec objects.
220 } // namespace lldb_private
222 #endif // #if defined(__cplusplus)
223 #endif // liblldb_FileSpecList_h_