forked from jaredtao/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectory.h
55 lines (54 loc) · 1.12 KB
/
Directory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include "Entry.h"
#include <iostream>
#include <string>
#include <vector>
class Directory : public Entry
{
public:
Directory(const std::string &name) : m_name(name) {}
~Directory()
{
for (auto it : m_dirs)
{
delete it;
}
m_dirs.clear();
}
virtual std::string getName() const override
{
return m_name;
}
virtual int getSize() const
{
int size = 0;
for (auto it : m_dirs)
{
size += it->getSize();
}
return size;
}
virtual void addEntryy(Entry *entry) override
{
m_dirs.push_back(entry);
}
virtual void accept(Visitor *visitor) override
{
visitor->visit(this);
}
const std::vector<Entry *> &getEntryList() const
{
return m_dirs;
}
virtual void printList(const std::string &str) override
{
std::cout << str << "/" << toString() << std::endl;
for (auto it : m_dirs)
{
it->printList(str + "/" + m_name);
}
}
private:
std::string m_name;
std::vector<Entry *> m_dirs;
};