IrregularityFile.hpp 2.42 KB
Newer Older
Matteo Spanio's avatar
update  
Matteo Spanio committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 * @file IrregularityFile.hpp
 * @author Matteo Spanio (dev2@audioinnova.com)
 * @brief Header file containing the IrregularityFile class
 * @version 1.0
 * @date 2023-05-14
 *
 * @copyright Copyright (c) 2023
 *
 */
#ifndef IRREGULARITY_FILE_H
#define IRREGULARITY_FILE_H

#include <algorithm>
#include <exception>
#include <iterator>
#include <memory>
#include <nlohmann/json.hpp>
#include <optional>
#include <vector>

#include "Irregularity.hpp"

using json = nlohmann::json;

/**
 * @class IrregularityFile
 * @brief An IrregularityFile is a collection of Irregularities detected on a
 * tape.
 *
 */
class IrregularityFile {
   public:
    /**
     * @brief Create an IrregularityFile object from a JSON object
     *
     * @param j
     * @return IrregularityFile
     */
    static IrregularityFile fromJSON(const json j);
    /**
     * @brief Convert the IrregularityFile to a JSON object
     *
     * @return json
     */
    json toJSON() const;
    IrregularityFile(std::optional<uint16_t> offset = std::nullopt);
    /**
     * @brief Copy constructor
     *
     * @param rhs
     */
    IrregularityFile(const IrregularityFile& rhs);
    ~IrregularityFile(){};
    /**
     * @brief Add an Irregularity to the IrregularityFile
     *
     * @param irregularity
     * @return IrregularityFile&
     */
    IrregularityFile& add(std::unique_ptr<Irregularity> irregularity);
    /**
     * @brief Remove an Irregularity from the IrregularityFile
     *
     * @param id
     * @return IrregularityFile&
     */
    IrregularityFile& remove_by_id(const boost::uuids::uuid id);
    /**
     * @brief Sort the IrregularityFile by time_label
     *
     * @return IrregularityFile&
     */
    IrregularityFile& sort();
    /**
     * @brief Get the offset object
     *
     * @return std::optional<uint16_t>
     */
    std::optional<uint16_t> get_offset() const;
    /**
     * @brief Get an iterator to the beginning of the IrregularityFile
     *
     * @return std::vector<std::unique_ptr<Irregularity>>::iterator
     */
    std::vector<std::unique_ptr<Irregularity>>::iterator begin();
    /**
     * @brief Get an iterator to the end of the IrregularityFile
     *
     * @return std::vector<std::unique_ptr<Irregularity>>::iterator
     */
    std::vector<std::unique_ptr<Irregularity>>::iterator end();

   private:
    std::optional<uint16_t> offset_;
    std::vector<std::unique_ptr<Irregularity>> irregularities_;
};

#endif  // IRREGULARITY_FILE_HPP