new folder structure

This commit is contained in:
Erik Frojdh
2024-03-07 15:48:06 +01:00
parent 52865930c2
commit ef61e62238
34 changed files with 126 additions and 103 deletions

23
core/src/Frame.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "aare/Frame.hpp"
#include <iostream>
template <typename DataType>
Frame<DataType>::Frame(std::byte* bytes, ssize_t rows, ssize_t cols):
rows(rows), cols(cols) {
data = new DataType[rows*cols];
std::memcpy(data, bytes, rows*cols*sizeof(DataType));
}
template <typename DataType>
DataType Frame<DataType>::get(int row, int col) {
if (row < 0 || row >= rows || col < 0 || col >= cols) {
std::cerr << "Invalid row or column index" << std::endl;
return 0;
}
return data[row*cols + col];
}
template class Frame<uint16_t>;

45
core/src/defs.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "aare/defs.hpp"
template <> std::string toString(DetectorType type) {
switch (type) {
case DetectorType::Jungfrau:
return "Jungfrau";
case DetectorType::Eiger:
return "Eiger";
case DetectorType::Mythen3:
return "Mythen3";
case DetectorType::Moench:
return "Moench";
default:
return "Unknown";
}
}
template <> DetectorType StringTo(std::string name) {
if (name == "Jungfrau")
return DetectorType::Jungfrau;
else if (name == "Eiger")
return DetectorType::Eiger;
else if (name == "Mythen3")
return DetectorType::Mythen3;
else if (name == "Moench")
return DetectorType::Moench;
else {
auto msg = fmt::format("Could not decode dector from: \"{}\"", name);
throw std::runtime_error(msg);
}
}
template <> TimingMode StringTo(std::string mode){
if (mode == "auto")
return TimingMode::Auto;
else if(mode == "trigger")
return TimingMode::Trigger;
else{
auto msg = fmt::format("Could not decode timing mode from: \"{}\"", mode);
throw std::runtime_error(msg);
}
}
// template <> TimingMode StringTo<TimingMode>(std::string mode);

8
core/src/defs.test.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <catch2/catch_test_macros.hpp>
#include <string>
#include "aare/defs.hpp"
TEST_CASE("Enum to string conversion"){
//By the way I don't think the enum string conversions should be in the defs.hpp file
//but let's use this to show a test
REQUIRE(toString(DetectorType::Jungfrau) == "Jungfrau");
}