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/Utility/FileSpec.h"
18 #include <stddef.h> // for size_t
20 namespace lldb_private {
24 namespace lldb_private {
26 //----------------------------------------------------------------------
27 /// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
28 /// @brief A file collection class.
30 /// A class that contains a mutable list of FileSpec objects.
31 //----------------------------------------------------------------------
34 //------------------------------------------------------------------
35 /// Default constructor.
37 /// Initialize this object with an empty file list.
38 //------------------------------------------------------------------
41 //------------------------------------------------------------------
44 /// Initialize this object with a copy of the file list from \a rhs.
47 /// A const reference to another file list object.
48 //------------------------------------------------------------------
49 FileSpecList(const FileSpecList &rhs);
51 //------------------------------------------------------------------
53 //------------------------------------------------------------------
56 //------------------------------------------------------------------
57 /// Assignment operator.
59 /// Replace the file list in this object with the file list from
63 /// A file list object to copy.
66 /// A const reference to this object.
67 //------------------------------------------------------------------
68 const FileSpecList &operator=(const FileSpecList &rhs);
70 //------------------------------------------------------------------
71 /// Append a FileSpec object to the list.
73 /// Appends \a file to the end of the file list.
76 /// A new file to append to this file list.
77 //------------------------------------------------------------------
78 void Append(const FileSpec &file);
80 //------------------------------------------------------------------
81 /// Append a FileSpec object if unique.
83 /// Appends \a file to the end of the file list if it doesn't
84 /// already exist in the file list.
87 /// A new file to append to this file list.
90 /// \b true if the file was appended, \b false otherwise.
91 //------------------------------------------------------------------
92 bool AppendIfUnique(const FileSpec &file);
94 //------------------------------------------------------------------
95 /// Clears the file list.
96 //------------------------------------------------------------------
99 //------------------------------------------------------------------
100 /// Dumps the file list to the supplied stream pointer "s".
103 /// The stream that will be used to dump the object description.
104 //------------------------------------------------------------------
105 void Dump(Stream *s, const char *separator_cstr = "\n") const;
107 //------------------------------------------------------------------
108 /// Find a file index.
110 /// Find the index of the file in the file spec list that matches
111 /// \a file starting \a idx entries into the file spec list.
114 /// An index into the file list.
117 /// The file specification to search for.
120 /// Should FileSpec::Equal be called with "full" true or false.
122 /// @param[in] remove_backup_dots
123 /// Should FileSpec::Equal be called with "remove_backup_dots" true or
127 /// The index of the file that matches \a file if it is found,
128 /// else UINT32_MAX is returned.
129 //------------------------------------------------------------------
130 size_t FindFileIndex(size_t idx, const FileSpec &file, bool full,
131 bool remove_backup_dots = false) const;
133 //------------------------------------------------------------------
134 /// Get file at index.
136 /// Gets a file from the file list. If \a idx is not a valid index,
137 /// an empty FileSpec object will be returned. The file objects
138 /// that are returned can be tested using
139 /// FileSpec::operator void*().
142 /// An index into the file list.
145 /// A copy of the FileSpec object at index \a idx. If \a idx
146 /// is out of range, then an empty FileSpec object will be
148 //------------------------------------------------------------------
149 const FileSpec &GetFileSpecAtIndex(size_t idx) const;
151 //------------------------------------------------------------------
152 /// Get file specification pointer at index.
154 /// Gets a file from the file list. The file objects that are
155 /// returned can be tested using FileSpec::operator void*().
158 /// An index into the file list.
161 /// A pointer to a contained FileSpec object at index \a idx.
162 /// If \a idx is out of range, then an NULL is returned.
163 //------------------------------------------------------------------
164 const FileSpec *GetFileSpecPointerAtIndex(size_t idx) const;
166 //------------------------------------------------------------------
167 /// Get the memory cost of this object.
169 /// Return the size in bytes that this object takes in memory. This
170 /// returns the size in bytes of this object, not any shared string
171 /// values it may refer to.
174 /// The number of bytes that this object occupies in memory.
176 /// @see ConstString::StaticMemorySize ()
177 //------------------------------------------------------------------
178 size_t MemorySize() const;
180 bool IsEmpty() const { return m_files.empty(); }
182 //------------------------------------------------------------------
183 /// Get the number of files in the file list.
186 /// The number of files in the file spec list.
187 //------------------------------------------------------------------
188 size_t GetSize() const;
190 bool Insert(size_t idx, const FileSpec &file) {
191 if (idx < m_files.size()) {
192 m_files.insert(m_files.begin() + idx, file);
194 } else if (idx == m_files.size()) {
195 m_files.push_back(file);
201 bool Replace(size_t idx, const FileSpec &file) {
202 if (idx < m_files.size()) {
209 bool Remove(size_t idx) {
210 if (idx < m_files.size()) {
211 m_files.erase(m_files.begin() + idx);
217 static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
218 FileSpecList &matches);
221 typedef std::vector<FileSpec>
222 collection; ///< The collection type for the file list.
223 collection m_files; ///< A collection of FileSpec objects.
226 } // namespace lldb_private
228 #endif // #if defined(__cplusplus)
229 #endif // liblldb_FileSpecList_h_