44#include " activity.h"
55#include " activityinvalidpropertyexception.h"
66
7- const std::vector<stg::activity::color_info_t > &stg::activity::default_colors () {
8- const static std::vector<stg::activity::color_info_t > colors = {
9- {" #FF6562" , " Red" },
10- {" #FFB700" , " Orange" },
11- {" #FFD600" , " Yellow" },
12- {" #A463F2" , " Purple" },
13- {" #D5008F" , " Indigo" },
14- {" #19A974" , " Green" },
15- {" #357EDD" , " Blue" },
16- {" #000000" , " Black" },
17- {" #777777" , " Gray" }
7+ namespace stg {
8+ auto activity::default_colors () -> const std::vector<stg::activity::color_info_t> & {
9+ const static std::vector<activity::color_info_t > colors = {
10+ {" #FF6562" , " Red" },
11+ {" #FFB700" , " Orange" },
12+ {" #FFD600" , " Yellow" },
13+ {" #A463F2" , " Purple" },
14+ {" #D5008F" , " Indigo" },
15+ {" #19A974" , " Green" },
16+ {" #357EDD" , " Blue" },
17+ {" #000000" , " Black" },
18+ {" #777777" , " Gray" }
19+ };
20+
21+ return colors;
1822 };
1923
20- return colors;
21- };
24+ activity::activity (name_t name, color_t color) : _color(std::move(color)) {
25+ if (!is_valid (name)) {
26+ throw empty_name_exception ();
27+ }
2228
23- stg::activity::activity (name_t name, color_t color) : _color(std::move(color)) {
24- if (!is_valid (name)) {
25- throw empty_name_exception ();
29+ _name = std::move (name);
2630 }
2731
28- _name = std::move (name);
29- }
30-
31- bool stg::activity::is_valid (const activity::name_t &name) {
32- bool white_spaces_only = name.find_first_not_of (" \t\n\v\f\r " ) == std::string::npos;
33- return !white_spaces_only;
34- }
35-
36- stg::activity::invalid_property_exception stg::activity::empty_name_exception () {
37- const auto message = " activity name can't be empty" ;
38- return invalid_property_exception (message);
39- }
40-
41- const stg::activity::name_t &stg::activity::name () const {
42- return _name;
43- }
44-
45- const stg::activity::color_t &stg::activity::color () const {
46- return _color;
47- }
48-
49- bool stg::operator ==(const stg::activity &lhs, const stg::activity &rhs) {
50- return lhs.name () == rhs.name () &&
51- lhs.color () == rhs.color ();
52- }
53-
54- bool stg::operator !=(const stg::activity &lhs, const stg::activity &rhs) {
55- return !(lhs == rhs);
56- }
57-
58- std::ostream &stg::operator <<(std::ostream &os,
59- const stg::activity &activity) {
60- os << " activity("
61- << activity.name ()
62- << " , "
63- << activity.color ()
64- << " )" ;
65-
66- return os;
67- }
68-
69- stg::activity stg::activity::copy_changing_name (const name_t &name) const {
70- return activity (name, _color);
71- }
72-
73- stg::activity stg::activity::copy_changing_color (const color_t &color) const {
74- return activity (_name, color);
75- }
76-
77- nlohmann::json stg::activity::to_json () {
78- nlohmann::json j;
79- j[keys::name] = this ->name ();
80- j[keys::color] = this ->color ();
81- return j;
82- }
83-
84- stg::activity stg::activity::from_json (const nlohmann::json &j) {
85- auto name = j[keys::name];
86-
87- stg::color color = activity::default_color;
88- if (j.count (keys::color) && !j[keys::color].is_null ()) {
89- color = j[keys::color];
32+ auto activity::is_valid (const activity::name_t &name) -> bool {
33+ bool white_spaces_only = name.find_first_not_of (" \t\n\v\f\r " ) == std::string::npos;
34+ return !white_spaces_only;
9035 }
9136
92- return activity{name, color};
37+ auto activity::empty_name_exception () -> activity::invalid_property_exception {
38+ const auto *message = " activity name can't be empty" ;
39+ return invalid_property_exception (message);
40+ }
41+
42+ auto activity::name () const -> const activity::name_t & {
43+ return _name;
44+ }
45+
46+ auto activity::color () const -> const activity::color_t & {
47+ return _color;
48+ }
49+
50+ auto operator ==(const stg::activity &lhs, const stg::activity &rhs) -> bool {
51+ return lhs.name () == rhs.name () &&
52+ lhs.color () == rhs.color ();
53+ }
54+
55+ auto operator !=(const stg::activity &lhs, const stg::activity &rhs) -> bool {
56+ return !(lhs == rhs);
57+ }
58+
59+ auto operator <<(std::ostream &os,
60+ const stg::activity &activity) -> std::ostream & {
61+ os << " activity("
62+ << activity.name ()
63+ << " , "
64+ << activity.color ()
65+ << " )" ;
66+
67+ return os;
68+ }
69+
70+ auto activity::with_name (const name_t &name) const -> activity {
71+ return activity (name, _color);
72+ }
73+
74+ auto activity::with_color (const color_t &color) const -> activity {
75+ return activity (_name, color);
76+ }
77+
78+ auto activity::to_json () const -> nlohmann::json {
79+ nlohmann::json j;
80+ j[keys::name] = this ->name ();
81+ j[keys::color] = this ->color ();
82+ return j;
83+ }
84+
85+ auto activity::from_json (const nlohmann::json &j) -> activity {
86+ auto name = j[keys::name];
87+
88+ stg::color color = activity::default_color;
89+ if (j.count (keys::color) && !j[keys::color].is_null ()) {
90+ color = j[keys::color];
91+ }
92+
93+ return activity{name, color};
94+ }
9395}
0 commit comments