FireSTARR
Loading...
Searching...
No Matches
SafeVector.h
1/* Copyright (c) Queen's Printer for Ontario, 2020. */
2/* Copyright (c) His Majesty the King in Right of Canada as represented by the Minister of Natural Resources, 2025. */
3
4/* SPDX-License-Identifier: AGPL-3.0-or-later */
5
6#pragma once
7#include <vector>
8namespace fs::util
9{
10class Statistics;
15{
19 std::vector<MathSize> values_{};
23 mutable mutex mutex_{};
24public:
28 ~SafeVector() = default;
32 SafeVector() = default;
37 SafeVector(const SafeVector& rhs);
42 SafeVector(SafeVector&& rhs) noexcept;
48 SafeVector& operator=(const SafeVector& rhs) noexcept;
54 SafeVector& operator=(SafeVector&& rhs) noexcept;
59 void addValue(MathSize value);
64 [[nodiscard]] std::vector<MathSize> getValues() const;
69 [[nodiscard]] Statistics getStatistics() const;
74 [[nodiscard]] size_t size() const noexcept;
75};
76}
A vector with added thread safety.
Definition SafeVector.h:15
Statistics getStatistics() const
Calculate Statistics for values in this SafeVector.
Definition SafeVector.cpp:57
SafeVector()=default
Construct empty SafeVector.
mutex mutex_
Mutex for parallel access.
Definition SafeVector.h:23
SafeVector & operator=(const SafeVector &rhs) noexcept
Copy assignment operator.
Definition SafeVector.cpp:19
~SafeVector()=default
Destructor.
size_t size() const noexcept
Number of values in the SafeVector.
Definition SafeVector.cpp:61
std::vector< MathSize > values_
Vector of stored values.
Definition SafeVector.h:19
void addValue(MathSize value)
Add a value to the SafeVector.
Definition SafeVector.cpp:47
std::vector< MathSize > getValues() const
Get a vector with the stored values.
Definition SafeVector.cpp:52
Provides statistics calculation for vectors of values.
Definition Statistics.h:125