diff --git a/sample/useResult.cpp b/sample/useResult.cpp index e48d94fde..08de0b04f 100644 --- a/sample/useResult.cpp +++ b/sample/useResult.cpp @@ -1,6 +1,7 @@ -#include #include "Result.h" #include "ToString.h" +#include +#include auto main() -> int { @@ -31,25 +32,19 @@ auto main() -> int { std::cout << "vec2: " << ToString(vec2) << "\n"; - // WARNING this feature is still not decied, its convenient - // but might turn out to be a source of bugs... - // it is also possible to convert from Result to T - int r = res3; - std::cout << "r: " << r << '\n'; - std::cout << "static_cast: " << static_cast(res3) << '\n'; - std::cout << "static_cast: " << static_cast(res3) << '\n'; - - int r2 = res; - std::cout << "res: " << res << " converted to int: " << r2 << "\n"; - - //Using squash we can also convert to a single value + // Using squash we can also convert to a single value std::cout << "res.squash(): " << res.squash() << '\n'; std::cout << "res3.squash(): " << res3.squash() << '\n'; - //.squash also takes a default value std::cout << "res.squash(-1): " << res.squash(-1) << '\n'; std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n'; + std::vector ivec{1, 3, 5}; + + Result nres(ivec); + // for (const auto& i : ivec) + // nres.push_back(sls::time::ns(i)); + std::cout << "nres: " << sls::ToString(nres) << '\n'; // } \ No newline at end of file diff --git a/slsDetectorSoftware/include/Result.h b/slsDetectorSoftware/include/Result.h index e4869c2f2..c3361c330 100644 --- a/slsDetectorSoftware/include/Result.h +++ b/slsDetectorSoftware/include/Result.h @@ -13,6 +13,7 @@ #include #include +#include "TimeHelper.h" #include "ToString.h" #include "container_utils.h" @@ -30,6 +31,34 @@ template > class Result { Result() = default; Result(std::initializer_list list) : vec(list){}; + template ::value && + std::is_same::value>::type> + Result(const std::vector &from) { + + vec.reserve(from.size()); + for (const auto &item : from) + vec.push_back(T(item)); + } + + template ::value && + std::is_same::value>::type> + Result(std::vector &from) { + vec.reserve(from.size()); + for (const auto &item : from) + vec.push_back(T(item)); + } + + template ::value && + std::is_same::value>::type> + Result(std::vector &&from) { + vec.reserve(from.size()); + for (const auto &item : from) + vec.push_back(T(item)); + } + /** * Forward arguments to the constructor of std::vector * @tparam Args template paramter pack to forward @@ -82,9 +111,6 @@ template > class Result { /** Convert Result to std::vector */ operator std::vector() { return vec; } - - /** Convert Result to T using squash() */ - operator T() { return squash(); } }; /** diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index fe7f12b81..0a1b91714 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -11,7 +11,6 @@ Detector::Detector(int multi_id) : pimpl(sls::make_unique(multi_id)) {} Detector::~Detector() = default; - // Acquisition void Detector::acquire() { pimpl->acquire(); } @@ -26,13 +25,9 @@ Result Detector::getReceiverStatus(Positions pos) { return pimpl->Parallel(&slsDetector::getReceiverStatus, pos); } -bool Detector::getAcquiringFlag() const{ - return pimpl->getAcquiringFlag(); -} +bool Detector::getAcquiringFlag() const { return pimpl->getAcquiringFlag(); } -void Detector::setAcquiringFlag(bool value){ - pimpl->setAcquiringFlag(value); -} +void Detector::setAcquiringFlag(bool value) { pimpl->setAcquiringFlag(value); } // Configuration Result Detector::getHostname(Positions pos) const { @@ -41,7 +36,6 @@ Result Detector::getHostname(Positions pos) const { void Detector::freeSharedMemory() { pimpl->freeSharedMemory(); } - void Detector::setConfig(const std::string &fname) { pimpl->readConfigurationFile(fname); } @@ -57,9 +51,8 @@ Result Detector::getRegister(uint32_t addr, Positions pos) { } Result Detector::getExptime(Positions pos) const { - auto r = pimpl->Parallel(&slsDetector::setTimer, pos, - defs::ACQUISITION_TIME, -1); - return Result(begin(r), end(r)); + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::ACQUISITION_TIME, + -1); } Result Detector::getStartingFrameNumber(Positions pos) const { @@ -75,9 +68,8 @@ void Detector::setExptime(ns t, Positions pos) { } Result Detector::getSubExptime(Positions pos) const { - auto r = pimpl->Parallel(&slsDetector::setTimer, pos, - defs::SUBFRAME_ACQUISITION_TIME, -1); - return Result(begin(r), end(r)); + return pimpl->Parallel(&slsDetector::setTimer, pos, + defs::SUBFRAME_ACQUISITION_TIME, -1); } void Detector::setSubExptime(ns t, Positions pos) { @@ -86,9 +78,7 @@ void Detector::setSubExptime(ns t, Positions pos) { } Result Detector::getPeriod(Positions pos) const { - auto r = - pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1); - return Result(begin(r), end(r)); + return pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1); } void Detector::setPeriod(ns t, Positions pos) {