IrregularityFile.h 2.34 KB
Newer Older
1
2
3
4
5
6
/**
 * @file IrregularityFile.h
 * @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
update  
Matteo committed
14
#include <nlohmann/json.hpp>
Matteo's avatar
Matteo committed
15
#include <optional>
Matteo's avatar
Matteo committed
16
17
18
#include <vector>

#include "Irregularity.h"
Matteo's avatar
update  
Matteo committed
19
20
21

using json = nlohmann::json;

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

Matteo's avatar
Matteo committed
90
   private:
Matteo's avatar
Matteo committed
91
92
    std::optional<uint16_t> offset_;
    std::vector<std::unique_ptr<Irregularity>> irregularities_;
Matteo's avatar
update  
Matteo committed
93
94
};

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