-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextFile.cpp
67 lines (52 loc) · 1.21 KB
/
TextFile.cpp
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
59
60
61
62
63
64
65
66
67
/*
Author: Jon Shidal
Purpose: CSE 332 lab 5, defines the TextFile class
*/
#include "TextFile.h"
#include "AbstractFileVisitor.h"
#include<iostream>
using namespace std;
TextFile::TextFile(string n) : name(n), parent(nullptr), count(1) {}
unsigned int TextFile::getSize() {
return contents.size();
}
string TextFile::getName() {
return name;
}
vector<char> TextFile::read() {
return contents;
}
void TextFile::accept(AbstractFileVisitor* fv) {
if (fv) { fv->visit(this); }
}
int TextFile::write(vector<char> data) {
contents = data;
return success;
}
int TextFile::append(vector<char> data) {
for (size_t i = 0; i < data.size(); ++i) {
contents.push_back(data[i]);
}
return success;
}
int TextFile::addChild(AbstractFile*) {
return notacomposite;
}
int TextFile::removeChild(string name) {
return notacomposite;
}
AbstractFile* TextFile::getChild(std::string name) {
return nullptr;
}
AbstractFile* TextFile::getParent() {
return parent;
}
void TextFile::setParent(AbstractFile* p) {
parent = p;
}
TextFile* TextFile::clone() {
TextFile* temp = new TextFile(name);
temp->write(this->read());
temp->setParent(nullptr);
return temp;
}