-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo_object.cpp
71 lines (59 loc) · 1.59 KB
/
todo_object.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
68
69
70
71
#include "todo_object.h"
std::string TodoObject::get_title()
{
return title;
}
std::string TodoObject::get_description()
{
return description;
}
bool TodoObject::get_completed()
{
return completed;
}
void TodoObject::set_title(std::string new_title)
{
this->title = new_title;
}
void TodoObject::set_description(std::string new_description)
{
this->description = new_description;
}
void TodoObject::set_completed(bool new_completed)
{
this->completed = new_completed;
}
// This one is a prettier print
std::ostream& operator<< (std::ostream &out, const TodoObject &todo)
{
out << (todo.completed ? "X" : "0") << " | " << todo.title << " : " << todo.description;
return out;
}
// this one is more for serialization
std::ostream& operator<< (std::ostream &out, const TodoObject *todo)
{
out << todo->title << "|" << todo->description << "|" << (todo->completed ? "1" : "0") << std::endl;
return out;
}
std::string TodoObject::get_pretty_print_string()
{
int title_len = this->title.size();
std::stringstream separator;
std::stringstream padding;
int pad_length = 5;
for (int i = 0; i < title_len + pad_length; i++)
{
separator << "-";
}
for (int i = 0; i < pad_length - 1; i++)
{
padding << " ";
}
return "\n" + this->title + padding.str() + (this->completed ? "X" : "O") + "\n" + separator.str() + "\n\n" + this->description + "\n";
}
TodoObject::TodoObject(std::string title, std::string description, bool completed)
{
this->title = title;
this->description = description;
this->completed = completed;
}