Design Pattern Examples
Overview of object-oriented design patterns
Composite_FileAccess Class Reference

Class containing static functions for accessing a hardcoded "file" and "directory" hierarchy. More...

#include <Composite_FileAccess.h>

Collaboration diagram for Composite_FileAccess:
Collaboration graph

Static Public Member Functions

static FileDirEntryGetEntry (std::string filepath)
 Return a FileDirEntry object representing the specified file "path" in an internal list of data entries that is organized in a file/ directory structure.
 

Static Private Member Functions

static FileDirEntry_FindEntry (std::string filepath)
 Helper method to search the static data list for the specified file/dir entry.
 

Static Private Attributes

static std::shared_ptr< FileDirEntryrootEntry
 List of all "files" and "directories" used in the Command Pattern example.
 

Detailed Description

Class containing static functions for accessing a hardcoded "file" and "directory" hierarchy.

Definition at line 22 of file cplusplus/Composite_FileAccess.h.

Member Function Documentation

◆ _FindEntry()

FileDirEntry * _FindEntry ( std::string  filepath)
staticprivate

Helper method to search the static data list for the specified file/dir entry.

Parameters
filepathA "path" specifying the entry to find, with each component separated by '/'.
Returns
Returns the found entry; otherwise, returns null.

Definition at line 39 of file Composite_FileAccess.cpp.

References FileDirEntry::Children(), FileDirEntry::Name(), Composite_FileAccess::rootEntry, and Helpers::split().

Referenced by Composite_FileAccess::GetEntry().

◆ GetEntry()

FileDirEntry * GetEntry ( std::string  filepath)
static

Return a FileDirEntry object representing the specified file "path" in an internal list of data entries that is organized in a file/ directory structure.

Parameters
filepathA "path" specifying the entry to find, with each component separated by '/'.
Returns
Returns a FileDirEntry object representing the specified file entry.
Exceptions
FIleNotFoundExceptionThe specified file entry was not found.

Definition at line 93 of file Composite_FileAccess.cpp.

References Composite_FileAccess::_FindEntry(), Helpers::formatstring(), and Helpers::Replace().

Referenced by DesignPatternExamples_cpp::Composite_Exercise().

Member Data Documentation

◆ rootEntry

std::shared_ptr< FileDirEntry > rootEntry
staticprivate
Initial value:
=
std::make_shared<DirEntry>("root", DateTime::Now(), FileDirEntryList{
std::make_shared<FileEntry>("FileA.txt", 101, DateTime::Now()),
std::make_shared<FileEntry>("FileB.txt", 102, DateTime::Now()),
std::make_shared<FileEntry>("FileC.txt", 103, DateTime::Now()),
std::make_shared<DirEntry>("subdir1", DateTime::Now(), FileDirEntryList{
std::make_shared<FileEntry>("FileD.txt", 104, DateTime::Now()),
std::make_shared<FileEntry>("FileE.txt", 105, DateTime::Now()),
std::make_shared<DirEntry>("subdir2", DateTime::Now(), FileDirEntryList{
std::make_shared<FileEntry>("FileF.txt", 106, DateTime::Now()),
std::make_shared<FileEntry>("FileG.txt", 107, DateTime::Now())
}),
}),
})
std::vector< std::shared_ptr< FileDirEntry > > FileDirEntryList
Makes it easier to refer to a list of child nodes.

List of all "files" and "directories" used in the Command Pattern example.

Definition at line 29 of file cplusplus/Composite_FileAccess.h.

Referenced by Composite_FileAccess::_FindEntry().


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