summaryrefslogtreecommitdiff
path: root/include/llvm/Support/FileSystem.h
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-06 04:28:42 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-06 04:28:42 +0000
commit753cbbbd3ce28253f381caff83ce2a7f6e08785b (patch)
tree2cd99ba29bce96f8f3db9d4e4ef781c959c68679 /include/llvm/Support/FileSystem.h
parentf150e7695e32d42856d86499fcde970825371637 (diff)
downloadllvm-753cbbbd3ce28253f381caff83ce2a7f6e08785b.tar.gz
llvm-753cbbbd3ce28253f381caff83ce2a7f6e08785b.tar.bz2
llvm-753cbbbd3ce28253f381caff83ce2a7f6e08785b.tar.xz
Support/FileSystem: Add directory_iterator implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120989 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/FileSystem.h')
-rw-r--r--include/llvm/Support/FileSystem.h55
1 files changed, 45 insertions, 10 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index fbf1e0d0a8..f8d3b779db 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -544,19 +544,29 @@ class directory_entry {
public:
explicit directory_entry(const Twine &path, file_status st = file_status(),
- file_status symlink_st = file_status());
+ file_status symlink_st = file_status())
+ : Path(path.str())
+ , Status(st)
+ , SymlinkStatus(symlink_st) {}
+
+ directory_entry() {}
void assign(const Twine &path, file_status st = file_status(),
- file_status symlink_st = file_status());
+ file_status symlink_st = file_status()) {
+ Path = path.str();
+ Status = st;
+ SymlinkStatus = symlink_st;
+ }
+
void replace_filename(const Twine &filename, file_status st = file_status(),
file_status symlink_st = file_status());
- const SmallVectorImpl<char> &path() const;
+ StringRef path() const { return Path; }
error_code status(file_status &result) const;
error_code symlink_status(file_status &result) const;
- bool operator==(const directory_entry& rhs) const;
- bool operator!=(const directory_entry& rhs) const;
+ bool operator==(const directory_entry& rhs) const { return Path == rhs.Path; }
+ bool operator!=(const directory_entry& rhs) const { return !(*this == rhs); }
bool operator< (const directory_entry& rhs) const;
bool operator<=(const directory_entry& rhs) const;
bool operator> (const directory_entry& rhs) const;
@@ -567,16 +577,41 @@ public:
/// operator++ because we need an error_code. If it's really needed we can make
/// it call report_fatal_error on error.
class directory_iterator {
- // implementation directory iterator status
+ intptr_t IterationHandle;
+ directory_entry CurrentEntry;
+
+ // Platform implementations implement these functions to handle iteration.
+ friend error_code directory_iterator_construct(directory_iterator& it,
+ const StringRef &path);
+ friend error_code directory_iterator_increment(directory_iterator& it);
+ friend error_code directory_iterator_destruct(directory_iterator& it);
public:
- explicit directory_iterator(const Twine &path, error_code &ec);
+ explicit directory_iterator(const Twine &path, error_code &ec)
+ : IterationHandle(0) {
+ SmallString<128> path_storage;
+ ec = directory_iterator_construct(*this, path.toStringRef(path_storage));
+ }
+
+ /// Construct end iterator.
+ directory_iterator() : IterationHandle(0) {}
+
+ ~directory_iterator() {
+ directory_iterator_destruct(*this);
+ }
+
// No operator++ because we need error_code.
- directory_iterator &increment(error_code &ec);
+ directory_iterator &increment(error_code &ec) {
+ ec = directory_iterator_increment(*this);
+ return *this;
+ }
- const directory_entry &operator*() const;
- const directory_entry *operator->() const;
+ const directory_entry &operator*() const { return CurrentEntry; }
+ const directory_entry *operator->() const { return &CurrentEntry; };
+ bool operator!=(const directory_iterator &RHS) const {
+ return CurrentEntry != RHS.CurrentEntry;
+ }
// Other members as required by
// C++ Std, 24.1.1 Input iterators [input.iterators]
};