mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 05:08:06 +01:00
removed pointers added constructor
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#endif
|
||||
@@ -1043,22 +1044,47 @@ typedef struct {
|
||||
sls_detector_module()
|
||||
: serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0),
|
||||
tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {}
|
||||
|
||||
sls_detector_module(slsDetectorDefs::detectorType type) {
|
||||
detParameters parameters{type};
|
||||
int nch = parameters.nChanX * parameters.nChanY;
|
||||
int nc = parameters.nChipX * parameters.nChipY;
|
||||
int nd = parameters.nDacs;
|
||||
// int nd = parameters.nDacs;
|
||||
|
||||
ndac = nd;
|
||||
ndac = parameters.nDacs;
|
||||
nchip = nc;
|
||||
nchan = nch * nc;
|
||||
dacs = new int[nd];
|
||||
chanregs = new int[nch * nc];
|
||||
dacs = new int[ndac];
|
||||
chanregs = new int[nchan];
|
||||
}
|
||||
|
||||
sls_detector_module(const sls_detector_module &other)
|
||||
: dacs(nullptr), chanregs(nullptr) {
|
||||
*this = other;
|
||||
}
|
||||
|
||||
sls_detector_module &operator=(const sls_detector_module &other) {
|
||||
delete[] dacs;
|
||||
delete[] chanregs;
|
||||
serialnumber = other.serialnumber;
|
||||
nchan = other.nchan;
|
||||
nchip = other.nchip;
|
||||
ndac = other.ndac;
|
||||
reg = other.reg;
|
||||
iodelay = other.iodelay;
|
||||
tau = other.tau;
|
||||
eV = other.eV;
|
||||
dacs = new int[ndac];
|
||||
std::copy(other.dacs, other.dacs + ndac, dacs);
|
||||
chanregs = new int[nchan];
|
||||
std::copy(other.chanregs, other.chanregs + nchan, chanregs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~sls_detector_module() {
|
||||
delete[] dacs;
|
||||
delete[] chanregs;
|
||||
}
|
||||
~sls_detector_module(){
|
||||
delete[] dacs;
|
||||
delete[] chanregs;
|
||||
}
|
||||
};
|
||||
#else
|
||||
} sls_detector_module;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "catch.hpp"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetector.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
using dt = slsDetectorDefs::detectorType;
|
||||
|
||||
@@ -18,10 +18,10 @@ TEST_CASE("sls_detector_module default construction", "[support][new]") {
|
||||
CHECK(m.chanregs == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("sls_detector_module from type", "[support][new]") {
|
||||
TEST_CASE("sls_detector_module from type", "[support]") {
|
||||
sls_detector_module m(dt::EIGER);
|
||||
CHECK(m.serialnumber == 0);
|
||||
CHECK(m.nchan == 256*256*4);
|
||||
CHECK(m.nchan == 256 * 256 * 4);
|
||||
CHECK(m.nchip == 4);
|
||||
CHECK(m.ndac == 16);
|
||||
CHECK(m.reg == 0);
|
||||
@@ -30,4 +30,24 @@ TEST_CASE("sls_detector_module from type", "[support][new]") {
|
||||
CHECK(m.eV == 0);
|
||||
CHECK(m.dacs != nullptr);
|
||||
CHECK(m.chanregs != nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("assign module", "[support]") {
|
||||
sls_detector_module m0;
|
||||
sls_detector_module m1(dt::EIGER);
|
||||
m1.serialnumber = 14;
|
||||
m1.reg = 500;
|
||||
m1.iodelay = 750;
|
||||
|
||||
m0 = m1; // Assignment operator
|
||||
CHECK(m0.serialnumber == 14);
|
||||
CHECK(m0.reg == 500);
|
||||
CHECK(m0.iodelay == 750);
|
||||
CHECK(m0.nchan == 256 * 256 * 4);
|
||||
|
||||
auto m3 = m1; // Copy constructor
|
||||
CHECK(m3.serialnumber == 14);
|
||||
CHECK(m3.reg == 500);
|
||||
CHECK(m3.iodelay == 750);
|
||||
CHECK(m3.nchan == 256 * 256 * 4);
|
||||
}
|
||||
Reference in New Issue
Block a user