]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/FileSpecList.h
Merge ACPICA 20170303.
[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/Host/FileSpec.h"
15 #include "lldb/lldb-private.h"
16 #include <vector>
17
18 namespace lldb_private {
19
20 //----------------------------------------------------------------------
21 /// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
22 /// @brief A file collection class.
23 ///
24 /// A class that contains a mutable list of FileSpec objects.
25 //----------------------------------------------------------------------
26 class FileSpecList {
27 public:
28   //------------------------------------------------------------------
29   /// Default constructor.
30   ///
31   /// Initialize this object with an empty file list.
32   //------------------------------------------------------------------
33   FileSpecList();
34
35   //------------------------------------------------------------------
36   /// Copy constructor.
37   ///
38   /// Initialize this object with a copy of the file list from \a rhs.
39   ///
40   /// @param[in] rhs
41   ///     A const reference to another file list object.
42   //------------------------------------------------------------------
43   FileSpecList(const FileSpecList &rhs);
44
45   //------------------------------------------------------------------
46   /// Destructor.
47   //------------------------------------------------------------------
48   ~FileSpecList();
49
50   //------------------------------------------------------------------
51   /// Assignment operator.
52   ///
53   /// Replace the file list in this object with the file list from
54   /// \a rhs.
55   ///
56   /// @param[in] rhs
57   ///     A file list object to copy.
58   ///
59   /// @return
60   ///     A const reference to this object.
61   //------------------------------------------------------------------
62   const FileSpecList &operator=(const FileSpecList &rhs);
63
64   //------------------------------------------------------------------
65   /// Append a FileSpec object to the list.
66   ///
67   /// Appends \a file to the end of the file list.
68   ///
69   /// @param[in] file
70   ///     A new file to append to this file list.
71   //------------------------------------------------------------------
72   void Append(const FileSpec &file);
73
74   //------------------------------------------------------------------
75   /// Append a FileSpec object if unique.
76   ///
77   /// Appends \a file to the end of the file list if it doesn't
78   /// already exist in the file list.
79   ///
80   /// @param[in] file
81   ///     A new file to append to this file list.
82   ///
83   /// @return
84   ///     \b true if the file was appended, \b false otherwise.
85   //------------------------------------------------------------------
86   bool AppendIfUnique(const FileSpec &file);
87
88   //------------------------------------------------------------------
89   /// Clears the file list.
90   //------------------------------------------------------------------
91   void Clear();
92
93   //------------------------------------------------------------------
94   /// Dumps the file list to the supplied stream pointer "s".
95   ///
96   /// @param[in] 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;
100
101   //------------------------------------------------------------------
102   /// Find a file index.
103   ///
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.
106   ///
107   /// @param[in] idx
108   ///     An index into the file list.
109   ///
110   /// @param[in] file
111   ///     The file specification to search for.
112   ///
113   /// @param[in] full
114   ///     Should FileSpec::Equal be called with "full" true or false.
115   ///
116   /// @param[in] remove_backup_dots
117   ///     Should FileSpec::Equal be called with "remove_backup_dots" true or
118   ///     false.
119   ///
120   /// @return
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;
126
127   //------------------------------------------------------------------
128   /// Get file at index.
129   ///
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*().
134   ///
135   /// @param[in] idx
136   ///     An index into the file list.
137   ///
138   /// @return
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
141   ///     returned.
142   //------------------------------------------------------------------
143   const FileSpec &GetFileSpecAtIndex(size_t idx) const;
144
145   //------------------------------------------------------------------
146   /// Get file specification pointer at index.
147   ///
148   /// Gets a file from the file list. The file objects that are
149   /// returned can be tested using FileSpec::operator void*().
150   ///
151   /// @param[in] idx
152   ///     An index into the file list.
153   ///
154   /// @return
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;
159
160   //------------------------------------------------------------------
161   /// Get the memory cost of this object.
162   ///
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.
166   ///
167   /// @return
168   ///     The number of bytes that this object occupies in memory.
169   ///
170   /// @see ConstString::StaticMemorySize ()
171   //------------------------------------------------------------------
172   size_t MemorySize() const;
173
174   bool IsEmpty() const { return m_files.empty(); }
175
176   //------------------------------------------------------------------
177   /// Get the number of files in the file list.
178   ///
179   /// @return
180   ///     The number of files in the file spec list.
181   //------------------------------------------------------------------
182   size_t GetSize() const;
183
184   bool Insert(size_t idx, const FileSpec &file) {
185     if (idx < m_files.size()) {
186       m_files.insert(m_files.begin() + idx, file);
187       return true;
188     } else if (idx == m_files.size()) {
189       m_files.push_back(file);
190       return true;
191     }
192     return false;
193   }
194
195   bool Replace(size_t idx, const FileSpec &file) {
196     if (idx < m_files.size()) {
197       m_files[idx] = file;
198       return true;
199     }
200     return false;
201   }
202
203   bool Remove(size_t idx) {
204     if (idx < m_files.size()) {
205       m_files.erase(m_files.begin() + idx);
206       return true;
207     }
208     return false;
209   }
210
211   static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
212                                             FileSpecList &matches);
213
214 protected:
215   typedef std::vector<FileSpec>
216       collection;     ///< The collection type for the file list.
217   collection m_files; ///< A collection of FileSpec objects.
218 };
219
220 } // namespace lldb_private
221
222 #endif // #if defined(__cplusplus)
223 #endif // liblldb_FileSpecList_h_