Irregularity.cpp 2.35 KB
Newer Older
Matteo's avatar
Matteo committed
1
2
#include "Irregularity.h"

Matteo's avatar
update  
Matteo committed
3
4
5
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
Matteo's avatar
Matteo committed
6
#include <boost/uuid/uuid_io.hpp>
Matteo's avatar
update  
Matteo committed
7

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

Matteo's avatar
Matteo committed
11
Irregularity::Irregularity(Irregularity&& other) noexcept
Matteo's avatar
Matteo committed
12
13
14
15
    : 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
16
17

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

Matteo's avatar
Matteo committed
24
25
26
27
28
29
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
30

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

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

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

    return j;
}

Matteo's avatar
Matteo committed
46
47
48
49
50
51
52
53
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
54
55
56
57
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
58

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

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

Matteo's avatar
Matteo committed
66
std::optional<string> Irregularity::get_image_URI() const { return this->image_URI; }
Matteo's avatar
Matteo committed
67
68
69
70

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