Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 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/lldb-private.h" |
| 15 | #include "lldb/Core/FileSpec.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 | { |
| 28 | public: |
| 29 | //------------------------------------------------------------------ |
| 30 | /// Default constructor. |
| 31 | /// |
| 32 | /// Initialize this object with an empty file list. |
| 33 | //------------------------------------------------------------------ |
| 34 | FileSpecList (); |
| 35 | |
| 36 | //------------------------------------------------------------------ |
| 37 | /// Copy constructor. |
| 38 | /// |
| 39 | /// Initialize this object with a copy of the file list from \a rhs. |
| 40 | /// |
| 41 | /// @param[in] rhs |
| 42 | /// A const reference to another file list object. |
| 43 | //------------------------------------------------------------------ |
| 44 | FileSpecList (const FileSpecList &rhs); |
| 45 | |
| 46 | //------------------------------------------------------------------ |
| 47 | /// Destructor. |
| 48 | //------------------------------------------------------------------ |
| 49 | ~FileSpecList (); |
| 50 | |
| 51 | //------------------------------------------------------------------ |
| 52 | /// Assignment operator. |
| 53 | /// |
| 54 | /// Replace the file list in this object with the file list from |
| 55 | /// \a rhs. |
| 56 | /// |
| 57 | /// @param[in] rhs |
| 58 | /// A file list object to copy. |
| 59 | /// |
| 60 | /// @return |
| 61 | /// A const reference to this object. |
| 62 | //------------------------------------------------------------------ |
| 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; |
| 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 | /// @return |
| 120 | /// The index of the file that matches \a file if it is found, |
| 121 | /// else UINT32_MAX is returned. |
| 122 | //------------------------------------------------------------------ |
| 123 | uint32_t |
| 124 | FindFileIndex (uint32_t idx, const FileSpec &file) const; |
| 125 | |
| 126 | //------------------------------------------------------------------ |
| 127 | /// Get file at index. |
| 128 | /// |
| 129 | /// Gets a file from the file list. If \a idx is not a valid index, |
| 130 | /// an empty FileSpec object will be returned. The file objects |
| 131 | /// that are returned can be tested using |
| 132 | /// 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 & |
| 143 | GetFileSpecAtIndex (uint32_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 * |
| 159 | GetFileSpecPointerAtIndex (uint32_t idx) const; |
| 160 | |
| 161 | //------------------------------------------------------------------ |
| 162 | /// Get the memory cost of this object. |
| 163 | /// |
| 164 | /// Return the size in bytes that this object takes in memory. This |
| 165 | /// returns the size in bytes of this object, not any shared string |
| 166 | /// values it may refer to. |
| 167 | /// |
| 168 | /// @return |
| 169 | /// The number of bytes that this object occupies in memory. |
| 170 | /// |
| 171 | /// @see ConstString::StaticMemorySize () |
| 172 | //------------------------------------------------------------------ |
| 173 | size_t |
| 174 | MemorySize () const; |
| 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 | uint32_t |
| 183 | GetSize () const; |
| 184 | |
| 185 | static size_t GetFilesMatchingPartialPath (const char *path, bool dir_okay, FileSpecList &matches); |
| 186 | |
| 187 | protected: |
| 188 | typedef std::vector<FileSpec> collection; ///< The collection type for the file list. |
| 189 | collection m_files; ///< A collection of FileSpec objects. |
| 190 | }; |
| 191 | |
| 192 | } // namespace lldb_private |
| 193 | |
| 194 | |
| 195 | #endif // #if defined(__cplusplus) |
| 196 | #endif // liblldb_FileSpecList_h_ |