Irregularity.cpp 2.38 KB
Newer Older
Matteo's avatar
update  
Matteo committed
1
2
3
4
5
6
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include "Irregularity.h"

Matteo's avatar
Matteo committed
7
8
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
9

Matteo's avatar
Matteo committed
10
11
12
13
Irregularity::Irregularity(Irregularity&& other) noexcept
    : id(std::move(other.id)), source(other.source), time_label(std::move(other.time_label)), type(std::move(other.type)) {}

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

Matteo's avatar
Matteo committed
20
21
22
23
24
25
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
26

Matteo's avatar
Matteo committed
27
json Irregularity::to_JSON() const {
Matteo's avatar
update  
Matteo committed
28
29
30
31
32
    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
33
34
35
36
37
38
39
40
    if (this->type.has_value())
        j["IrregularityType"] = irregularityTypeToString(this->type.value());

    if (this->image_URI.has_value())
        j["ImageURI"] = this->image_URI.value();

    if (this->audio_URI.has_value())
        j["AudioURI"] = this->audio_URI.value();
Matteo's avatar
update  
Matteo committed
41
42
43
44

    return j;
}

Matteo's avatar
Matteo committed
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
72
73
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);
}

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;
}

std::optional<string> Irregularity::get_audio_URI() const {
    return this->audio_URI;
}

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

Matteo's avatar
Matteo committed
75
76
77
78
79
80
81
std::optional<string> Irregularity::get_image_URI() const {
    return this->image_URI;
}

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