This commit is contained in:
Erik Frojdh
2020-05-11 18:28:06 +02:00
parent 1ed1b5da86
commit eff664e790
4 changed files with 125 additions and 367 deletions

View File

@ -12,6 +12,7 @@
#include "sls_detector_defs.h"
#include "sls_detector_exceptions.h"
#include "string_utils.h"
#include "FixedCapacityContainer.h"
#include <chrono>
#include <iomanip>
#include <map>
@ -36,6 +37,14 @@ std::string ToString(const defs::detectorModeType s);
std::string ToString(const defs::burstMode s);
std::string ToString(const defs::timingSourceType s);
std::string ToString(const slsDetectorDefs::ROI &roi);
std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi);
template<typename T, size_t Capacity>
std::ostream &operator<<(std::ostream &os, const sls::FixedCapacityContainer<T, Capacity>& c){
return os << ToString(c);
}
const std::string &ToString(const std::string &s);
/** Convert std::chrono::duration with specified output unit */

View File

@ -2,6 +2,16 @@
namespace sls {
std::string ToString(const slsDetectorDefs::ROI& roi){
std::ostringstream oss;
oss << '[' << roi.xmin << ", " << roi.xmax << ']';
return oss.str();
}
std::ostream&operator<<(std::ostream &os, const slsDetectorDefs::ROI& roi){
return os << ToString(roi);
}
std::string ToString(const defs::runStatus s) {
switch (s) {
case defs::ERROR:

View File

@ -6,6 +6,7 @@
#include <array>
#include <map>
#include <vector>
#include <sstream>
// using namespace sls;
using sls::defs;
@ -216,4 +217,35 @@ TEST_CASE("Detector type") {
auto dt = defs::detectorType::EIGER;
REQUIRE(ToString(dt) == "Eiger");
REQUIRE(StringTo<defs::detectorType>("Eiger") == dt);
}
TEST_CASE("Formatting slsDetectorDefs::ROI"){
slsDetectorDefs::ROI roi{5,159};
REQUIRE(ToString(roi) == "[5, 159]");
}
TEST_CASE("Streaming of slsDetectorDefs::ROI"){
using namespace sls;
slsDetectorDefs::ROI roi{-10,1};
std::ostringstream oss;
oss << roi;
REQUIRE(oss.str() == "[-10, 1]");
}
TEST_CASE("sls::FixedCapacityContainer"){
sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(3);
vec.push_back(8);
REQUIRE(ToString(vec) == "[3, 8]");
}
TEST_CASE("sls::FixedCapacityContainer stream"){
sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(33);
vec.push_back(85667);
vec.push_back(2);
std::ostringstream oss;
oss << vec;
REQUIRE(oss.str() == "[33, 85667, 2]");
}