/src/bag/api/bag_trackinglist.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef BAG_TRACKINGLIST_H |
2 | | #define BAG_TRACKINGLIST_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 a tracking list. |
27 | | class BAG_API TrackingList final |
28 | | { |
29 | | public: |
30 | | using value_type = TrackingItem; |
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 | | TrackingList(const TrackingList&) = delete; |
37 | | TrackingList(TrackingList&&) = delete; |
38 | | |
39 | | TrackingList& operator=(const TrackingList&) = delete; |
40 | | TrackingList& operator=(TrackingList&&) = delete; |
41 | | |
42 | 0 | bool operator==(const TrackingList &rhs) const noexcept { |
43 | 0 | return m_pH5dataSet == rhs.m_pH5dataSet && |
44 | 0 | weak_ptr_equals(m_pBagDataset, rhs.m_pBagDataset) && |
45 | 0 | itemsEqual(rhs.m_items); |
46 | 0 | } |
47 | | |
48 | 0 | bool operator!=(const TrackingList &rhs) const noexcept { |
49 | 0 | return !(rhs == *this); |
50 | 0 | } |
51 | | |
52 | | iterator begin() & noexcept; |
53 | | const_iterator begin() const & noexcept; |
54 | | iterator end() & noexcept; |
55 | | const_iterator end() const & noexcept; |
56 | | const_iterator cbegin() const & noexcept; |
57 | | const_iterator cend() const & noexcept; |
58 | | |
59 | | void clear() noexcept; |
60 | | void push_back(const value_type& value); |
61 | | void push_back(value_type&& value); |
62 | | template <typename... Args> |
63 | | void emplace_back(Args&&... args) &; |
64 | | reference front() &; |
65 | | const_reference front() const &; |
66 | | reference back() &; |
67 | | const_reference back() const &; |
68 | | void reserve(size_t newCapacity); |
69 | | void resize(size_t count); |
70 | | value_type* data() & noexcept; |
71 | | const value_type* data() const & noexcept; |
72 | | |
73 | | bool empty() const noexcept; |
74 | | size_t size() const noexcept; |
75 | | reference operator[](size_t index) & noexcept; |
76 | | const_reference operator[](size_t index) const & noexcept; |
77 | | |
78 | | void write() const; |
79 | | |
80 | | protected: |
81 | | explicit TrackingList(const Dataset& dataset); |
82 | | TrackingList(const Dataset& dataset, int compressionLevel); |
83 | | |
84 | | private: |
85 | | |
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 in the tracking list. |
93 | | std::vector<value_type> m_items; |
94 | | //! The HDF5 DataSet this class wraps. |
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 TrackingItem. |
125 | | */ |
126 | | template <typename... Args> |
127 | | void TrackingList::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_TRACKINGLIST_H |
139 | | |