This repository was archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEntry.cpp
More file actions
58 lines (48 loc) · 1.28 KB
/
Entry.cpp
File metadata and controls
58 lines (48 loc) · 1.28 KB
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
56
57
58
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include "Entry.h"
#include <wx/icon.h>
#include "res/img_error.xpm"
wxImage Entry::CreateImage() {
if (IsDirectory())
return wxImage();
auto stream = GetInputStream();
if(!stream) return wxImage(IMG_ERROR_xpm);
wxImage output(*stream);
delete stream;
if(!output.IsOk())
return wxImage(IMG_ERROR_xpm);
return output;
}
void Entry::WriteStream(wxOutputStream &output) {
auto stream = GetInputStream();
if(!stream) return;
output.Write(*stream);
delete stream;
}
Entry::~Entry() {
for (auto entry : children) {
delete entry;
}
children.clear();
}
void Entry::PrintChildren(const int &level) {
for (int i = 0; i < level; i++)
std::cout << "|-";
std::cout << Name() << std::endl;
for (auto child : children) {
child->PrintChildren(level + 1);
}
}
void Entry::SortChildren() {
std::sort(children.begin(), children.end(), [](Entry *e1, Entry *e2) {
if (e1->IsDirectory() == e2->IsDirectory()) {
return e1->Name() < e2->Name();
} else if (e1->IsDirectory()) {
return true;
} else {
return false;
}
});
std::for_each(children.begin(), children.end(),
[](Entry *e) { e->SortChildren(); });
}