diff --git a/sample/api.cpp b/sample/api.cpp index b16c6f8ff..eff05049a 100644 --- a/sample/api.cpp +++ b/sample/api.cpp @@ -2,43 +2,44 @@ #include #include +#include "TimeHelper.h" +#include "ToString.h" +// std::ostream &operator<<(std::ostream &os, const std::chrono::nanoseconds &t) { +// os << t.count() << "ns"; +// return os; +// } -std::ostream &operator<<(std::ostream &os, const std::chrono::nanoseconds &t) { - os << t.count() << "ns"; - return os; -} +// template +// struct is_container : std::false_type {}; -template -struct is_container : std::false_type {}; +// template struct is_container_helper {}; -template struct is_container_helper {}; +// template +// struct is_container< +// T, typename std::conditional< +// false, +// is_container_helper().size()), +// decltype(std::declval().begin()), +// decltype(std::declval().end()), +// decltype(std::declval().cbegin()), +// decltype(std::declval().cend()), +// decltype(std::declval().empty())>, +// void>::type> : public std::true_type {}; -template -struct is_container< - T, typename std::conditional< - false, - is_container_helper().size()), - decltype(std::declval().begin()), - decltype(std::declval().end()), - decltype(std::declval().cbegin()), - decltype(std::declval().cend()), - decltype(std::declval().empty())>, - void>::type> : public std::true_type {}; - -template -auto operator<<(std::ostream &os, const Container &con) -> - typename std::enable_if::value, - std::ostream &>::type { - if (con.empty()) - return os << "[]"; - auto it = con.cbegin(); - os << '[' << *it++; - while (it != con.cend()) - os << ", " << *it++; - return os << ']'; -} +// template +// auto operator<<(std::ostream &os, const Container &con) -> +// typename std::enable_if::value, +// std::ostream &>::type { +// if (con.empty()) +// return os << "[]"; +// auto it = con.cbegin(); +// os << '[' << *it++; +// while (it != con.cend()) +// os << ", " << *it++; +// return os << ']'; +// } using sls::Detector; using std::chrono::nanoseconds; @@ -57,7 +58,7 @@ int main() { // std::cout << "exptime: " < #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..ea9b810d8 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,38 @@ template > class Result { Result() = default; Result(std::initializer_list list) : vec(list){}; + + /** Custom constructor from integer type to Result */ + 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)); + } + + /** Custom constructor from integer type to Result */ + 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)); + } + + /** Custom constructor from integer type to Result */ + 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 +115,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 b4407d646..d2922325a 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -51,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 { @@ -69,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) { @@ -80,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) {