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"
20 namespace lldb_private {
24 namespace lldb_private {
26 //----------------------------------------------------------------------
27 /// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
28 /// 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 \a rhs.
62 /// A file list object to copy.
65 /// A const reference to this object.
66 //------------------------------------------------------------------
67 const FileSpecList &operator=(const FileSpecList &rhs);
69 //------------------------------------------------------------------
70 /// Append a FileSpec object to the list.
72 /// Appends \a file to the end of the file list.
75 /// A new file to append to this file list.
76 //------------------------------------------------------------------
77 void Append(const FileSpec &file);
79 //------------------------------------------------------------------
80 /// Append a FileSpec object if unique.
82 /// Appends \a file to the end of the file list if it doesn't already exist
86 /// A new file to append to this file list.
89 /// \b true if the file was appended, \b false otherwise.
90 //------------------------------------------------------------------
91 bool AppendIfUnique(const FileSpec &file);
93 //------------------------------------------------------------------
94 /// Clears the file list.
95 //------------------------------------------------------------------
98 //------------------------------------------------------------------
99 /// Dumps the file list to the supplied stream pointer "s".
102 /// The stream that will be used to dump the object description.
103 //------------------------------------------------------------------
104 void Dump(Stream *s, const char *separator_cstr = "\n") const;
106 //------------------------------------------------------------------
107 /// Find a file index.
109 /// Find the index of the file in the file spec list that matches \a file
110 /// starting \a idx entries into the file spec list.
113 /// An index into the file list.
116 /// The file specification to search for.
119 /// Should FileSpec::Equal be called with "full" true or false.
122 /// The index of the file that matches \a file if it is found,
123 /// else UINT32_MAX is returned.
124 //------------------------------------------------------------------
125 size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const;
127 //------------------------------------------------------------------
128 /// Get file at index.
130 /// Gets a file from the file list. If \a idx is not a valid index, an empty
131 /// FileSpec object will be returned. The file objects that are returned can
132 /// be tested using FileSpec::operator void*().
135 /// An index into the file list.
138 /// A copy of the FileSpec object at index \a idx. If \a idx
139 /// is out of range, then an empty FileSpec object will be
141 //------------------------------------------------------------------
142 const FileSpec &GetFileSpecAtIndex(size_t idx) const;
144 //------------------------------------------------------------------
145 /// Get file specification pointer at index.
147 /// Gets a file from the file list. The file objects that are returned can
148 /// be tested using FileSpec::operator void*().
151 /// An index into the file list.
154 /// A pointer to a contained FileSpec object at index \a idx.
155 /// If \a idx is out of range, then an NULL is returned.
156 //------------------------------------------------------------------
157 const FileSpec *GetFileSpecPointerAtIndex(size_t idx) const;
159 //------------------------------------------------------------------
160 /// Get the memory cost of this object.
162 /// Return the size in bytes that this object takes in memory. This returns
163 /// the size in bytes of this object, not any shared string values it may
167 /// The number of bytes that this object occupies in memory.
169 /// @see ConstString::StaticMemorySize ()
170 //------------------------------------------------------------------
171 size_t MemorySize() const;
173 bool IsEmpty() const { return m_files.empty(); }
175 //------------------------------------------------------------------
176 /// Get the number of files in the file list.
179 /// The number of files in the file spec list.
180 //------------------------------------------------------------------
181 size_t GetSize() const;
183 bool Insert(size_t idx, const FileSpec &file) {
184 if (idx < m_files.size()) {
185 m_files.insert(m_files.begin() + idx, file);
187 } else if (idx == m_files.size()) {
188 m_files.push_back(file);
194 bool Replace(size_t idx, const FileSpec &file) {
195 if (idx < m_files.size()) {
202 bool Remove(size_t idx) {
203 if (idx < m_files.size()) {
204 m_files.erase(m_files.begin() + idx);
210 static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
211 FileSpecList &matches);
214 typedef std::vector<FileSpec>
215 collection; ///< The collection type for the file list.
216 collection m_files; ///< A collection of FileSpec objects.
219 } // namespace lldb_private
221 #endif // #if defined(__cplusplus)
222 #endif // liblldb_FileSpecList_h_