Irregularity.cpp 2.22 KB
Newer Older
Matteo's avatar
Matteo committed
1
#include "Irregularity.hpp"
Matteo's avatar
Matteo committed
2
3
Irregularity::Irregularity(const Irregularity& other)
    : id(other.id), source(other.source), time_label(other.time_label), type(other.type) {}
Matteo's avatar
update  
Matteo committed
4

Matteo's avatar
Matteo committed
5
Irregularity::Irregularity(Irregularity&& other) noexcept
Matteo's avatar
Matteo committed
6
7
8
9
    : id(std::move(other.id)),
      source(other.source),
      time_label(std::move(other.time_label)),
      type(std::move(other.type)) {}
Matteo's avatar
Matteo committed
10
11

Irregularity::Irregularity(Source source, string time_label) {
Matteo's avatar
update  
Matteo committed
12
13
14
    this->id = boost::uuids::random_generator()();
    this->source = source;
    this->time_label = time_label;
Matteo's avatar
Matteo committed
15
    this->type = std::nullopt;
Matteo's avatar
update  
Matteo committed
16
17
}

Matteo's avatar
Matteo committed
18
19
20
21
22
23
Irregularity::Irregularity(Source source, string time_label, IrregularityType type) {
    this->id = boost::uuids::random_generator()();
    this->source = source;
    this->time_label = time_label;
    this->type = type;
}
Matteo's avatar
update  
Matteo committed
24

Matteo's avatar
Matteo committed
25
json Irregularity::to_JSON() const {
Matteo's avatar
update  
Matteo committed
26
27
28
29
30
    json j;

    j["IrregularityID"] = boost::lexical_cast<string>(this->id);
    j["Source"] = sourceToString(this->source);
    j["TimeLabel"] = this->time_label;
Matteo's avatar
Matteo committed
31
    if (this->type.has_value()) j["IrregularityType"] = irregularityTypeToString(this->type.value());
Matteo's avatar
Matteo committed
32

Matteo's avatar
Matteo committed
33
    if (this->image_URI.has_value()) j["ImageURI"] = this->image_URI.value();
Matteo's avatar
Matteo committed
34

Matteo's avatar
Matteo committed
35
    if (this->audio_URI.has_value()) j["AudioURI"] = this->audio_URI.value();
Matteo's avatar
update  
Matteo committed
36
37
38
39

    return j;
}

Matteo's avatar
Matteo committed
40
41
42
43
44
45
46
47
Irregularity Irregularity::from_JSON(const json& j) {
    Source source = sourceFromString(j["Source"]);
    string time_label = j["TimeLabel"];
    IrregularityType type = irregularityTypeFromString(j["IrregularityType"]);

    return Irregularity(source, time_label, type);
}

Matteo's avatar
Matteo committed
48
49
50
51
Source Irregularity::get_source() const { return this->source; }
string Irregularity::get_time_label() const { return this->time_label; }
std::optional<IrregularityType> Irregularity::get_type() const { return this->type; }
boost::uuids::uuid Irregularity::get_id() const { return this->id; }
Matteo's avatar
Matteo committed
52

Matteo's avatar
Matteo committed
53
std::optional<string> Irregularity::get_audio_URI() const { return this->audio_URI; }
Matteo's avatar
Matteo committed
54
55
56
57
58

Irregularity& Irregularity::set_audio_URI(string audio_URI) {
    this->audio_URI = audio_URI;
    return *this;
}
Matteo's avatar
update  
Matteo committed
59

Matteo's avatar
Matteo committed
60
std::optional<string> Irregularity::get_image_URI() const { return this->image_URI; }
Matteo's avatar
Matteo committed
61
62
63
64

Irregularity& Irregularity::set_image_URI(string image_URI) {
    this->image_URI = image_URI;
    return *this;
Matteo's avatar
update  
Matteo committed
65
}