Scroll to navigation

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

The specified path must be a valid directory path and name. If the name represents a file, then the DirectoryCollection is marked as invalid.

Note

The file content is not loaded so the collection is fairly lightweight.

Parameters

path A directory path. If the name is not a valid directory the created DirectoryCollection is marked as being invalid.
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

This function creates a clone of the entry to make sure that the caller's entry can be modified without affecting the FileCollection.

Parameters

entry The entry to add to the FileCollection.

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

The function returns a shared pointer of the new collection.

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

The copy of the vector is required because of the implementation of CollectionCollection which does not hold a vector of all the entries defined in its children. It is also cleaner (albeit slower) in case one wants to use the library in a thread environment.

Returns

A copy of the internal FileEntry vector.

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

The collection must be valid or the function raises an exception.

Parameters

name A string containing the name of the entry to get.
matchpath Specify MatchPath::MATCH, if the path should match as well, specify MatchPath::IGNORE, if the path should be ignored.

Returns

A shared pointer to the found entry. The returned pointer is null if no entry is found.

See also

mustBeValid()

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

The stream is always opened in binary mode.

Parameters

entry_name The name of the file to search in the collection.
matchpath Whether the full path or just the filename is matched.

Returns

A shared pointer to an open istream for the specified entry.

See also

CollectionCollection

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

The collection my be valid.

Returns

The name of the FileCollection.

See also

mustBeValid()

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

true if the collection is valid.

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

subdir The directory to read.

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

InvalidStateException This exception is raised if the m_valid field is currently false and thus most of the collection data is considered invalid.

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

limit The threshold to use to define the compression level.
small_compression_level The compression level for smaller files.
large_compression_level The compression level for larger files.

See also

setMethod()

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

limit The threshold to use to define the compression level.
small_storage_method The storage method for smaller files.
large_storage_method The storage method for larger files.

See also

setLevel()

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

The collection my be valid.

Returns

The number of entries in the FileCollection.

See also

mustBeValid()

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