IrregularityFile.hpp 2.42 KB
Newer Older
1
/**
Matteo's avatar
Matteo committed
2
 * @file IrregularityFile.hpp
3
4
5
6
 * @author Matteo Spanio (dev2@audioinnova.com)
 * @brief Header file containing the IrregularityFile class
 * @version 1.0
 * @date 2023-05-14
Matteo's avatar
Matteo committed
7
 *
8
 * @copyright Copyright (c) 2023
Matteo's avatar
Matteo committed
9
 *
10
 */
Matteo's avatar
update  
Matteo committed
11
12
#ifndef IRREGULARITY_FILE_H
#define IRREGULARITY_FILE_H
Matteo's avatar
Matteo committed
13

Matteo's avatar
Matteo committed
14
15
16
17
#include <algorithm>
#include <exception>
#include <iterator>
#include <memory>
Matteo's avatar
update  
Matteo committed
18
#include <nlohmann/json.hpp>
Matteo's avatar
Matteo committed
19
#include <optional>
Matteo's avatar
Matteo committed
20
21
#include <vector>

Matteo's avatar
Matteo committed
22
#include "Irregularity.hpp"
Matteo's avatar
update  
Matteo committed
23
24
25

using json = nlohmann::json;

Matteo's avatar
Matteo committed
26
27
/**
 * @class IrregularityFile
Matteo's avatar
Matteo committed
28
29
30
 * @brief An IrregularityFile is a collection of Irregularities detected on a
 * tape.
 *
Matteo's avatar
Matteo committed
31
 */
Matteo's avatar
Matteo committed
32
class IrregularityFile {
Matteo's avatar
Matteo committed
33
   public:
Matteo's avatar
Matteo committed
34
35
    /**
     * @brief Create an IrregularityFile object from a JSON object
Matteo's avatar
Matteo committed
36
37
38
     *
     * @param j
     * @return IrregularityFile
Matteo's avatar
Matteo committed
39
     */
Matteo's avatar
update  
Matteo committed
40
    static IrregularityFile fromJSON(const json j);
Matteo's avatar
Matteo committed
41
42
    /**
     * @brief Convert the IrregularityFile to a JSON object
Matteo's avatar
Matteo committed
43
44
     *
     * @return json
Matteo's avatar
Matteo committed
45
46
47
48
49
     */
    json toJSON() const;
    IrregularityFile(std::optional<uint16_t> offset = std::nullopt);
    /**
     * @brief Copy constructor
Matteo's avatar
Matteo committed
50
51
     *
     * @param rhs
Matteo's avatar
Matteo committed
52
     */
Matteo's avatar
Matteo committed
53
54
    IrregularityFile(const IrregularityFile& rhs);
    ~IrregularityFile(){};
Matteo's avatar
Matteo committed
55
56
    /**
     * @brief Add an Irregularity to the IrregularityFile
Matteo's avatar
Matteo committed
57
58
59
     *
     * @param irregularity
     * @return IrregularityFile&
Matteo's avatar
Matteo committed
60
61
62
63
     */
    IrregularityFile& add(std::unique_ptr<Irregularity> irregularity);
    /**
     * @brief Remove an Irregularity from the IrregularityFile
Matteo's avatar
Matteo committed
64
65
66
     *
     * @param id
     * @return IrregularityFile&
Matteo's avatar
Matteo committed
67
     */
Matteo's avatar
update    
Matteo committed
68
    IrregularityFile& remove_by_id(const boost::uuids::uuid id);
Matteo's avatar
Matteo committed
69
70
    /**
     * @brief Sort the IrregularityFile by time_label
Matteo's avatar
Matteo committed
71
72
     *
     * @return IrregularityFile&
Matteo's avatar
Matteo committed
73
     */
Matteo's avatar
update    
Matteo committed
74
    IrregularityFile& sort();
Matteo's avatar
Matteo committed
75
76
    /**
     * @brief Get the offset object
Matteo's avatar
Matteo committed
77
78
     *
     * @return std::optional<uint16_t>
Matteo's avatar
Matteo committed
79
80
81
82
     */
    std::optional<uint16_t> get_offset() const;
    /**
     * @brief Get an iterator to the beginning of the IrregularityFile
Matteo's avatar
Matteo committed
83
84
     *
     * @return std::vector<std::unique_ptr<Irregularity>>::iterator
Matteo's avatar
Matteo committed
85
86
87
88
     */
    std::vector<std::unique_ptr<Irregularity>>::iterator begin();
    /**
     * @brief Get an iterator to the end of the IrregularityFile
Matteo's avatar
Matteo committed
89
90
     *
     * @return std::vector<std::unique_ptr<Irregularity>>::iterator
Matteo's avatar
Matteo committed
91
92
93
     */
    std::vector<std::unique_ptr<Irregularity>>::iterator end();

Matteo's avatar
Matteo committed
94
   private:
Matteo's avatar
Matteo committed
95
96
    std::optional<uint16_t> offset_;
    std::vector<std::unique_ptr<Irregularity>> irregularities_;
Matteo's avatar
update  
Matteo committed
97
98
};

Matteo's avatar
Matteo committed
99
#endif  // IRREGULARITY_FILE_HPP