zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
Base class for various file collections. More...
#include <filecollection.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 | |
FileCollection (std::string const &filename="") | |
Initializes a FileCollection object. More... | |
FileCollection (FileCollection const &src) | |
Copy a FileCollection in a new one. More... | |
virtual | ~FileCollection () |
Make sure the resources are released. More... | |
virtual void | addEntry (FileEntry const &entry) |
Add an entry to this collection. More... | |
virtual pointer_t | clone () const =0 |
Create a clone of this object. More... | |
virtual void | close () |
Close the current FileEntry of this FileCollection. More... | |
virtual FileEntry::vector_t | entries () const |
Retrieve the array of entries. More... | |
virtual FileEntry::pointer_t | getEntry (std::string const &name, MatchPath matchpath=MatchPath::MATCH) const |
Get an entry from this collection. More... | |
virtual stream_pointer_t | getInputStream (std::string const &entry_name, MatchPath matchpath=MatchPath::MATCH)=0 |
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... | |
FileCollection & | operator= (FileCollection const &src) |
Replace the content of a collection with a copy of another collection. 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 |
Returns the number of entries in the FileCollection. More... | |
Protected Attributes | |
FileEntry::vector_t | m_entries |
std::string | m_filename |
bool | m_valid = true |
FileCollection is an abstract baseclass that represents a collection of files. The specializations of FileCollection represents different origins of file collections, such as directories, simple filename lists and compressed archives.
Definition at line 40 of file filecollection.hpp.
typedef std::shared_ptr<FileCollection> zipios::FileCollection::pointer_t |
Definition at line 43 of file filecollection.hpp.
std::shared_ptr< std::istream > zipios::FileCollection::stream_pointer_t |
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 |
Definition at line 44 of file filecollection.hpp.
|
strong |
Enumerator | |
---|---|
IGNORE | |
MATCH |
Definition at line 47 of file filecollection.hpp.
zipios::FileCollection::FileCollection | ( | std::string const & | filename = "" | ) |
This FileCollection constructor initializes the object and mark it as invalid. In most cases an invalid collection cannot be used for anything. You may make it valid by copying a valid collection in it.
By default the FileCollection is given the special filename "-".
The collection is empty and marked as invalid.
Definition at line 269 of file filecollection.cpp.
zipios::FileCollection::FileCollection | ( | FileCollection const & | src | ) |
This constructor copies a file collection (src
) in a new collection.
The copy entries that all the entries from the source collection get cloned in the copy. This means entries in the source or new collection can be modified and it has no effect on the entries in the other collection.
[in] | src | The source collection to copy in this collection. |
Definition at line 288 of file filecollection.cpp.
References m_entries.
|
virtual |
The FileCollection destructor makes sure that any resources still allocated get released.
For example, the ZipFile implementation calls the close() function.
Definition at line 349 of file filecollection.cpp.
|
virtual |
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 m_entries.
|
pure virtual |
This function creates a heap allocated clone of the object this method is called for.
Implemented in zipios::ZipFile, zipios::DirectoryCollection, and zipios::CollectionCollection.
Referenced by zipios::CollectionCollection::addCollection().
|
virtual |
This function closes the current file entry.
Reimplemented in zipios::CollectionCollection, and zipios::DirectoryCollection.
Definition at line 378 of file filecollection.cpp.
References zipios::anonymous_namespace{filecollection.cpp}::g_default_filename, m_entries, m_filename, and m_valid.
Referenced by zipios::DirectoryCollection::close(), zipios::CollectionCollection::close(), and zipios::ZipFile::~ZipFile().
|
virtual |
This function returns a copy of the file collection vector of entries. Note that the vector is copied but not the entries, so modifications to the entries will be reflected in this FileCollection entries. However, adding and removing entries to the collection is not reflected in the copy.
Reimplemented in zipios::CollectionCollection, and zipios::DirectoryCollection.
Definition at line 396 of file filecollection.cpp.
References m_entries, and mustBeValid().
Referenced by zipios::DirectoryCollection::entries(), getEntry(), main(), zipios::operator<<(), zipios::ZipFile::saveCollectionToArchive(), setLevel(), setMethod(), and size().
|
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.
[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 in zipios::CollectionCollection, and zipios::DirectoryCollection.
Definition at line 424 of file filecollection.cpp.
References entries(), m_entries, MATCH, and mustBeValid().
Referenced by zipios::DirectoryCollection::getEntry(), zipios::ZipFile::getInputStream(), and main().
|
pure 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 there is no entry with the specified name in this FileCollection.
Note that the function returns a smart pointer to an istream. In general the FileCollection will not hold 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. |
Implemented in zipios::ZipFile, zipios::CollectionCollection, and zipios::DirectoryCollection.
Referenced by zipios::ZipFile::saveCollectionToArchive().
|
virtual |
This function returns the filename of the collection as a whole.
Definition at line 456 of file filecollection.cpp.
References m_filename, and mustBeValid().
Referenced by zipios::operator<<().
bool zipios::FileCollection::isValid | ( | ) | const |
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 m_valid.
Referenced by zipios::CollectionCollection::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 in zipios::CollectionCollection.
Definition at line 509 of file filecollection.cpp.
References m_valid.
Referenced by entries(), getEntry(), zipios::ZipFile::getInputStream(), getName(), zipios::DirectoryCollection::loadEntries(), zipios::CollectionCollection::mustBeValid(), setLevel(), setMethod(), and size().
FileCollection & zipios::FileCollection::operator= | ( | FileCollection const & | rhs | ) |
This function copies the rhs
collection in this collection.
Note that the entries in the this collection get released. If you still have a reference to them in a shared pointer, they will not be deleted.
The entries in rhs
get cloned so modifying the entries in the source or the destination has no effect on the entries of the other collection.
[in] | rhs | The source FileCollection to copy. |
Definition at line 315 of file filecollection.cpp.
References m_entries, m_filename, and m_valid.
Referenced by zipios::CollectionCollection::operator=().
void zipios::FileCollection::setLevel | ( | size_t | limit, |
FileEntry::CompressionLevel | small_compression_level, | ||
FileEntry::CompressionLevel | large_compression_level | ||
) |
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 entries(), m_entries, and mustBeValid().
void zipios::FileCollection::setMethod | ( | size_t | limit, |
StorageMethod | small_storage_method, | ||
StorageMethod | large_storage_method | ||
) |
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 entries(), m_entries, and mustBeValid().
|
virtual |
This function returns the number of entries in the collection.
Reimplemented in zipios::CollectionCollection, and zipios::DirectoryCollection.
Definition at line 474 of file filecollection.cpp.
References entries(), m_entries, and mustBeValid().
Referenced by main().
|
protected |
Definition at line 73 of file filecollection.hpp.
Referenced by addEntry(), close(), entries(), FileCollection(), getEntry(), zipios::DirectoryCollection::load(), zipios::DirectoryCollection::loadEntries(), operator=(), setLevel(), setMethod(), zipios::DirectoryCollection::size(), size(), and zipios::ZipFile::ZipFile().
|
protected |
Definition at line 72 of file filecollection.hpp.
Referenced by close(), zipios::DirectoryCollection::DirectoryCollection(), zipios::ZipFile::getInputStream(), getName(), operator=(), and zipios::ZipFile::ZipFile().
|
protected |
Definition at line 74 of file filecollection.hpp.
Referenced by close(), zipios::CollectionCollection::CollectionCollection(), zipios::DirectoryCollection::DirectoryCollection(), isValid(), mustBeValid(), operator=(), and zipios::ZipFile::ZipFile().