zipios++  2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
zipios::DirectoryCollection Class Reference

A collection generated from reading a directory. More...

#include <directorycollection.hpp>

Inheritance diagram for zipios::DirectoryCollection:
Inheritance graph
[legend]
Collaboration diagram for zipios::DirectoryCollection:
Collaboration graph
[legend]

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_tvector_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
 

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 zipios::FileCollection::MatchPath : uint32_t
stronginherited
Enumerator
IGNORE 
MATCH 

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.

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.

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

zipios::DirectoryCollection::~DirectoryCollection ( )
overridevirtual

The destructor ensures that the object is properly cleaned up.

Definition at line 109 of file directorycollection.cpp.

References close().

Member Function Documentation

void zipios::FileCollection::addEntry ( FileEntry const &  entry)
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.

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
[in]entryThe entry to add to the FileCollection.

Definition at line 368 of file filecollection.cpp.

References zipios::FileEntry::clone(), and zipios::FileCollection::m_entries.

FileCollection::pointer_t zipios::DirectoryCollection::clone ( ) const
overridevirtual

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 242 of file directorycollection.cpp.

References DirectoryCollection().

void zipios::DirectoryCollection::close ( )
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().

FileEntry::vector_t zipios::DirectoryCollection::entries ( ) const
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.

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 144 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
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.

Note
The collection must be valid or the function raises an exception.
Parameters
[in]nameA string containing the name of the entry to get.
[in]matchpathSpeficy 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 172 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 
)
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.

Note
The stream is always opened in binary mode.
Parameters
[in]entry_nameThe name of the file to search in the collection.
[in]matchpathWhether 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 205 of file directorycollection.cpp.

References getEntry().

std::string zipios::FileCollection::getName ( ) const
virtualinherited

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 456 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 493 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
[in]subdirThe directory to read.

Definition at line 297 of file directorycollection.cpp.

References zipios::FileCollection::m_entries, m_filepath, and m_recursive.

Referenced by 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 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().

void zipios::FileCollection::mustBeValid ( ) const
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.

Exceptions
InvalidStateExceptionThis 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().

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
[in]limitThe threshold to use to define the compression level.
[in]small_compression_levelThe compression level for smaller files.
[in]large_compression_levelThe 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().

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
[in]limitThe threshold to use to define the compression level.
[in]small_storage_methodThe storage method for smaller files.
[in]large_storage_methodThe 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().

size_t zipios::DirectoryCollection::size ( ) const
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.

Returns
The number of entries defined in this collection.

Reimplemented from zipios::FileCollection.

Definition at line 227 of file directorycollection.cpp.

References loadEntries(), and zipios::FileCollection::m_entries.

Member Data Documentation

FileEntry::vector_t zipios::FileCollection::m_entries
protectedinherited
bool zipios::DirectoryCollection::m_entries_loaded = false
mutableprotected

Definition at line 59 of file directorycollection.hpp.

Referenced by close(), and loadEntries().

std::string zipios::FileCollection::m_filename
protectedinherited
FilePath zipios::DirectoryCollection::m_filepath
protected

Definition at line 61 of file directorycollection.hpp.

Referenced by close(), DirectoryCollection(), load(), and loadEntries().

bool zipios::DirectoryCollection::m_recursive = true
protected

Definition at line 60 of file directorycollection.hpp.

Referenced by load().

bool zipios::FileCollection::m_valid = true
protectedinherited

The documentation for this class was generated from the following files: