Implementation of the Composite_Exercise() function as used in the Composite Pattern. More...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/datetime.h"
#include "helpers/dynamicstring.h"
#include "helpers/formatstring.h"
#include "helpers/makelocaltime.h"
#include "Composite_FileDirEntry.h"
#include "Composite_FileAccess.h"
#include "Composite_Exercise.h"
Go to the source code of this file.
Functions | |
static void | Composite_Exercise_FormatEntry (FileDirEntry *entry, int depth, DynamicString *output) |
Format the specified entry for display. | |
static void | Composite_Exercise_ShowEntry (FileDirEntry *entry) |
Recursively display the contents of the hierarchical list of FileDirEntry objects starting with the given object. | |
void | Composite_Exercise (void) |
Example of using the Composite Pattern. | |
Implementation of the Composite_Exercise() function as used in the Composite Pattern.
Definition in file Composite_Exercise.c.
void Composite_Exercise | ( | void | ) |
Example of using the Composite Pattern.
The Composite pattern is used when a collection of objects is to be formed in a hierarchical form where each object needs to be treated like any other object but some objects can contain other objects.
This example uses a file structure of file and directories to represent each object type.
Definition at line 112 of file Composite_Exercise.c.
References Composite_Exercise_ShowEntry(), and Composite_FileAccess_GetEntry().
|
static |
Format the specified entry for display.
This is a recursive call.
entry | The FileDirEntry object to format |
depth | The current recursion depth. This is used as leading space. |
output | A DynamicString in which to collect the output. |
Definition at line 34 of file Composite_Exercise.c.
References Composite_Exercise_FormatEntry(), datetime_to_string(), DynamicString_Append(), FileDirEntry_GetChildren(), FileDirEntry_GetFileDirType(), FileDirEntry_GetLength(), FileDirEntry_GetName(), FileDirEntry_GetWhenModified(), FileDirType_Directory, formatstring(), and FileDirEntry::next.
Referenced by Composite_Exercise_FormatEntry(), and Composite_Exercise_ShowEntry().
|
static |
Recursively display the contents of the hierarchical list of FileDirEntry objects starting with the given object.
entry | The FileDirEntry object to display |
Definition at line 87 of file Composite_Exercise.c.
References Composite_Exercise_FormatEntry(), DynamicString_Clear(), and DynamicString::string.
Referenced by DesignPatternExamples_cpp::Composite_Exercise(), and Composite_Exercise().