]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/FileSpecList.h
MFV r316931: 6268 zfs diff confused by moving a file to another directory
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / FileSpecList.h
1 //===-- FileSpecList.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_FileSpecList_h_
11 #define liblldb_FileSpecList_h_
12 #if defined(__cplusplus)
13
14 #include "lldb/Utility/FileSpec.h"
15
16 #include <vector>
17
18 #include <stddef.h> // for size_t
19
20 namespace lldb_private {
21 class Stream;
22 }
23
24 namespace lldb_private {
25
26 //----------------------------------------------------------------------
27 /// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
28 /// @brief A file collection class.
29 ///
30 /// A class that contains a mutable list of FileSpec objects.
31 //----------------------------------------------------------------------
32 class FileSpecList {
33 public:
34   //------------------------------------------------------------------
35   /// Default constructor.
36   ///
37   /// Initialize this object with an empty file list.
38   //------------------------------------------------------------------
39   FileSpecList();
40
41   //------------------------------------------------------------------
42   /// Copy constructor.
43   ///
44   /// Initialize this object with a copy of the file list from \a rhs.
45   ///
46   /// @param[in] rhs
47   ///     A const reference to another file list object.
48   //------------------------------------------------------------------
49   FileSpecList(const FileSpecList &rhs);
50
51   //------------------------------------------------------------------
52   /// Destructor.
53   //------------------------------------------------------------------
54   ~FileSpecList();
55
56   //------------------------------------------------------------------
57   /// Assignment operator.
58   ///
59   /// Replace the file list in this object with the file list from
60   /// \a rhs.
61   ///
62   /// @param[in] rhs
63   ///     A file list object to copy.
64   ///
65   /// @return
66   ///     A const reference to this object.
67   //------------------------------------------------------------------
68   const FileSpecList &operator=(const FileSpecList &rhs);
69
70   //------------------------------------------------------------------
71   /// Append a FileSpec object to the list.
72   ///
73   /// Appends \a file to the end of the file list.
74   ///
75   /// @param[in] file
76   ///     A new file to append to this file list.
77   //------------------------------------------------------------------
78   void Append(const FileSpec &file);
79
80   //------------------------------------------------------------------
81   /// Append a FileSpec object if unique.
82   ///
83   /// Appends \a file to the end of the file list if it doesn't
84   /// already exist in the file list.
85   ///
86   /// @param[in] file
87   ///     A new file to append to this file list.
88   ///
89   /// @return
90   ///     \b true if the file was appended, \b false otherwise.
91   //------------------------------------------------------------------
92   bool AppendIfUnique(const FileSpec &file);
93
94   //------------------------------------------------------------------
95   /// Clears the file list.
96   //------------------------------------------------------------------
97   void Clear();
98
99   //------------------------------------------------------------------
100   /// Dumps the file list to the supplied stream pointer "s".
101   ///
102   /// @param[in] 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;
106
107   //------------------------------------------------------------------
108   /// Find a file index.
109   ///
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.
112   ///
113   /// @param[in] idx
114   ///     An index into the file list.
115   ///
116   /// @param[in] file
117   ///     The file specification to search for.
118   ///
119   /// @param[in] full
120   ///     Should FileSpec::Equal be called with "full" true or false.
121   ///
122   /// @param[in] remove_backup_dots
123   ///     Should FileSpec::Equal be called with "remove_backup_dots" true or
124   ///     false.
125   ///
126   /// @return
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;
132
133   //------------------------------------------------------------------
134   /// Get file at index.
135   ///
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*().
140   ///
141   /// @param[in] idx
142   ///     An index into the file list.
143   ///
144   /// @return
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
147   ///     returned.
148   //------------------------------------------------------------------
149   const FileSpec &GetFileSpecAtIndex(size_t idx) const;
150
151   //------------------------------------------------------------------
152   /// Get file specification pointer at index.
153   ///
154   /// Gets a file from the file list. The file objects that are
155   /// returned can be tested using FileSpec::operator void*().
156   ///
157   /// @param[in] idx
158   ///     An index into the file list.
159   ///
160   /// @return
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;
165
166   //------------------------------------------------------------------
167   /// Get the memory cost of this object.
168   ///
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.
172   ///
173   /// @return
174   ///     The number of bytes that this object occupies in memory.
175   ///
176   /// @see ConstString::StaticMemorySize ()
177   //------------------------------------------------------------------
178   size_t MemorySize() const;
179
180   bool IsEmpty() const { return m_files.empty(); }
181
182   //------------------------------------------------------------------
183   /// Get the number of files in the file list.
184   ///
185   /// @return
186   ///     The number of files in the file spec list.
187   //------------------------------------------------------------------
188   size_t GetSize() const;
189
190   bool Insert(size_t idx, const FileSpec &file) {
191     if (idx < m_files.size()) {
192       m_files.insert(m_files.begin() + idx, file);
193       return true;
194     } else if (idx == m_files.size()) {
195       m_files.push_back(file);
196       return true;
197     }
198     return false;
199   }
200
201   bool Replace(size_t idx, const FileSpec &file) {
202     if (idx < m_files.size()) {
203       m_files[idx] = file;
204       return true;
205     }
206     return false;
207   }
208
209   bool Remove(size_t idx) {
210     if (idx < m_files.size()) {
211       m_files.erase(m_files.begin() + idx);
212       return true;
213     }
214     return false;
215   }
216
217   static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
218                                             FileSpecList &matches);
219
220 protected:
221   typedef std::vector<FileSpec>
222       collection;     ///< The collection type for the file list.
223   collection m_files; ///< A collection of FileSpec objects.
224 };
225
226 } // namespace lldb_private
227
228 #endif // #if defined(__cplusplus)
229 #endif // liblldb_FileSpecList_h_