Coverage Report

Created: 2025-07-11 06:33

/src/bag/api/bag_vrtrackinglist.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef BAG_VRTRACKINGLIST_H
2
#define BAG_VRTRACKINGLIST_H
3
4
#include "bag_config.h"
5
#include "bag_deleteh5dataset.h"
6
#include "bag_fordec.h"
7
#include "bag_types.h"
8
9
#include <memory>
10
#include <vector>
11
12
13
namespace H5 {
14
15
class DataSet;
16
17
}  // namespace H5
18
19
namespace BAG {
20
21
#ifdef _MSC_VER
22
#pragma warning(push)
23
#pragma warning(disable: 4251)  // std classes do not have DLL-interface when exporting
24
#endif
25
26
//! The interface for the variable resolution tracking list.
27
class BAG_API VRTrackingList final
28
{
29
public:
30
    using value_type = VRTrackingItem;
31
    using iterator = std::vector<value_type>::iterator;
32
    using const_iterator = std::vector<value_type>::const_iterator;
33
    using reference = value_type&;
34
    using const_reference = const value_type&;
35
36
    VRTrackingList(const Dataset& dataset, int compressionLevel);
37
    VRTrackingList(const VRTrackingList&) = delete;
38
    VRTrackingList(VRTrackingList&&) = delete;
39
    // Allow std::make_shared() to call our constructor
40
    explicit VRTrackingList(const Dataset& dataset);
41
42
    VRTrackingList& operator=(const VRTrackingList&) = delete;
43
    VRTrackingList& operator=(VRTrackingList&&) = delete;
44
45
0
    bool operator==(const VRTrackingList &rhs) const noexcept {
46
0
        return m_pH5dataSet == rhs.m_pH5dataSet &&
47
0
               weak_ptr_equals(m_pBagDataset, rhs.m_pBagDataset) &&
48
0
                itemsEqual(rhs.m_items);
49
0
    }
50
51
0
    bool operator!=(const VRTrackingList &rhs) const noexcept {
52
0
        return !(rhs == *this);
53
0
    }
54
55
    iterator begin() & noexcept;
56
    const_iterator begin() const & noexcept;
57
    iterator end() & noexcept;
58
    const_iterator end() const & noexcept;
59
    const_iterator cbegin() const & noexcept;
60
    const_iterator cend() const & noexcept;
61
62
    void clear() noexcept;
63
    void push_back(const value_type& value);
64
    void push_back(value_type&& value);
65
    template <typename... Args>
66
    void emplace_back(Args&&... args) &;
67
    reference front() &;
68
    const_reference front() const &;
69
    reference back() &;
70
    const_reference back() const &;
71
    void reserve(size_t newCapacity);
72
    void resize(size_t count);
73
    value_type* data() & noexcept;
74
    const value_type* data() const & noexcept;
75
76
    bool empty() const noexcept;
77
    size_t size() const noexcept;
78
    reference operator[](size_t index) & noexcept;
79
    const_reference operator[](size_t index) const & noexcept;
80
81
    void write() const;
82
83
protected:
84
85
private:
86
    std::unique_ptr<::H5::DataSet, DeleteH5dataSet> createH5dataSet(
87
        int compressionLevel);
88
    std::unique_ptr<::H5::DataSet, DeleteH5dataSet> openH5dataSet();
89
90
    //! The associated BAG Dataset.
91
    std::weak_ptr<const Dataset> m_pBagDataset;
92
    //! The items making up the tracking list.
93
    std::vector<value_type> m_items;
94
    //! The HDF5 DataSet this class relates to.
95
    std::unique_ptr<::H5::DataSet, DeleteH5dataSet> m_pH5dataSet;
96
97
0
    bool itemsEqual(std::vector<value_type> other) const {
98
0
        auto size = m_items.size();
99
0
        bool areEqual = size == other.size();
100
0
        if (!areEqual) return areEqual;
101
0
102
0
        for (size_t i = 0; i < size; i++) {
103
0
            auto ours = m_items[i];
104
0
            auto theirs = other[i];
105
0
            if (ours.row != theirs.row ||
106
0
                ours.col != theirs.col ||
107
0
                ours.depth != theirs.depth ||
108
0
                ours.uncertainty != theirs.uncertainty ||
109
0
                ours.track_code != theirs.track_code ||
110
0
                ours.list_series != theirs.list_series) {
111
0
                return false;
112
0
            }
113
0
        }
114
0
115
0
        return areEqual;
116
0
    }
117
118
    friend Dataset;
119
};
120
121
//! Add an item to the end of the tracking list.
122
/*!
123
\param args
124
    One or more parameters to hand to the constructor of VRTrackingItem.
125
*/
126
template <typename... Args>
127
void VRTrackingList::emplace_back(Args&&... args) &
128
{
129
    m_items.emplace_back(std::forward<Args>(args)...);
130
}
131
132
#ifdef _MSC_VER
133
#pragma warning(pop)
134
#endif
135
136
}  // namespace BAG
137
138
#endif  // BAG_VRTRACKINGLIST_H
139