zipios::DirectoryCollection(3) | zipios | zipios::DirectoryCollection(3) |
NAME¶
zipios::DirectoryCollection - A collection generated from reading a directory.
SYNOPSIS¶
#include <directorycollection.hpp>
Inherits zipios::FileCollection.
Public Types¶
enum class MatchPath : uint32_t { IGNORE,
MATCH }
typedef std::shared_ptr< FileCollection > pointer_t
typedef std::shared_ptr< std::istream > stream_pointer_t
A shared pointer to an input stream. typedef std::vector< pointer_t
> vector_t
Public Member Functions¶
DirectoryCollection ()
Initialize a DirectoryCollection object. DirectoryCollection
(std::string const &path, bool recursive=true)
Initialize a DirectoryCollection object. virtual
~DirectoryCollection () override
Clean up a DirectoryCollection object. virtual void addEntry
(FileEntry const &entry)
Add an entry to this collection. virtual pointer_t clone ()
const override
Create another DirectoryCollection. virtual void close ()
override
Close the directory collection. virtual FileEntry::vector_t
entries () const override
Retrieve a vector to the collection entries. virtual
FileEntry::pointer_t getEntry (std::string const &name,
MatchPath matchpath=MatchPath::MATCH) const override
Get an entry from the collection. virtual stream_pointer_t
getInputStream (std::string const &entry_name, MatchPath
matchpath=MatchPath::MATCH) override
Retrieve pointer to an istream. virtual std::string getName () const
Returns the name of the FileCollection. bool isValid () const
Check whether the current collection is valid. virtual void mustBeValid
() const
Check whether the collection is valid. void setLevel (size_t limit,
FileEntry::CompressionLevel small_compression_level,
FileEntry::CompressionLevel large_compression_level)
Change the compression level to the specified value. void setMethod
(size_t limit, StorageMethod small_storage_method,
StorageMethod large_storage_method)
Change the storage method to the specified value. virtual size_t size
() const
Returns the number of entries in the FileCollection.
Protected Member Functions¶
void load (FilePath const &subdir)
This is the function loading all the file entries. void loadEntries ()
const
This is an internal function that loads the file entries.
Protected Attributes¶
FileEntry::vector_t m_entries =
FileEntry::vector_t()
bool m_entries_loaded = false
std::string m_filename = std::string()
FilePath m_filepath
bool m_recursive = true
bool m_valid = true
Detailed Description¶
The DirectoryCollection class is a FileCollection that obtains its entries from a directory on disk.
Definition at line 41 of file directorycollection.hpp.
Member Typedef Documentation¶
typedef std::shared_ptr<FileCollection> zipios::FileCollection::pointer_t [inherited]¶
Definition at line 43 of file filecollection.hpp.
std::shared_ptr< std::istream > zipios::FileCollection::stream_pointer_t [inherited]¶
This type of pointer is used whenever you retrieve an input stream from a file collection such as the ZipFile class. Having shared pointers ensures that the pointers can be shared between various functions and it gets deleted in the end.
Definition at line 45 of file filecollection.hpp.
typedef std::vector<pointer_t> zipios::FileCollection::vector_t [inherited]¶
Definition at line 44 of file filecollection.hpp.
Member Enumeration Documentation¶
enum class zipios::FileCollection::MatchPath : uint32_t [strong], [inherited]¶
Enumerator
Definition at line 47 of file filecollection.hpp.
Constructor & Destructor Documentation¶
zipios::DirectoryCollection::DirectoryCollection ()¶
The default constructor initializes an empty directory collection. Note that an empty collection is invalid by default so there is probably not much you will be able to do with such an object.
Definition at line 65 of file directorycollection.cpp.
zipios::DirectoryCollection::DirectoryCollection (std::string const & path, bool recursive = true)¶
This function initializes a directory which represents a collection of files from disk.
By default recursive is true meaning that the specified directory and all of its children are read in the collection.
Warning
Note
Parameters
recursive Whether to load all the files found in sub-directories.
Definition at line 92 of file directorycollection.cpp.
References zipios::FilePath::isDirectory(), zipios::FilePath::isRegular(), zipios::FileCollection::m_filename, m_filepath, and zipios::FileCollection::m_valid.
zipios::DirectoryCollection::~DirectoryCollection () [override], [virtual]¶
The destructor ensures that the object is properly cleaned up.
Definition at line 107 of file directorycollection.cpp.
References close().
Member Function Documentation¶
void zipios::FileCollection::addEntry (FileEntry const & entry) [virtual], [inherited]¶
This function adds an entry to the file collection allowing you to create a FileCollection from the exact files you want to have in the collection instead of having to read an entire directory as the DirectoryCollection offers by default.
Warning
Parameters
Definition at line 365 of file filecollection.cpp.
References zipios::FileEntry::clone(), and zipios::FileCollection::m_entries.
FileCollection::pointer_t zipios::DirectoryCollection::clone () const [override], [virtual]¶
This function creates a clone of this DirectoryCollection. This is a simple new DirectoryCollection of this collection.
Returns
Implements zipios::FileCollection.
Definition at line 223 of file directorycollection.cpp.
void zipios::DirectoryCollection::close () [override], [virtual]¶
This function marks the collection as invalid in effect rendering the collection unusable.
Reimplemented from zipios::FileCollection.
Definition at line 118 of file directorycollection.cpp.
References zipios::FilePath::clear(), zipios::FileCollection::close(), m_entries_loaded, and m_filepath.
Referenced by ~DirectoryCollection(), and loadEntries().
FileEntry::vector_t zipios::DirectoryCollection::entries () const [override], [virtual]¶
This function makes sure that the directory collection is valid, if not an exception is raised. If valid, then the function makes sure that the entries were loaded and then it returns a copy of the vector holding the entries.
Note
Returns
Reimplemented from zipios::FileCollection.
Definition at line 142 of file directorycollection.cpp.
References zipios::FileCollection::entries(), and loadEntries().
FileEntry::pointer_t zipios::DirectoryCollection::getEntry (std::string const & name, MatchPath matchpath = MatchPath::MATCH) const [override], [virtual]¶
This function returns a shared pointer to a FileEntry object for the entry with the specified name. To ignore the path part of the filename while searching for a match, specify FileCollection::IGNORE as the second argument.
Note
Parameters
matchpath Specify MatchPath::MATCH, if the path should match as well, specify MatchPath::IGNORE, if the path should be ignored.
Returns
See also
Reimplemented from zipios::FileCollection.
Definition at line 170 of file directorycollection.cpp.
References zipios::FileCollection::getEntry(), and loadEntries().
Referenced by getInputStream().
DirectoryCollection::stream_pointer_t zipios::DirectoryCollection::getInputStream (std::string const & entry_name, MatchPath matchpath = MatchPath::MATCH) [override], [virtual]¶
This function returns a shared pointer to an istream defined from the named entry, which is expected to be available in this collection.
The function returns a null pointer if no FileEntry can be found from the specified name or the FileEntry is marked as invalid.
The returned istream represents a file on disk, although the filename must exist in the collection or it will be ignored. A filename that represents a directory cannot return an input stream and thus an error is returned in that case.
Note
Parameters
matchpath Whether the full path or just the filename is matched.
Returns
See also
FileCollection
ZipFile
Implements zipios::FileCollection.
Definition at line 203 of file directorycollection.cpp.
References getEntry().
std::string zipios::FileCollection::getName () const [virtual], [inherited]¶
This function returns the filename of the collection as a whole.
Note
Returns
See also
Definition at line 453 of file filecollection.cpp.
References zipios::FileCollection::m_filename, and zipios::FileCollection::mustBeValid().
Referenced by zipios::operator<<().
bool zipios::FileCollection::isValid () const [inherited]¶
This function returns true if the collection is valid.
Note that by default (just after a new) a collection is not considered valid.
Returns
Definition at line 490 of file filecollection.cpp.
References zipios::FileCollection::m_valid.
Referenced by zipios::CollectionCollection::addCollection().
void zipios::DirectoryCollection::load (FilePath const & subdir) [protected]¶
This function loads all the file entries found in the specified directory. If the DirectoryCollection was created with the recursive flag, then this function will load sub-directories infinitum.
Parameters
Definition at line 278 of file directorycollection.cpp.
References load(), zipios::FileCollection::m_entries, m_filepath, and m_recursive.
Referenced by load(), and loadEntries().
void zipios::DirectoryCollection::loadEntries () const [protected]¶
This function is the top level which starts the process of loading all the files found in the specified directory and sub-directories if the DirectoryCollection was created with the recursive flag set to true (the default.)
Definition at line 236 of file directorycollection.cpp.
References close(), zipios::FilePath::isDirectory(), load(), zipios::FileCollection::m_entries, m_entries_loaded, m_filepath, and zipios::FileCollection::mustBeValid().
Referenced by entries(), and getEntry().
void zipios::FileCollection::mustBeValid () const [virtual], [inherited]¶
This function verifies that the collection is valid. If not, an exception is raised. Many other functions from the various collection functions are calling this function before accessing data.
Exceptions
Reimplemented in zipios::CollectionCollection.
Definition at line 506 of file filecollection.cpp.
References zipios::FileCollection::m_valid.
Referenced by zipios::FileCollection::entries(), zipios::FileCollection::getEntry(), zipios::ZipFile::getInputStream(), zipios::FileCollection::getName(), loadEntries(), zipios::CollectionCollection::mustBeValid(), zipios::FileCollection::setLevel(), zipios::FileCollection::setMethod(), and zipios::FileCollection::size().
void zipios::FileCollection::setLevel (size_t limit, FileEntry::CompressionLevel small_compression_level, FileEntry::CompressionLevel large_compression_level) [inherited]¶
This function changes the compression level of all the entries in this collection to the specified value.
The size limit is used to know which compression level to use: small_compression_level for any file that has a size smaller or equal to the specified limit and large_compression_level for the others.
Parameters
small_compression_level The compression level for smaller files.
large_compression_level The compression level for larger files.
See also
Definition at line 571 of file filecollection.cpp.
References zipios::FileCollection::entries(), zipios::FileCollection::m_entries, and zipios::FileCollection::mustBeValid().
Referenced by main().
void zipios::FileCollection::setMethod (size_t limit, StorageMethod small_storage_method, StorageMethod large_storage_method) [inherited]¶
This function changes the storage method of all the entries in this collection to the specified value.
The size limit is used to know which storage method to use: small_storage_method for any file that has a size smaller or equal to the specified limit and large_storage_method for the others.
Parameters
small_storage_method The storage method for smaller files.
large_storage_method The storage method for larger files.
See also
Definition at line 531 of file filecollection.cpp.
References zipios::FileCollection::entries(), zipios::FileCollection::m_entries, and zipios::FileCollection::mustBeValid().
Referenced by main().
size_t zipios::FileCollection::size () const [virtual], [inherited]¶
This function returns the number of entries in the collection.
Note
Returns
See also
Reimplemented in zipios::CollectionCollection.
Definition at line 471 of file filecollection.cpp.
References zipios::FileCollection::entries(), zipios::FileCollection::m_entries, and zipios::FileCollection::mustBeValid().
Referenced by main().
Member Data Documentation¶
FileEntry::vector_t zipios::FileCollection::m_entries = FileEntry::vector_t() [protected], [inherited]¶
Definition at line 74 of file filecollection.hpp.
Referenced by zipios::FileCollection::FileCollection(), zipios::FileCollection::addEntry(), zipios::FileCollection::close(), zipios::FileCollection::entries(), zipios::FileCollection::getEntry(), zipios::ZipFile::init(), load(), loadEntries(), zipios::FileCollection::operator=(), zipios::FileCollection::setLevel(), zipios::FileCollection::setMethod(), and zipios::FileCollection::size().
bool zipios::DirectoryCollection::m_entries_loaded = false [mutable], [protected]¶
Definition at line 60 of file directorycollection.hpp.
Referenced by close(), and loadEntries().
std::string zipios::FileCollection::m_filename = std::string() [protected], [inherited]¶
Definition at line 73 of file filecollection.hpp.
Referenced by DirectoryCollection(), zipios::ZipFile::ZipFile(), zipios::FileCollection::close(), zipios::ZipFile::getInputStream(), zipios::FileCollection::getName(), and zipios::FileCollection::operator=().
FilePath zipios::DirectoryCollection::m_filepath [protected]¶
Definition at line 62 of file directorycollection.hpp.
Referenced by DirectoryCollection(), close(), load(), and loadEntries().
bool zipios::DirectoryCollection::m_recursive = true [protected]¶
Definition at line 61 of file directorycollection.hpp.
Referenced by load().
bool zipios::FileCollection::m_valid = true [protected], [inherited]¶
Definition at line 75 of file filecollection.hpp.
Referenced by zipios::CollectionCollection::CollectionCollection(), DirectoryCollection(), zipios::FileCollection::close(), zipios::ZipFile::init(), zipios::FileCollection::isValid(), zipios::FileCollection::mustBeValid(), and zipios::FileCollection::operator=().
Author¶
Generated automatically by Doxygen for zipios from the source code.
Sat Dec 30 2023 01:18:29 | Version 2.3.2 |