1169695Skan//===-- FileSpecList.h ------------------------------------------*- C++ -*-===//
2169695Skan//
3169695Skan//                     The LLVM Compiler Infrastructure
4169695Skan//
5169695Skan// This file is distributed under the University of Illinois Open Source
6169695Skan// License. See LICENSE.TXT for details.
7169695Skan//
8169695Skan//===----------------------------------------------------------------------===//
9169695Skan
10169695Skan#ifndef liblldb_FileSpecList_h_
11169695Skan#define liblldb_FileSpecList_h_
12169695Skan#if defined(__cplusplus)
13169695Skan
14169695Skan#include "lldb/lldb-private.h"
15169695Skan#include "lldb/Host/FileSpec.h"
16169695Skan#include <vector>
17169695Skan
18169695Skannamespace lldb_private {
19169695Skan
20169695Skan//----------------------------------------------------------------------
21169695Skan/// @class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
22169695Skan/// @brief A file collection class.
23169695Skan///
24169695Skan/// A class that contains a mutable list of FileSpec objects.
25169695Skan//----------------------------------------------------------------------
26169695Skanclass FileSpecList
27169695Skan{
28169695Skanpublic:
29169695Skan    //------------------------------------------------------------------
30169695Skan    /// Default constructor.
31169695Skan    ///
32169695Skan    /// Initialize this object with an empty file list.
33169695Skan    //------------------------------------------------------------------
34169695Skan    FileSpecList ();
35169695Skan
36169695Skan    //------------------------------------------------------------------
37169695Skan    /// Copy constructor.
38169695Skan    ///
39169695Skan    /// Initialize this object with a copy of the file list from \a rhs.
40169695Skan    ///
41169695Skan    /// @param[in] rhs
42169695Skan    ///     A const reference to another file list object.
43169695Skan    //------------------------------------------------------------------
44169695Skan    FileSpecList (const FileSpecList &rhs);
45169695Skan
46169695Skan    //------------------------------------------------------------------
47169695Skan    /// Destructor.
48169695Skan    //------------------------------------------------------------------
49169695Skan    ~FileSpecList ();
50169695Skan
51169695Skan    //------------------------------------------------------------------
52169695Skan    /// Assignment operator.
53169695Skan    ///
54169695Skan    /// Replace the file list in this object with the file list from
55169695Skan    /// \a rhs.
56169695Skan    ///
57169695Skan    /// @param[in] rhs
58169695Skan    ///     A file list object to copy.
59169695Skan    ///
60169695Skan    /// @return
61169695Skan    ///     A const reference to this object.
62169695Skan    //------------------------------------------------------------------
63    const FileSpecList&
64    operator= (const FileSpecList &rhs);
65
66    //------------------------------------------------------------------
67    /// Append a FileSpec object to the list.
68    ///
69    /// Appends \a file to the end of the file list.
70    ///
71    /// @param[in] file
72    ///     A new file to append to this file list.
73    //------------------------------------------------------------------
74    void
75    Append (const FileSpec &file);
76
77    //------------------------------------------------------------------
78    /// Append a FileSpec object if unique.
79    ///
80    /// Appends \a file to the end of the file list if it doesn't
81    /// already exist in the file list.
82    ///
83    /// @param[in] file
84    ///     A new file to append to this file list.
85    ///
86    /// @return
87    ///     \b true if the file was appended, \b false otherwise.
88    //------------------------------------------------------------------
89    bool
90    AppendIfUnique (const FileSpec &file);
91
92    //------------------------------------------------------------------
93    /// Clears the file list.
94    //------------------------------------------------------------------
95    void
96    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
105    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    /// @return
123    ///     The index of the file that matches \a file if it is found,
124    ///     else UINT32_MAX is returned.
125    //------------------------------------------------------------------
126    size_t
127    FindFileIndex (size_t idx, const FileSpec &file, bool full) const;
128
129    //------------------------------------------------------------------
130    /// Get file at index.
131    ///
132    /// Gets a file from the file list. If \a idx is not a valid index,
133    /// an empty FileSpec object will be returned. The file objects
134    /// that are returned can be tested using
135    /// FileSpec::operator void*().
136    ///
137    /// @param[in] idx
138    ///     An index into the file list.
139    ///
140    /// @return
141    ///     A copy of the FileSpec object at index \a idx. If \a idx
142    ///     is out of range, then an empty FileSpec object will be
143    ///     returned.
144    //------------------------------------------------------------------
145    const FileSpec &
146    GetFileSpecAtIndex (size_t idx) const;
147
148    //------------------------------------------------------------------
149    /// Get file specification pointer at index.
150    ///
151    /// Gets a file from the file list. The file objects that are
152    /// returned can be tested using FileSpec::operator void*().
153    ///
154    /// @param[in] idx
155    ///     An index into the file list.
156    ///
157    /// @return
158    ///     A pointer to a contained FileSpec object at index \a idx.
159    ///     If \a idx is out of range, then an NULL is returned.
160    //------------------------------------------------------------------
161    const FileSpec *
162    GetFileSpecPointerAtIndex (size_t idx) const;
163
164    //------------------------------------------------------------------
165    /// Get the memory cost of this object.
166    ///
167    /// Return the size in bytes that this object takes in memory. This
168    /// returns the size in bytes of this object, not any shared string
169    /// values it may refer to.
170    ///
171    /// @return
172    ///     The number of bytes that this object occupies in memory.
173    ///
174    /// @see ConstString::StaticMemorySize ()
175    //------------------------------------------------------------------
176    size_t
177    MemorySize () const;
178
179    bool
180    IsEmpty() const
181    {
182        return m_files.empty();
183    }
184
185    //------------------------------------------------------------------
186    /// Get the number of files in the file list.
187    ///
188    /// @return
189    ///     The number of files in the file spec list.
190    //------------------------------------------------------------------
191    size_t
192    GetSize () const;
193
194    bool
195    Insert (size_t idx, const FileSpec &file)
196    {
197        if (idx < m_files.size())
198        {
199            m_files.insert(m_files.begin() + idx, file);
200            return true;
201        }
202        else if (idx == m_files.size())
203        {
204            m_files.push_back(file);
205            return true;
206        }
207        return false;
208    }
209
210    bool
211    Replace (size_t idx, const FileSpec &file)
212    {
213        if (idx < m_files.size())
214        {
215            m_files[idx] = file;
216            return true;
217        }
218        return false;
219    }
220
221    bool
222    Remove (size_t idx)
223    {
224        if (idx < m_files.size())
225        {
226            m_files.erase(m_files.begin() + idx);
227            return true;
228        }
229        return false;
230    }
231
232    static size_t GetFilesMatchingPartialPath (const char *path, bool dir_okay, FileSpecList &matches);
233
234protected:
235    typedef std::vector<FileSpec> collection;   ///< The collection type for the file list.
236    collection m_files; ///< A collection of FileSpec objects.
237};
238
239} // namespace lldb_private
240
241
242#endif  // #if defined(__cplusplus)
243#endif  // liblldb_FileSpecList_h_
244