9#include "helpers/DateTime.h"
10#include "helpers/formatstring.h"
11#include "helpers/replace.h"
12#include "helpers/split.h"
25 std::make_shared<FileEntry>(
"FileA.txt", 101, DateTime::Now()),
26 std::make_shared<FileEntry>(
"FileB.txt", 102, DateTime::Now()),
27 std::make_shared<FileEntry>(
"FileC.txt", 103, DateTime::Now()),
29 std::make_shared<FileEntry>(
"FileD.txt", 104, DateTime::Now()),
30 std::make_shared<FileEntry>(
"FileE.txt", 105, DateTime::Now()),
32 std::make_shared<FileEntry>(
"FileF.txt", 106, DateTime::Now()),
33 std::make_shared<FileEntry>(
"FileG.txt", 107, DateTime::Now())
43 std::vector<std::string> pathComponents =
Helpers::split(filepath,
"/");
44 size_t numComponents = pathComponents.size();
45 for (
size_t index = 0; index < numComponents; ++index)
47 if (root->
Name() != pathComponents[index])
53 if (index + 1 >= numComponents)
71 std::string childComponent = pathComponents[index + 1];
72 for (FileDirEntryList::iterator childIter = std::begin(children);
73 childIter != std::end(children);
76 if (childComponent == (*childIter)->Name())
78 root = (*childIter).get();
98 if (fileDirEntry ==
nullptr)
101 std::error_code errorcode(2, std::generic_category());
102 throw std::filesystem::filesystem_error(msg, errorcode);
static FileDirEntry * _FindEntry(std::string filepath)
Helper method to search the static data list for the specified file/dir entry.
static std::shared_ptr< FileDirEntry > rootEntry
List of all "files" and "directories" used in the Command Pattern example.
static FileDirEntry * GetEntry(std::string filepath)
Return a FileDirEntry object representing the specified file "path" in an internal list of data entri...
Base class representing a File or Directory entry.
virtual std::string Name()
The name of this entry.
virtual FileDirEntryList Children()
The children of this entry. Is empty if the entry can never have any children (that is,...
Represents a timestamp composed of a date and a time encoded in a time_t value. Provides ways of gett...
Declaration of the Composite_FileAccess class used in the Composite Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
std::vector< std::shared_ptr< FileDirEntry > > FileDirEntryList
Makes it easier to refer to a list of child nodes.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....
std::vector< std::string > split(const char *pszString, const char *splitChars)
Split the given string into a list of strings given the character on which to split....
std::string Replace(const std::string &s, const char *str1, const char *str2, bool bCaseInsensitive)
Replace all occurrences of narrow string str1 with narrow string str2 in s. If str2 is empty then all...