Irregularity.cpp 2.22 KB
Newer Older
Matteo Spanio's avatar
update    
Matteo Spanio committed
1
2
3
#include "Irregularity.hpp"
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 Spanio's avatar
update    
Matteo Spanio committed
5
6
7
8
9
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)) {}
Matteo's avatar
update  
Matteo committed
10

Matteo Spanio's avatar
update    
Matteo Spanio committed
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 Spanio's avatar
update    
Matteo Spanio committed
15
    this->type = std::nullopt;
Matteo's avatar
update  
Matteo committed
16
17
}

Matteo Spanio's avatar
update    
Matteo Spanio 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 Spanio's avatar
update    
Matteo Spanio 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 Spanio's avatar
update    
Matteo Spanio committed
31
32
33
34
35
    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
36
37
38
39

    return j;
}

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

Matteo Spanio's avatar
update    
Matteo Spanio committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    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;
}

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