1 //===-- FileSpecList.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/FileSpecList.h"
12 #include "lldb/Utility/ConstString.h"
13 #include "lldb/Utility/Stream.h"
19 using namespace lldb_private;
22 FileSpecList::FileSpecList() : m_files() {}
24 FileSpecList::FileSpecList(const FileSpecList &rhs) = default;
26 FileSpecList::~FileSpecList() = default;
28 //------------------------------------------------------------------
29 // Assignment operator
30 //------------------------------------------------------------------
31 const FileSpecList &FileSpecList::operator=(const FileSpecList &rhs) {
33 m_files = rhs.m_files;
37 //------------------------------------------------------------------
38 // Append the "file_spec" to the end of the file spec list.
39 //------------------------------------------------------------------
40 void FileSpecList::Append(const FileSpec &file_spec) {
41 m_files.push_back(file_spec);
44 //------------------------------------------------------------------
45 // Only append the "file_spec" if this list doesn't already contain it.
47 // Returns true if "file_spec" was added, false if this list already contained
48 // a copy of "file_spec".
49 //------------------------------------------------------------------
50 bool FileSpecList::AppendIfUnique(const FileSpec &file_spec) {
51 collection::iterator end = m_files.end();
52 if (find(m_files.begin(), end, file_spec) == end) {
53 m_files.push_back(file_spec);
59 //------------------------------------------------------------------
60 // Clears the file list.
61 //------------------------------------------------------------------
62 void FileSpecList::Clear() { m_files.clear(); }
64 //------------------------------------------------------------------
65 // Dumps the file list to the supplied stream pointer "s".
66 //------------------------------------------------------------------
67 void FileSpecList::Dump(Stream *s, const char *separator_cstr) const {
68 collection::const_iterator pos, end = m_files.end();
69 for (pos = m_files.begin(); pos != end; ++pos) {
71 if (separator_cstr && ((pos + 1) != end))
72 s->PutCString(separator_cstr);
76 //------------------------------------------------------------------
77 // Find the index of the file in the file spec list that matches "file_spec"
78 // starting "start_idx" entries into the file spec list.
80 // Returns the valid index of the file that matches "file_spec" if it is found,
81 // else std::numeric_limits<uint32_t>::max() is returned.
82 //------------------------------------------------------------------
83 size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec,
85 const size_t num_files = m_files.size();
87 // When looking for files, we will compare only the filename if the FILE_SPEC
89 bool compare_filename_only = file_spec.GetDirectory().IsEmpty();
91 for (size_t idx = start_idx; idx < num_files; ++idx) {
92 if (compare_filename_only) {
93 if (ConstString::Equals(
94 m_files[idx].GetFilename(), file_spec.GetFilename(),
95 file_spec.IsCaseSensitive() || m_files[idx].IsCaseSensitive()))
98 if (FileSpec::Equal(m_files[idx], file_spec, full))
103 // We didn't find the file, return an invalid index
107 //------------------------------------------------------------------
108 // Returns the FileSpec object at index "idx". If "idx" is out of range, then
109 // an empty FileSpec object will be returned.
110 //------------------------------------------------------------------
111 const FileSpec &FileSpecList::GetFileSpecAtIndex(size_t idx) const {
112 if (idx < m_files.size())
114 static FileSpec g_empty_file_spec;
115 return g_empty_file_spec;
118 const FileSpec *FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const {
119 if (idx < m_files.size())
120 return &m_files[idx];
124 //------------------------------------------------------------------
125 // Return the size in bytes that this object takes in memory. This returns the
126 // size in bytes of this object's member variables and any FileSpec objects its
127 // member variables contain, the result doesn't not include the string values
128 // for the directories any filenames as those are in shared string pools.
129 //------------------------------------------------------------------
130 size_t FileSpecList::MemorySize() const {
131 size_t mem_size = sizeof(FileSpecList);
132 collection::const_iterator pos, end = m_files.end();
133 for (pos = m_files.begin(); pos != end; ++pos) {
134 mem_size += pos->MemorySize();
140 //------------------------------------------------------------------
141 // Return the number of files in the file spec list.
142 //------------------------------------------------------------------
143 size_t FileSpecList::GetSize() const { return m_files.size(); }
145 size_t FileSpecList::GetFilesMatchingPartialPath(const char *path,
147 FileSpecList &matches) {