poco/Foundation/include/Poco/DirectoryIterator.h

154 lines
3.2 KiB
C
Raw Normal View History

2012-04-29 20:52:25 +02:00
//
// DirectoryIterator.h
//
// Library: Foundation
// Package: Filesystem
// Module: DirectoryIterator
//
// Definition of the DirectoryIterator class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
2012-04-29 20:52:25 +02:00
//
#ifndef Foundation_DirectoryIterator_INCLUDED
#define Foundation_DirectoryIterator_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/File.h"
#include "Poco/Path.h"
namespace Poco {
class DirectoryIteratorImpl;
class Foundation_API DirectoryIterator
/// The DirectoryIterator class is used to enumerate
/// all files in a directory.
///
/// DirectoryIterator has some limitations:
/// * only forward iteration (++) is supported
/// * an iterator copied from another one will always
/// point to the same file as the original iterator,
/// even is the original iterator has been advanced
/// (all copies of an iterator share their state with
/// the original iterator)
2022-07-07 11:18:20 +02:00
/// * because of this you should only use the prefix
2012-04-29 20:52:25 +02:00
/// increment operator
{
public:
DirectoryIterator();
/// Creates the end iterator.
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
DirectoryIterator(const std::string& path);
/// Creates a directory iterator for the given path.
DirectoryIterator(const DirectoryIterator& iterator);
/// Creates a directory iterator for the given path.
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
DirectoryIterator(const File& file);
/// Creates a directory iterator for the given file.
DirectoryIterator(const Path& path);
/// Creates a directory iterator for the given path.
2013-02-19 21:29:58 +01:00
virtual ~DirectoryIterator();
2012-04-29 20:52:25 +02:00
/// Destroys the DirectoryIterator.
const std::string& name() const;
/// Returns the current filename.
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
const Path& path() const;
/// Returns the current path.
DirectoryIterator& operator = (const DirectoryIterator& it);
DirectoryIterator& operator = (const File& file);
DirectoryIterator& operator = (const Path& path);
DirectoryIterator& operator = (const std::string& path);
2022-07-07 11:18:20 +02:00
2013-02-19 21:29:58 +01:00
virtual DirectoryIterator& operator ++ (); // prefix
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
//@ deprecated
DirectoryIterator operator ++ (int); // postfix
/// Please use the prefix increment operator instead.
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
const File& operator * () const;
File& operator * ();
const File* operator -> () const;
File* operator -> ();
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
bool operator == (const DirectoryIterator& iterator) const;
bool operator != (const DirectoryIterator& iterator) const;
protected:
2012-04-29 20:52:25 +02:00
Path _path;
File _file;
2013-02-19 21:29:58 +01:00
private:
2012-04-29 20:52:25 +02:00
DirectoryIteratorImpl* _pImpl;
};
//
// inlines
//
inline const std::string& DirectoryIterator::name() const
{
return _path.getFileName();
}
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
inline const Path& DirectoryIterator::path() const
{
return _path;
}
inline const File& DirectoryIterator::operator * () const
{
return _file;
}
inline File& DirectoryIterator::operator * ()
{
return _file;
}
inline const File* DirectoryIterator::operator -> () const
{
return &_file;
}
inline File* DirectoryIterator::operator -> ()
{
return &_file;
}
inline bool DirectoryIterator::operator == (const DirectoryIterator& iterator) const
{
return name() == iterator.name();
}
inline bool DirectoryIterator::operator != (const DirectoryIterator& iterator) const
{
return name() != iterator.name();
}
} // namespace Poco
#endif // Foundation_DirectoryIterator_INCLUDED