zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
A collection of collections. More...
#include <collectioncollection.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 | |
CollectionCollection () | |
Initialize a CollectionCollection object. More... | |
CollectionCollection (CollectionCollection const &src) | |
Copy a CollectionCollection in another. More... | |
virtual | ~CollectionCollection () override |
Clean up this CollectionCollection object. More... | |
bool | addCollection (FileCollection const &collection) |
Add a FileCollection to this CollectionCollection. More... | |
bool | addCollection (FileCollection::pointer_t collection) |
Add a collection to this CollectionCollection. More... | |
virtual void | addEntry (FileEntry const &entry) |
Add an entry to this collection. More... | |
virtual pointer_t | clone () const override |
Create a clone of this object. More... | |
virtual void | close () override |
Close the CollectionCollection object. More... | |
virtual FileEntry::vector_t | entries () const override |
Retrieve a vector to all 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... | |
CollectionCollection & | operator= (CollectionCollection const &src) |
Copy assignment operator. 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 size of the of this collection. More... | |
Protected Attributes | |
vector_t | m_collections |
FileEntry::vector_t | m_entries |
std::string | m_filename |
bool | m_valid = true |
CollectionCollection is a FileCollection that consists of an arbitrary number of FileCollection's. With a CollectionCollection the user can use multiple FileCollection objects transparently, making it easy for a program to keep some of its files in a zip archive and others stored in ordinary files. CollectionCollection can be used to create a simple virtual filesystem, where all collections are mounted on /. If more than one collection contain a file with the same path only the one in the first added collection is accessible.
Definition at line 40 of file collectioncollection.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.
|
explicit |
The constructor initializes the CollectionCollection as a valid collection.
Definition at line 97 of file collectioncollection.cpp.
References zipios::FileCollection::m_valid.
Referenced by clone().
zipios::CollectionCollection::CollectionCollection | ( | CollectionCollection const & | src | ) |
This function copies a collection of collections in another. Note that all the children get cloned so the copy can be edited without modify the source and vice versa.
[in] | src | The source to copy in the new CollectionCollection. |
Definition at line 111 of file collectioncollection.cpp.
References m_collections.
|
overridevirtual |
This function ensures that the CollectionCollection object is cleaned up before deallcoating the memory.
Definition at line 172 of file collectioncollection.cpp.
References close().
bool zipios::CollectionCollection::addCollection | ( | FileCollection const & | collection | ) |
This function adds a collection in this CollectionCollection. Since a CollectionCollection is itself a FileCollection, you may add a CollectionCollection to another CollectionCollection.
[in] | collection | The collection to add. |
collection
represents this collection. Definition at line 193 of file collectioncollection.cpp.
References zipios::FileCollection::clone(), zipios::FileCollection::isValid(), m_collections, and mustBeValid().
Referenced by addCollection().
bool zipios::CollectionCollection::addCollection | ( | FileCollection::pointer_t | collection | ) |
This function adds the collection pointed to by collection
to this CollectionCollection.
The CollectionCollection makes a clone of the specified collection
to make sure management of the child collection works as expected.
If the collection does not get added, the function returns false. This happens when the collection
parameter represents an invalid collection.
InvalidException | The function raises InvalidException if the collection parameter is a null pointer. |
[in] | collection | A pointer to the collection to add. |
Definition at line 236 of file collectioncollection.cpp.
References addCollection().
|
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 heap allocated clone of the CollectionCollection.
Note that all the collections that this CollectionCollection points to are all going to get cloned.
Implements zipios::FileCollection.
Definition at line 161 of file collectioncollection.cpp.
References CollectionCollection().
|
overridevirtual |
This function marks the collection as invalid in effect rendering the collection unusable. Note that all the collections that you previously added to this collection all get marked as invalid (i.e. their close() function gets called.) This has the nice side effect to release memory immediately.
Reimplemented from zipios::FileCollection.
Definition at line 260 of file collectioncollection.cpp.
References zipios::FileCollection::close(), and m_collections.
Referenced by ~CollectionCollection().
|
overridevirtual |
This function gathers the entries of all the children collections and add them to a vector that it then returns.
The CollectionCollection itself has no entries.
It is possible to define a CollectionCollection as a child of another CollectionCollection. The process repeats infinitum as required.
Reimplemented from zipios::FileCollection.
Definition at line 293 of file collectioncollection.cpp.
References m_collections, and mustBeValid().
|
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::MatchPath::IGNORE as the second argument. (the default is FileCollection::MatchPath::MATCH.
[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 341 of file collectioncollection.cpp.
References m_collections, zipios::anonymous_namespace{collectioncollection.cpp}::matchEntry(), and mustBeValid().
|
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 there is no entry with the specified name in this CollectionCollection. Note that the name is searched in all the child collections of the CollectionCollection.
Note that the function returns a smart pointer to an istream. In general the CollectionCollection will not hold a copy of that pointer meaning that if you call getInputStream() multiple times with the same entry_name
parameter, you get distinct istream instances each time.
By default the entry_name
parameter is expected to match the full path and filename (MatchPath::MATCH). If you are looking for a file and want to ignore the directory name, set the matchpath parameter to MatchPath::IGNORE.
[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 384 of file collectioncollection.cpp.
References m_collections, zipios::anonymous_namespace{collectioncollection.cpp}::matchEntry(), and mustBeValid().
|
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 addCollection().
|
virtual |
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 from zipios::FileCollection.
Definition at line 432 of file collectioncollection.cpp.
References m_collections, and zipios::FileCollection::mustBeValid().
Referenced by addCollection(), entries(), getEntry(), getInputStream(), and size().
CollectionCollection & zipios::CollectionCollection::operator= | ( | CollectionCollection const & | rhs | ) |
This assignment operator copies rhs
to this collection replacing the file entries that exist in this collection.
Note that the source file entries are cloned in the destination so modifying this collection will not modify the source.
[in] | rhs | The source to copy in this collection. |
Definition at line 132 of file collectioncollection.cpp.
References m_collections, and zipios::FileCollection::operator=().
|
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 computes the total size of this collection which is to sum of the size of its child collections.
Reimplemented from zipios::FileCollection.
Definition at line 408 of file collectioncollection.cpp.
References m_collections, and mustBeValid().
|
protected |
Definition at line 59 of file collectioncollection.hpp.
Referenced by addCollection(), close(), CollectionCollection(), entries(), getEntry(), getInputStream(), mustBeValid(), operator=(), and size().
|
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(), zipios::DirectoryCollection::load(), zipios::DirectoryCollection::loadEntries(), zipios::FileCollection::operator=(), zipios::FileCollection::setLevel(), zipios::FileCollection::setMethod(), zipios::DirectoryCollection::size(), zipios::FileCollection::size(), and zipios::ZipFile::ZipFile().
|
protectedinherited |
Definition at line 72 of file filecollection.hpp.
Referenced by zipios::FileCollection::close(), zipios::DirectoryCollection::DirectoryCollection(), zipios::ZipFile::getInputStream(), zipios::FileCollection::getName(), zipios::FileCollection::operator=(), and zipios::ZipFile::ZipFile().
|
protectedinherited |
Definition at line 74 of file filecollection.hpp.
Referenced by zipios::FileCollection::close(), CollectionCollection(), zipios::DirectoryCollection::DirectoryCollection(), zipios::FileCollection::isValid(), zipios::FileCollection::mustBeValid(), zipios::FileCollection::operator=(), and zipios::ZipFile::ZipFile().