]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/FileSpecList.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[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>
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 /// 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 \a rhs.
60   ///
61   /// @param[in] rhs
62   ///     A file list object to copy.
63   ///
64   /// @return
65   ///     A const reference to this object.
66   //------------------------------------------------------------------
67   const FileSpecList &operator=(const FileSpecList &rhs);
68
69   //------------------------------------------------------------------
70   /// Append a FileSpec object to the list.
71   ///
72   /// Appends \a file to the end of the file list.
73   ///
74   /// @param[in] file
75   ///     A new file to append to this file list.
76   //------------------------------------------------------------------
77   void Append(const FileSpec &file);
78
79   //------------------------------------------------------------------
80   /// Append a FileSpec object if unique.
81   ///
82   /// Appends \a file to the end of the file list if it doesn't already exist
83   /// in the file list.
84   ///
85   /// @param[in] file
86   ///     A new file to append to this file list.
87   ///
88   /// @return
89   ///     \b true if the file was appended, \b false otherwise.
90   //------------------------------------------------------------------
91   bool AppendIfUnique(const FileSpec &file);
92
93   //------------------------------------------------------------------
94   /// Clears the file list.
95   //------------------------------------------------------------------
96   void Clear();
97
98   //------------------------------------------------------------------
99   /// Dumps the file list to the supplied stream pointer "s".
100   ///
101   /// @param[in] 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;
105
106   //------------------------------------------------------------------
107   /// Find a file index.
108   ///
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.
111   ///
112   /// @param[in] idx
113   ///     An index into the file list.
114   ///
115   /// @param[in] file
116   ///     The file specification to search for.
117   ///
118   /// @param[in] full
119   ///     Should FileSpec::Equal be called with "full" true or false.
120   ///
121   /// @return
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;
126
127   //------------------------------------------------------------------
128   /// Get file at index.
129   ///
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*().
133   ///
134   /// @param[in] idx
135   ///     An index into the file list.
136   ///
137   /// @return
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
140   ///     returned.
141   //------------------------------------------------------------------
142   const FileSpec &GetFileSpecAtIndex(size_t idx) const;
143
144   //------------------------------------------------------------------
145   /// Get file specification pointer at index.
146   ///
147   /// Gets a file from the file list. The file objects that are returned can
148   /// be tested using FileSpec::operator void*().
149   ///
150   /// @param[in] idx
151   ///     An index into the file list.
152   ///
153   /// @return
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;
158
159   //------------------------------------------------------------------
160   /// Get the memory cost of this object.
161   ///
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
164   /// refer to.
165   ///
166   /// @return
167   ///     The number of bytes that this object occupies in memory.
168   ///
169   /// @see ConstString::StaticMemorySize ()
170   //------------------------------------------------------------------
171   size_t MemorySize() const;
172
173   bool IsEmpty() const { return m_files.empty(); }
174
175   //------------------------------------------------------------------
176   /// Get the number of files in the file list.
177   ///
178   /// @return
179   ///     The number of files in the file spec list.
180   //------------------------------------------------------------------
181   size_t GetSize() const;
182
183   bool Insert(size_t idx, const FileSpec &file) {
184     if (idx < m_files.size()) {
185       m_files.insert(m_files.begin() + idx, file);
186       return true;
187     } else if (idx == m_files.size()) {
188       m_files.push_back(file);
189       return true;
190     }
191     return false;
192   }
193
194   bool Replace(size_t idx, const FileSpec &file) {
195     if (idx < m_files.size()) {
196       m_files[idx] = file;
197       return true;
198     }
199     return false;
200   }
201
202   bool Remove(size_t idx) {
203     if (idx < m_files.size()) {
204       m_files.erase(m_files.begin() + idx);
205       return true;
206     }
207     return false;
208   }
209
210   static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
211                                             FileSpecList &matches);
212
213 protected:
214   typedef std::vector<FileSpec>
215       collection;     ///< The collection type for the file list.
216   collection m_files; ///< A collection of FileSpec objects.
217 };
218
219 } // namespace lldb_private
220
221 #endif // #if defined(__cplusplus)
222 #endif // liblldb_FileSpecList_h_