todo-cli
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/describe.hpp>
4#include <boost/json.hpp>
5#include <cstdint>
6#include <string>
7#include <vector>
8
9namespace todo {
10struct Task {
11 std::string desc;
12 std::vector<Task> child_tasks;
13 uint16_t priority;
14
15 enum class Status : char {
21
22 struct Date {
23 uint16_t year{};
24 uint16_t month{};
25 uint16_t day{};
27
28 Task() = default;
29 Task(const Task &) = default;
30 Task(Task &&) = default;
31 Task &operator=(const Task &) = default;
32 Task &operator=(Task &&) = default;
33
34 Task(std::string &&desc, uint16_t prio, Status completion, Date &&date)
35 : desc(std::move(desc))
36 , priority(prio)
37 , status(completion)
38 , due_date(std::move(date))
39 {
40 }
41
42 bool operator==(const Task &other) const
43 {
44 if (desc != other.desc) {
45 return false;
46 }
47
48 if (priority != other.priority) {
49 return false;
50 }
51
52 if (status != other.status) {
53 return false;
54 }
55
56 if (child_tasks != other.child_tasks) {
57 return false;
58 }
59
60 if (due_date.year != other.due_date.year) {
61 return false;
62 }
63
64 if (due_date.month != other.due_date.month) {
65 return false;
66 }
67
68 if (due_date.day != other.due_date.day) {
69 return false;
70 }
71
72 return true;
73 }
74
75 bool operator!=(const Task &other) const
76 {
77 return not(*this == other);
78 }
79};
80
81inline void tag_invoke(
82 boost::json::value_from_tag, boost::json::value &v,
83 todo::Task::Status const &s
84)
85{
86 v = static_cast<int>(s);
87}
88
90 boost::json::value_to_tag<todo::Task::Status>, boost::json::value const &v
91)
92{
93 return static_cast<todo::Task::Status>(v.as_int64());
94}
95
96BOOST_DESCRIBE_ENUM(Task::Status, NOT_STARTED, IN_PROGRESS, COMPLETED);
97BOOST_DESCRIBE_STRUCT(Task::Date, (), (year, month, day));
99 Task, (), (desc, child_tasks, priority, status, due_date)
100);
101} // namespace todo
Definition actions.cpp:3
BOOST_DESCRIBE_ENUM(Task::Status, NOT_STARTED, IN_PROGRESS, COMPLETED)
void tag_invoke(boost::json::value_from_tag, boost::json::value &v, todo::Task::Status const &s)
Definition task.h:81
BOOST_DESCRIBE_STRUCT(Task::Date,(),(year, month, day))
Definition task.h:22
uint16_t year
Definition task.h:23
uint16_t day
Definition task.h:25
uint16_t month
Definition task.h:24
Definition task.h:10
Task(const Task &)=default
std::string desc
Description of the task.
Definition task.h:11
enum todo::Task::Status status
Completion status of the task.
Task & operator=(const Task &)=default
struct todo::Task::Date due_date
Due date of the task.
Status
Definition task.h:15
@ NOT_STARTED
Definition task.h:16
@ COMPLETED
Definition task.h:18
@ IN_PROGRESS
Definition task.h:17
@ INVALID
Definition task.h:19
Task()=default
std::vector< Task > child_tasks
Child tasks.
Definition task.h:12
Task & operator=(Task &&)=default
bool operator==(const Task &other) const
Definition task.h:42
Task(std::string &&desc, uint16_t prio, Status completion, Date &&date)
Definition task.h:34
Task(Task &&)=default
uint16_t priority
Priority of the task.
Definition task.h:13
bool operator!=(const Task &other) const
Definition task.h:75