renamed FixedCap.. to StaticVector

This commit is contained in:
Erik Frojdh 2020-05-15 09:03:23 +02:00
parent e6deccc2c6
commit 0dd5a099c8
9 changed files with 107 additions and 109 deletions

View File

@ -2164,12 +2164,12 @@ void Module::setReceiverDbitList(const std::vector<int> &list) {
"Dbit list value must be between 0 and 63\n"); "Dbit list value must be between 0 and 63\n");
} }
} }
sls::FixedCapacityContainer<int, MAX_RX_DBIT> arg = list; sls::StaticVector<int, MAX_RX_DBIT> arg = list;
sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr);
} }
std::vector<int> Module::getReceiverDbitList() const { std::vector<int> Module::getReceiverDbitList() const {
return sendToReceiver<sls::FixedCapacityContainer<int, MAX_RX_DBIT>>( return sendToReceiver<sls::StaticVector<int, MAX_RX_DBIT>>(
F_GET_RECEIVER_DBIT_LIST); F_GET_RECEIVER_DBIT_LIST);
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "ClientSocket.h" #include "ClientSocket.h"
#include "FixedCapacityContainer.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "StaticVector.h"
#include "logger.h" #include "logger.h"
#include "network_utils.h" #include "network_utils.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
@ -51,7 +51,7 @@ struct sharedSlsDetector {
char settingsDir[MAX_STR_LENGTH]; char settingsDir[MAX_STR_LENGTH];
/** list of the energies at which the detector has been trimmed */ /** list of the energies at which the detector has been trimmed */
sls::FixedCapacityContainer<int, MAX_TRIMEN> trimEnergies; sls::StaticVector<int, MAX_TRIMEN> trimEnergies;
/** number of channels per chip in one direction */ /** number of channels per chip in one direction */
slsDetectorDefs::xy nChan; slsDetectorDefs::xy nChan;

View File

@ -1,6 +1,6 @@
#include "ClientInterface.h" #include "ClientInterface.h"
#include "FixedCapacityContainer.h"
#include "ServerSocket.h" #include "ServerSocket.h"
#include "StaticVector.h"
#include "ToString.h" #include "ToString.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "string_utils.h" #include "string_utils.h"
@ -335,39 +335,39 @@ int ClientInterface::get_version(Interface &socket) {
int ClientInterface::setup_receiver(Interface &socket) { int ClientInterface::setup_receiver(Interface &socket) {
auto arg = socket.Receive<rxParameters>(); auto arg = socket.Receive<rxParameters>();
LOG(logDEBUG) << "detType:" << arg.detType << std::endl LOG(logDEBUG) << "detType:" << arg.detType << std::endl
<< "multiSize.x:" << arg.multiSize.x << std::endl << "multiSize.x:" << arg.multiSize.x << std::endl
<< "multiSize.y:" << arg.multiSize.y << std::endl << "multiSize.y:" << arg.multiSize.y << std::endl
<< "detId:" << arg.detId << std::endl << "detId:" << arg.detId << std::endl
<< "hostname:" << arg.hostname << std::endl << "hostname:" << arg.hostname << std::endl
<< "udpInterfaces:" << arg.udpInterfaces << std::endl << "udpInterfaces:" << arg.udpInterfaces << std::endl
<< "udp_dstport:" << arg.udp_dstport << std::endl << "udp_dstport:" << arg.udp_dstport << std::endl
<< "udp_dstip:" << sls::IpAddr(arg.udp_dstip) << std::endl << "udp_dstip:" << sls::IpAddr(arg.udp_dstip) << std::endl
<< "udp_dstmac:" << sls::MacAddr(arg.udp_dstmac) << std::endl << "udp_dstmac:" << sls::MacAddr(arg.udp_dstmac) << std::endl
<< "udp_dstport2:" << arg.udp_dstport2 << std::endl << "udp_dstport2:" << arg.udp_dstport2 << std::endl
<< "udp_dstip2:" << sls::IpAddr(arg.udp_dstip2) << std::endl << "udp_dstip2:" << sls::IpAddr(arg.udp_dstip2) << std::endl
<< "udp_dstmac2:" << sls::MacAddr(arg.udp_dstmac2) << "udp_dstmac2:" << sls::MacAddr(arg.udp_dstmac2)
<< std::endl << std::endl
<< "frames:" << arg.frames << std::endl << "frames:" << arg.frames << std::endl
<< "triggers:" << arg.triggers << std::endl << "triggers:" << arg.triggers << std::endl
<< "bursts:" << arg.bursts << std::endl << "bursts:" << arg.bursts << std::endl
<< "analogSamples:" << arg.analogSamples << std::endl << "analogSamples:" << arg.analogSamples << std::endl
<< "digitalSamples:" << arg.digitalSamples << std::endl << "digitalSamples:" << arg.digitalSamples << std::endl
<< "expTimeNs:" << arg.expTimeNs << std::endl << "expTimeNs:" << arg.expTimeNs << std::endl
<< "periodNs:" << arg.periodNs << std::endl << "periodNs:" << arg.periodNs << std::endl
<< "subExpTimeNs:" << arg.subExpTimeNs << std::endl << "subExpTimeNs:" << arg.subExpTimeNs << std::endl
<< "subDeadTimeNs:" << arg.subDeadTimeNs << std::endl << "subDeadTimeNs:" << arg.subDeadTimeNs << std::endl
<< "activate:" << arg.activate << std::endl << "activate:" << arg.activate << std::endl
<< "quad:" << arg.quad << std::endl << "quad:" << arg.quad << std::endl
<< "dynamicRange:" << arg.dynamicRange << std::endl << "dynamicRange:" << arg.dynamicRange << std::endl
<< "timMode:" << arg.timMode << std::endl << "timMode:" << arg.timMode << std::endl
<< "tenGiga:" << arg.tenGiga << std::endl << "tenGiga:" << arg.tenGiga << std::endl
<< "roMode:" << arg.roMode << std::endl << "roMode:" << arg.roMode << std::endl
<< "adcMask:" << arg.adcMask << std::endl << "adcMask:" << arg.adcMask << std::endl
<< "adc10gMask:" << arg.adc10gMask << std::endl << "adc10gMask:" << arg.adc10gMask << std::endl
<< "roi.xmin:" << arg.roi.xmin << std::endl << "roi.xmin:" << arg.roi.xmin << std::endl
<< "roi.xmax:" << arg.roi.xmax << std::endl << "roi.xmax:" << arg.roi.xmax << std::endl
<< "countermask:" << arg.countermask << std::endl << "countermask:" << arg.countermask << std::endl
<< "burstType:" << arg.burstType << std::endl; << "burstType:" << arg.burstType << std::endl;
// if object exists, verify unlocked and idle, else only verify lock // if object exists, verify unlocked and idle, else only verify lock
// (connecting first time) // (connecting first time)
@ -388,15 +388,15 @@ int ClientInterface::setup_receiver(Interface &socket) {
// update retvals only if detmac is not the same as in detector // update retvals only if detmac is not the same as in detector
sls::MacAddr retvals[2]; sls::MacAddr retvals[2];
if (arg.udp_dstip != 0) { if (arg.udp_dstip != 0) {
sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip)); sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip));
sls::MacAddr detMac{arg.udp_dstmac}; sls::MacAddr detMac{arg.udp_dstmac};
if (detMac != r) { if (detMac != r) {
retvals[0] = r; retvals[0] = r;
} }
} }
if (arg.udp_dstip2 != 0) { if (arg.udp_dstip2 != 0) {
sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2)); sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2));
sls::MacAddr detMac{arg.udp_dstmac2}; sls::MacAddr detMac{arg.udp_dstmac2};
if (detMac != r) { if (detMac != r) {
retvals[1] = r; retvals[1] = r;
} }
@ -1399,7 +1399,7 @@ int ClientInterface::set_adc_mask(Interface &socket) {
} }
int ClientInterface::set_dbit_list(Interface &socket) { int ClientInterface::set_dbit_list(Interface &socket) {
sls::FixedCapacityContainer<int, MAX_RX_DBIT> args; sls::StaticVector<int, MAX_RX_DBIT> args;
socket.Receive(args); socket.Receive(args);
if (myDetectorType != CHIPTESTBOARD) if (myDetectorType != CHIPTESTBOARD)
functionNotImplemented(); functionNotImplemented();
@ -1416,7 +1416,7 @@ int ClientInterface::set_dbit_list(Interface &socket) {
int ClientInterface::get_dbit_list(Interface &socket) { int ClientInterface::get_dbit_list(Interface &socket) {
if (myDetectorType != CHIPTESTBOARD) if (myDetectorType != CHIPTESTBOARD)
functionNotImplemented(); functionNotImplemented();
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval; sls::StaticVector<int, MAX_RX_DBIT> retval;
retval = impl()->getDbitList(); retval = impl()->getDbitList();
LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); LOG(logDEBUG1) << "Dbit list size retval:" << retval.size();
return socket.sendResult(retval); return socket.sendResult(retval);

View File

@ -28,7 +28,7 @@ set(PUBLICHEADERS
include/ServerSocket.h include/ServerSocket.h
include/ServerInterface.h include/ServerInterface.h
include/network_utils.h include/network_utils.h
include/FixedCapacityContainer.h include/StaticVector.h
include/ToString.h include/ToString.h
include/TimeHelper.h include/TimeHelper.h
include/TypeTraits.h include/TypeTraits.h

View File

@ -7,7 +7,7 @@
#include <vector> #include <vector>
namespace sls { namespace sls {
template <typename T, size_t Capacity> class FixedCapacityContainer { template <typename T, size_t Capacity> class StaticVector {
public: public:
using size_type = typename std::array<T, Capacity>::size_type; using size_type = typename std::array<T, Capacity>::size_type;
@ -20,10 +20,9 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
std::array<T, Capacity> data_; std::array<T, Capacity> data_;
public: public:
FixedCapacityContainer() = default; StaticVector() = default;
explicit FixedCapacityContainer(std::initializer_list<T> l) explicit StaticVector(std::initializer_list<T> l) : current_size(l.size()) {
: current_size(l.size()) {
size_check(l.size()); size_check(l.size());
std::copy(l.begin(), l.end(), data_.begin()); std::copy(l.begin(), l.end(), data_.begin());
} }
@ -33,15 +32,14 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
typename = typename std::enable_if< typename = typename std::enable_if<
is_container<V>::value && is_container<V>::value &&
std::is_same<T, typename V::value_type>::value>::type> std::is_same<T, typename V::value_type>::value>::type>
FixedCapacityContainer(const V &v) : current_size(v.size()) { StaticVector(const V &v) : current_size(v.size()) {
size_check(v.size()); size_check(v.size());
std::copy(v.begin(), v.end(), data_.begin()); std::copy(v.begin(), v.end(), data_.begin());
} }
/** copy assignment from another container */ /** copy assignment from another container */
template <typename V> template <typename V>
typename std::enable_if<is_container<V>::value, typename std::enable_if<is_container<V>::value, StaticVector &>::type
FixedCapacityContainer &>::type
operator=(const V &other) { operator=(const V &other) {
size_check(other.size()); size_check(other.size());
std::copy(other.begin(), other.end(), data_.begin()); std::copy(other.begin(), other.end(), data_.begin());
@ -49,7 +47,7 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
return *this; return *this;
} }
/** Compare FixedCapacityContainer with any other container*/ /** Compare StaticVector with any other container*/
// template <typename V> // template <typename V>
// typename std::enable_if<is_container<V>::value, bool>::type // typename std::enable_if<is_container<V>::value, bool>::type
// operator==(const V &other) const noexcept { // operator==(const V &other) const noexcept {
@ -143,66 +141,66 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
} __attribute__((packed)); } __attribute__((packed));
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs> template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator==(const StaticVector<T, CapacityLhs> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return lhs.is_equal(rhs); return lhs.is_equal(rhs);
} }
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs> template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return !(lhs.is_equal(rhs)); return !(lhs.is_equal(rhs));
} }
// Compare with array // Compare with array
template <typename T, size_t CapacityLhs, typename V, size_t Size> template <typename T, size_t CapacityLhs, typename V, size_t Size>
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator==(const StaticVector<T, CapacityLhs> &lhs,
const std::array<V, Size> &rhs) { const std::array<V, Size> &rhs) {
return lhs.is_equal(rhs); return lhs.is_equal(rhs);
} }
template <typename T, size_t Size, typename V, size_t CapacityRhs> template <typename T, size_t Size, typename V, size_t CapacityRhs>
bool operator==(const std::array<T, Size> &lhs, bool operator==(const std::array<T, Size> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return rhs.is_equal(lhs); return rhs.is_equal(lhs);
} }
template <typename T, size_t CapacityLhs, typename V, size_t Size> template <typename T, size_t CapacityLhs, typename V, size_t Size>
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
const std::array<V, Size> &rhs) { const std::array<V, Size> &rhs) {
return !lhs.is_equal(rhs); return !lhs.is_equal(rhs);
} }
template <typename T, size_t Size, typename V, size_t CapacityRhs> template <typename T, size_t Size, typename V, size_t CapacityRhs>
bool operator!=(const std::array<T, Size> &lhs, bool operator!=(const std::array<T, Size> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return !rhs.is_equal(lhs); return !rhs.is_equal(lhs);
} }
// Compare with vector // Compare with vector
template <typename T, size_t CapacityLhs, typename V> template <typename T, size_t CapacityLhs, typename V>
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator==(const StaticVector<T, CapacityLhs> &lhs,
const std::vector<V> &rhs) { const std::vector<V> &rhs) {
return lhs.is_equal(rhs); return lhs.is_equal(rhs);
} }
template <typename T, typename V, size_t CapacityRhs> template <typename T, typename V, size_t CapacityRhs>
bool operator==(const std::vector<T> &lhs, bool operator==(const std::vector<T> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return rhs.is_equal(lhs); return rhs.is_equal(lhs);
} }
template <typename T, size_t CapacityLhs, typename V> template <typename T, size_t CapacityLhs, typename V>
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs, bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
const std::vector<V> &rhs) { const std::vector<V> &rhs) {
return !lhs.is_equal(rhs); return !lhs.is_equal(rhs);
} }
template <typename T, typename V, size_t CapacityRhs> template <typename T, typename V, size_t CapacityRhs>
bool operator!=(const std::vector<T> &lhs, bool operator!=(const std::vector<T> &lhs,
const FixedCapacityContainer<V, CapacityRhs> &rhs) { const StaticVector<V, CapacityRhs> &rhs) {
return !rhs.is_equal(lhs); return !rhs.is_equal(lhs);
} }
@ -210,7 +208,7 @@ bool operator!=(const std::vector<T> &lhs,
// template <typename T, size_t Capacity, typename C> // template <typename T, size_t Capacity, typename C>
// typename std::enable_if<is_container<C>::value, bool>::type operator==( // typename std::enable_if<is_container<C>::value, bool>::type operator==(
// const C &container, // const C &container,
// const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept { // const StaticVector<T, Capacity> &fixed_container) noexcept {
// return fixed_container.operator==(container); // return fixed_container.operator==(container);
// } // }
@ -218,7 +216,7 @@ bool operator!=(const std::vector<T> &lhs,
// template <typename T, size_t Capacity, typename C> // template <typename T, size_t Capacity, typename C>
// typename std::enable_if<is_container<C>::value, bool>::type operator!=( // typename std::enable_if<is_container<C>::value, bool>::type operator!=(
// const C &container, // const C &container,
// const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept { // const StaticVector<T, Capacity> &fixed_container) noexcept {
// return fixed_container.operator!=(container); // return fixed_container.operator!=(container);
// } // }

View File

@ -7,7 +7,7 @@
* *
*/ */
#include "FixedCapacityContainer.h" #include "StaticVector.h"
#include "TimeHelper.h" #include "TimeHelper.h"
#include "TypeTraits.h" #include "TypeTraits.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
@ -42,7 +42,7 @@ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi);
template <typename T, size_t Capacity> template <typename T, size_t Capacity>
std::ostream &operator<<(std::ostream &os, std::ostream &operator<<(std::ostream &os,
const sls::FixedCapacityContainer<T, Capacity> &c) { const sls::StaticVector<T, Capacity> &c) {
return os << ToString(c); return os << ToString(c);
} }

View File

@ -5,7 +5,7 @@ target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-sls_detector_defs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-sls_detector_defs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-Sockets.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Sockets.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-FixedCapacityContainer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-StaticVector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-ToString.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-ToString.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-TypeTraits.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-TypeTraits.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-UdpRxSocket.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-UdpRxSocket.cpp

View File

@ -1,19 +1,19 @@
#include "FixedCapacityContainer.h" #include "StaticVector.h"
#include "TypeTraits.h" #include "TypeTraits.h"
#include "catch.hpp" #include "catch.hpp"
#include <array> #include <array>
#include <vector> #include <vector>
using sls::FixedCapacityContainer; using sls::StaticVector;
TEST_CASE("FixedCapacityContainer is a container") { TEST_CASE("StaticVector is a container") {
REQUIRE(sls::is_container<FixedCapacityContainer<int, 7>>::value == true); REQUIRE(sls::is_container<StaticVector<int, 7>>::value == true);
} }
TEST_CASE("Comparing FixedCapacity containers") { TEST_CASE("Comparing StaticVector containers") {
FixedCapacityContainer<int, 5> a{0, 1, 2}; StaticVector<int, 5> a{0, 1, 2};
FixedCapacityContainer<int, 5> b{0, 1, 2}; StaticVector<int, 5> b{0, 1, 2};
FixedCapacityContainer<int, 5> c{0, 1, 2, 4}; StaticVector<int, 5> c{0, 1, 2, 4};
REQUIRE(a == b); REQUIRE(a == b);
REQUIRE_FALSE(a != b); REQUIRE_FALSE(a != b);
@ -27,7 +27,7 @@ TEST_CASE("Comparing FixedCapacity containers") {
TEST_CASE("Compare array and fixed capacity container") { TEST_CASE("Compare array and fixed capacity container") {
std::array<int, 3> arr{1, 2, 3}; std::array<int, 3> arr{1, 2, 3};
std::array<int, 3> arr2{1, 7, 3}; std::array<int, 3> arr2{1, 7, 3};
FixedCapacityContainer<int, 7> fcc{1, 2, 3}; StaticVector<int, 7> fcc{1, 2, 3};
REQUIRE(fcc == arr); REQUIRE(fcc == arr);
REQUIRE(arr == fcc); REQUIRE(arr == fcc);
REQUIRE_FALSE(fcc != arr); REQUIRE_FALSE(fcc != arr);
@ -39,7 +39,7 @@ TEST_CASE("Compare array and fixed capacity container") {
TEST_CASE("Compare vector and fixed capacity container") { TEST_CASE("Compare vector and fixed capacity container") {
std::vector<int> vec{1, 2, 3}; std::vector<int> vec{1, 2, 3};
std::vector<int> vec2{10, 2, 3}; std::vector<int> vec2{10, 2, 3};
FixedCapacityContainer<int, 7> fcc{1, 2, 3}; StaticVector<int, 7> fcc{1, 2, 3};
REQUIRE(fcc == vec); REQUIRE(fcc == vec);
REQUIRE(vec == fcc); REQUIRE(vec == fcc);
REQUIRE_FALSE(fcc != vec); REQUIRE_FALSE(fcc != vec);
@ -50,51 +50,51 @@ TEST_CASE("Compare vector and fixed capacity container") {
TEST_CASE("Construct from vector") { TEST_CASE("Construct from vector") {
std::vector<int> vec{1, 2, 3}; std::vector<int> vec{1, 2, 3};
FixedCapacityContainer<int, 5> fcc{vec}; StaticVector<int, 5> fcc{vec};
REQUIRE(fcc == vec); REQUIRE(fcc == vec);
} }
TEST_CASE("Copy construct from vector") { TEST_CASE("Copy construct from vector") {
std::vector<int> vec{1, 2, 3}; std::vector<int> vec{1, 2, 3};
FixedCapacityContainer<int, 5> fcc = vec; StaticVector<int, 5> fcc = vec;
REQUIRE(fcc == vec); REQUIRE(fcc == vec);
} }
TEST_CASE("Copy assignment from vector") { TEST_CASE("Copy assignment from vector") {
std::vector<int> vec{1, 2, 3}; std::vector<int> vec{1, 2, 3};
FixedCapacityContainer<int, 5> fcc; StaticVector<int, 5> fcc;
fcc = vec; fcc = vec;
REQUIRE(fcc == vec); REQUIRE(fcc == vec);
} }
TEST_CASE("Construct from array") { TEST_CASE("Construct from array") {
std::array<int, 3> arr{1, 2, 3}; std::array<int, 3> arr{1, 2, 3};
FixedCapacityContainer<int, 5> fcc{arr}; StaticVector<int, 5> fcc{arr};
REQUIRE(fcc == arr); REQUIRE(fcc == arr);
} }
TEST_CASE("Copy assign from array") { TEST_CASE("Copy assign from array") {
std::array<int, 3> arr{1, 2, 3}; std::array<int, 3> arr{1, 2, 3};
FixedCapacityContainer<int, 5> fcc; StaticVector<int, 5> fcc;
fcc = arr; fcc = arr;
REQUIRE(fcc == arr); REQUIRE(fcc == arr);
} }
TEST_CASE("Copy construct from array") { TEST_CASE("Copy construct from array") {
std::array<int, 3> arr{1, 2, 3}; std::array<int, 3> arr{1, 2, 3};
FixedCapacityContainer<int, 5> fcc = arr; StaticVector<int, 5> fcc = arr;
REQUIRE(fcc == arr); REQUIRE(fcc == arr);
} }
TEST_CASE("Free function and method gives the same iterators") { TEST_CASE("Free function and method gives the same iterators") {
FixedCapacityContainer<int, 3> fcc{1, 2, 3}; StaticVector<int, 3> fcc{1, 2, 3};
REQUIRE(std::begin(fcc) == fcc.begin()); REQUIRE(std::begin(fcc) == fcc.begin());
} }
SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { SCENARIO("StaticVectors can be sized and resized", "[support]") {
GIVEN("A default constructed container") { GIVEN("A default constructed container") {
constexpr size_t n_elem = 5; constexpr size_t n_elem = 5;
FixedCapacityContainer<int, n_elem> vec; StaticVector<int, n_elem> vec;
REQUIRE(vec.empty()); REQUIRE(vec.empty());
REQUIRE(vec.size() == 0); // NOLINT REQUIRE(vec.size() == 0); // NOLINT
@ -131,8 +131,8 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
} }
} }
GIVEN("A FixedCapacityContainer constructed form a std::initializer list") { GIVEN("A StaticVector constructed form a std::initializer list") {
FixedCapacityContainer<int, 10> vec{23, 52, 11}; StaticVector<int, 10> vec{23, 52, 11};
REQUIRE(vec.size() == 3); REQUIRE(vec.size() == 3);
REQUIRE(vec.capacity() == 10); REQUIRE(vec.capacity() == 10);
REQUIRE(vec[0] == 23); REQUIRE(vec[0] == 23);
@ -174,7 +174,7 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
GIVEN("An std::vector of size 3") { GIVEN("An std::vector of size 3") {
std::vector<int> standard_vector{5, 2, 1}; std::vector<int> standard_vector{5, 2, 1};
WHEN("we construct a fixed capacity container from it") { WHEN("we construct a fixed capacity container from it") {
FixedCapacityContainer<int, 5> vec(standard_vector); StaticVector<int, 5> vec(standard_vector);
THEN("size and data matches") { THEN("size and data matches") {
REQUIRE(vec.size() == 3); REQUIRE(vec.size() == 3);
REQUIRE(vec[0] == 5); REQUIRE(vec[0] == 5);
@ -188,10 +188,10 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
} }
} }
SCENARIO("Comparison of FixedCapacityContainers", "[support]") { SCENARIO("Comparison of StaticVectors", "[support]") {
GIVEN("Two containers containers that are equal at the start") { GIVEN("Two containers containers that are equal at the start") {
FixedCapacityContainer<int, 5> a{0, 1, 2}; StaticVector<int, 5> a{0, 1, 2};
FixedCapacityContainer<int, 5> b{0, 1, 2}; StaticVector<int, 5> b{0, 1, 2};
REQUIRE(a == b); REQUIRE(a == b);
REQUIRE_FALSE(a != b); REQUIRE_FALSE(a != b);
@ -199,8 +199,8 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") {
a.push_back(4); a.push_back(4);
THEN("they are not equal anymore") { REQUIRE(a != b); } THEN("they are not equal anymore") { REQUIRE(a != b); }
} }
WHEN("Compared to a FixedCapacityContainer with different capacity") { WHEN("Compared to a StaticVector with different capacity") {
FixedCapacityContainer<int, 8> c{0, 1, 2}; StaticVector<int, 8> c{0, 1, 2};
THEN("The comparison still holds") { THEN("The comparison still holds") {
REQUIRE(a == c); REQUIRE(a == c);
REQUIRE_FALSE(a != c); REQUIRE_FALSE(a != c);
@ -232,7 +232,7 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") {
SCENARIO("Sorting, removing and other manipulation of a container", SCENARIO("Sorting, removing and other manipulation of a container",
"[support]") { "[support]") {
GIVEN("An unsorted container") { GIVEN("An unsorted container") {
FixedCapacityContainer<int, 5> a{14, 12, 90, 12}; StaticVector<int, 5> a{14, 12, 90, 12};
WHEN("We sort it") { WHEN("We sort it") {
std::sort(a.begin(), a.end()); std::sort(a.begin(), a.end());
THEN("Elements appear sorted") { THEN("Elements appear sorted") {
@ -264,8 +264,8 @@ SCENARIO("Sorting, removing and other manipulation of a container",
SCENARIO("Assigning containers to each other", "[support]") { SCENARIO("Assigning containers to each other", "[support]") {
GIVEN("Two containers") { GIVEN("Two containers") {
FixedCapacityContainer<int, 3> a{1, 2, 3}; StaticVector<int, 3> a{1, 2, 3};
FixedCapacityContainer<int, 3> b{4, 5, 6}; StaticVector<int, 3> b{4, 5, 6};
WHEN("a is assigned to b") { WHEN("a is assigned to b") {
a = b; a = b;
THEN("A deep copy is made and both containers are equal") { THEN("A deep copy is made and both containers are equal") {
@ -278,7 +278,7 @@ SCENARIO("Assigning containers to each other", "[support]") {
} }
} }
WHEN("A new object is create from an old one") { WHEN("A new object is create from an old one") {
FixedCapacityContainer<int, 3> c(a); StaticVector<int, 3> c(a);
THEN("A deep copy is also made") { THEN("A deep copy is also made") {
REQUIRE(c == a); REQUIRE(c == a);
REQUIRE(&c != &a); REQUIRE(&c != &a);
@ -288,8 +288,8 @@ SCENARIO("Assigning containers to each other", "[support]") {
REQUIRE(c[2] == 3); REQUIRE(c[2] == 3);
} }
} }
WHEN("We create a const FixedCapacityContainer") { WHEN("We create a const StaticVector") {
const FixedCapacityContainer<int, 5> c(a); const StaticVector<int, 5> c(a);
THEN("The values are still the same using const operators") { THEN("The values are still the same using const operators") {
REQUIRE(c[0] == 1); REQUIRE(c[0] == 1);
REQUIRE(c[1] == 2); REQUIRE(c[1] == 2);
@ -302,8 +302,8 @@ SCENARIO("Assigning containers to each other", "[support]") {
} }
SCENARIO("Converting to vector", "[support]") { SCENARIO("Converting to vector", "[support]") {
GIVEN("a FixedCapacityContainer") { GIVEN("a StaticVector") {
FixedCapacityContainer<int, 5> a{1, 2, 3}; StaticVector<int, 5> a{1, 2, 3};
WHEN("Converted into a vector") { WHEN("Converted into a vector") {
std::vector<int> b(a); std::vector<int> b(a);
THEN("Data and size matches") { THEN("Data and size matches") {

View File

@ -232,15 +232,15 @@ TEST_CASE("Streaming of slsDetectorDefs::ROI") {
REQUIRE(oss.str() == "[-10, 1]"); REQUIRE(oss.str() == "[-10, 1]");
} }
TEST_CASE("sls::FixedCapacityContainer") { TEST_CASE("sls::StaticVector") {
sls::FixedCapacityContainer<int, 5> vec; sls::StaticVector<int, 5> vec;
vec.push_back(3); vec.push_back(3);
vec.push_back(8); vec.push_back(8);
REQUIRE(ToString(vec) == "[3, 8]"); REQUIRE(ToString(vec) == "[3, 8]");
} }
TEST_CASE("sls::FixedCapacityContainer stream") { TEST_CASE("sls::StaticVector stream") {
sls::FixedCapacityContainer<int, 5> vec; sls::StaticVector<int, 5> vec;
vec.push_back(33); vec.push_back(33);
vec.push_back(85667); vec.push_back(85667);
vec.push_back(2); vec.push_back(2);