zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
A collection generated from reading a directory. More...
#include <directorycollection.hpp>
Public Types | |
enum | MatchPath : uint32_t { MatchPath::IGNORE, MatchPath::MATCH } |
typedef std::shared_ptr < FileCollection > | pointer_t |
typedef std::shared_ptr < std::istream > | stream_pointer_t |
A shared pointer to an input stream. More... | |
typedef std::vector< pointer_t > | vector_t |
Public Member Functions | |
DirectoryCollection () | |
Initialize a DirectoryCollection object. More... | |
DirectoryCollection (std::string const &path, bool recursive=true) | |
Initialize a DirectoryCollection object. More... | |
virtual | ~DirectoryCollection () override |
Clean up a DirectoryCollection object. More... | |
virtual void | addEntry (FileEntry const &entry) |
Add an entry to this collection. More... | |
virtual pointer_t | clone () const override |
Create another DirectoryCollection. More... | |
virtual void | close () override |
Close the directory collection. More... | |
virtual FileEntry::vector_t | entries () const override |
Retrieve a vector to the collection entries. More... | |
virtual FileEntry::pointer_t | getEntry (std::string const &name, MatchPath matchpath=MatchPath::MATCH) const override |
Get an entry from the collection. More... | |
virtual stream_pointer_t | getInputStream (std::string const &entry_name, MatchPath matchpath=MatchPath::MATCH) override |
Retrieve pointer to an istream. More... | |
virtual std::string | getName () const |
Returns the name of the FileCollection. More... | |
bool | isValid () const |
Check whether the current collection is valid. More... | |
virtual void | mustBeValid () const |
Check whether the collection is valid. More... | |
void | setLevel (size_t limit, FileEntry::CompressionLevel small_compression_level, FileEntry::CompressionLevel large_compression_level) |
Change the compression level to the specified value. More... | |
void | setMethod (size_t limit, StorageMethod small_storage_method, StorageMethod large_storage_method) |
Change the storage method to the specified value. More... | |
virtual size_t | size () const override |
Return the number of entries defined in this collection. More... | |
Protected Member Functions | |
void | load (FilePath const &subdir) |
This is the function loading all the file entries. More... | |
void | loadEntries () const |
This is an internal function that loads the file entries. More... | |
Protected Attributes | |
FileEntry::vector_t | m_entries |
bool | m_entries_loaded = false |
std::string | m_filename |
FilePath | m_filepath |
bool | m_recursive = true |
bool | m_valid = true |
The DirectoryCollection class is a FileCollection that obtains its entries from a directory on disk.
Definition at line 41 of file directorycollection.hpp.
|
inherited |
Definition at line 43 of file filecollection.hpp.
|
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.
|
inherited |
Definition at line 44 of file filecollection.hpp.
|
stronginherited |
Enumerator | |
---|---|
IGNORE | |
MATCH |
Definition at line 47 of file filecollection.hpp.
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.
Referenced by clone().
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.
[in] | path | A directory path. If the name is not a valid directory the created DirectoryCollection is marked as being invalid. |
[in] | recursive | Whether to load all the files found in sub-direcotries. |
Definition at line 95 of file directorycollection.cpp.
References zipios::FilePath::isDirectory(), zipios::FilePath::isRegular(), zipios::FileCollection::m_filename, m_filepath, and zipios::FileCollection::m_valid.
|
overridevirtual |
The destructor ensures that the object is properly cleaned up.
Definition at line 109 of file directorycollection.cpp.
References close().
|
virtualinherited |
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.
[in] | entry | The entry to add to the FileCollection. |
Definition at line 368 of file filecollection.cpp.
References zipios::FileEntry::clone(), and zipios::FileCollection::m_entries.
|
overridevirtual |
This function creates a clone of this DirectoryCollection. This is a simple new DirectoryCollection of this collection.
Implements zipios::FileCollection.
Definition at line 242 of file directorycollection.cpp.
References DirectoryCollection().
|
overridevirtual |
This function marks the collection as invalid in effect rendering the collection unusable.
Reimplemented from zipios::FileCollection.
Definition at line 120 of file directorycollection.cpp.
References zipios::FileCollection::close(), m_entries_loaded, and m_filepath.
Referenced by loadEntries(), and ~DirectoryCollection().
|
overridevirtual |
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.
Reimplemented from zipios::FileCollection.
Definition at line 144 of file directorycollection.cpp.
References zipios::FileCollection::entries(), and loadEntries().
|
overridevirtual |
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.
[in] | name | A string containing the name of the entry to get. |
[in] | matchpath | Speficy MatchPath::MATCH, if the path should match as well, specify MatchPath::IGNORE, if the path should be ignored. |
Reimplemented from zipios::FileCollection.
Definition at line 172 of file directorycollection.cpp.
References zipios::FileCollection::getEntry(), and loadEntries().
Referenced by getInputStream().
|
overridevirtual |
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.
[in] | entry_name | The name of the file to search in the collection. |
[in] | matchpath | Whether the full path or just the filename is matched. |
Implements zipios::FileCollection.
Definition at line 205 of file directorycollection.cpp.
References getEntry().
|
virtualinherited |
This function returns the filename of the collection as a whole.
Definition at line 456 of file filecollection.cpp.
References zipios::FileCollection::m_filename, and zipios::FileCollection::mustBeValid().
Referenced by zipios::operator<<().
|
inherited |
This function returns true if the collection is valid.
Note that by default (just after a new) a collection is not considered valid.
Definition at line 493 of file filecollection.cpp.
References zipios::FileCollection::m_valid.
Referenced by zipios::CollectionCollection::addCollection().
|
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.
[in] | subdir | The directory to read. |
Definition at line 297 of file directorycollection.cpp.
References zipios::FileCollection::m_entries, m_filepath, and m_recursive.
Referenced by loadEntries().
|
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 255 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(), getEntry(), and size().
|
virtualinherited |
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.
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 509 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().
|
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.
[in] | limit | The threshold to use to define the compression level. |
[in] | small_compression_level | The compression level for smaller files. |
[in] | large_compression_level | The compression level for larger files. |
Definition at line 567 of file filecollection.cpp.
References zipios::FileCollection::entries(), zipios::FileCollection::m_entries, and zipios::FileCollection::mustBeValid().
|
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.
[in] | limit | The threshold to use to define the compression level. |
[in] | small_storage_method | The storage method for smaller files. |
[in] | large_storage_method | The storage method for larger files. |
Definition at line 532 of file filecollection.cpp.
References zipios::FileCollection::entries(), zipios::FileCollection::m_entries, and zipios::FileCollection::mustBeValid().
|
overridevirtual |
This function makes sure that the DirectoryCollection loaded its entries, then it returns the size of the m_entries vector which represents all the files in this directory, including the root directory.
Reimplemented from zipios::FileCollection.
Definition at line 227 of file directorycollection.cpp.
References loadEntries(), and zipios::FileCollection::m_entries.
|
protectedinherited |
Definition at line 73 of file filecollection.hpp.
Referenced by zipios::FileCollection::addEntry(), zipios::FileCollection::close(), zipios::FileCollection::entries(), zipios::FileCollection::FileCollection(), zipios::FileCollection::getEntry(), load(), loadEntries(), zipios::FileCollection::operator=(), zipios::FileCollection::setLevel(), zipios::FileCollection::setMethod(), size(), zipios::FileCollection::size(), and zipios::ZipFile::ZipFile().
|
mutableprotected |
Definition at line 59 of file directorycollection.hpp.
Referenced by close(), and loadEntries().
|
protectedinherited |
Definition at line 72 of file filecollection.hpp.
Referenced by zipios::FileCollection::close(), DirectoryCollection(), zipios::ZipFile::getInputStream(), zipios::FileCollection::getName(), zipios::FileCollection::operator=(), and zipios::ZipFile::ZipFile().
|
protected |
Definition at line 61 of file directorycollection.hpp.
Referenced by close(), DirectoryCollection(), load(), and loadEntries().
|
protected |
Definition at line 60 of file directorycollection.hpp.
Referenced by load().
|
protectedinherited |
Definition at line 74 of file filecollection.hpp.
Referenced by zipios::FileCollection::close(), zipios::CollectionCollection::CollectionCollection(), DirectoryCollection(), zipios::FileCollection::isValid(), zipios::FileCollection::mustBeValid(), zipios::FileCollection::operator=(), and zipios::ZipFile::ZipFile().