Consider a hierarchical structure like this
directory
[
[item_0;item_1;...;item_n]
[item_0;item_1;inner_directory[...];item_m]
other_directory
[...]
]
A directory contains
- An array of strings (delimited by ‘;’ in input data)
- A map from name to sub-directories (the name of the directory is followed by ‘[‘)
- An array of unnamed sub-directories
The directory can be described by this class:
class Directory
{
public:
//Appropriate operations
private:
std::vector<std::string> items;
std::map<std::string, Directory> named_dirs;
std::vector<Directory> unnamed_dirs;
};
However:
- The Directory class requires three sets of operations, resulting in a large class definition
- A copy operation will be recursive
Can the data be stored in a better way avoiding at least the first point?