diff --git a/README.md b/README.md index 308c2391..8dc10c71 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,3 @@ Versatile DAQ engine for physics detectors, event mode and otherwise, with a var ## The future You can see current tickets and their priorities on the [Kanban board](https://github.com/ess-dmsc/daquiri/projects/1) - -Please send any feature requests you have to (martin.shetty@esss.se). diff --git a/cmake/QtLibraryConfig.cmake b/cmake/QtLibraryConfig.cmake index 521b09c9..bbfc3244 100644 --- a/cmake/QtLibraryConfig.cmake +++ b/cmake/QtLibraryConfig.cmake @@ -9,3 +9,5 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) find_package(Qt5 COMPONENTS Widgets PrintSupport Network Test REQUIRED) +message(STATUS "Detected QT version = ${Qt5Widgets_VERSION_STRING}") + diff --git a/documentation/installation.md b/documentation/installation.md index 7c4a6f53..b0e00156 100644 --- a/documentation/installation.md +++ b/documentation/installation.md @@ -1,7 +1,7 @@ ## Requirements Supported (continuously tested) platforms: -- Ubuntu 18.04 +- Ubuntu 20.04 - macOS Catalina - Centos 7 diff --git a/documentation/manual_building.md b/documentation/manual_building.md index 52009f9c..ea4c373b 100644 --- a/documentation/manual_building.md +++ b/documentation/manual_building.md @@ -5,7 +5,7 @@ In case you want to do everything manually, here are some of the gory details. ## Requirements Supported platforms: -- Ubuntu 18.04 +- Ubuntu 20.04 - macOS High Sierra - Centos 7 @@ -14,20 +14,18 @@ You definitely need these: - recent C++ compiler - CMake 3.0 - Qt5 -- conan 1.0 (via pip) +- conan (via pip) ## Conan setup -To avoid C++ dependency hell, we use `conan`. The following repos need to be added: -``` -conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan -conan remote add ecdc https://artifactoryconan.esss.dk/artifactory/api/conan/ecdc -``` -If you are on a `linux` sytem you also need to ensure that `conan` builds everything using the c++11 standard. Edit your `~/.conan/profiles/default` to replace `compiler.libcxx=libstdc++` with `compiler.libcxx=libstdc++11`. -If said file does not exists, you are likely yet to run `conan` for the first time. Do the following to generate the above-mentioned file: -``` +To avoid C++ dependency hell, we use `conan`. After you install it, run: + +```bash conan profile new --detect default +conan profile update settings.compiler.libcxx=libstdc++11 default ``` +For the most up-to-date remotes, see the standard `ESS` configuration for conan in [this repository](https://github.com/ess-dmsc/conan-configuration) + ## Installation of Qt There is currently no fully portable conan package of Qt so it should be installed in @@ -35,7 +33,7 @@ a platform-specific way. For each platform it's the following: - Ubuntu: `qt5-default` package from apt - Centos: `qt5-qtbase-devel` package from yum -- macOS: whatever default qt package from brew +- macOS: whatever default qt5 package from brew It is easiest if you have Qt installed via brew or apt. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 3b588894..e6cf41a5 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -4,7 +4,7 @@ include(BuildInfo) find_package(date REQUIRED) find_package(spdlog REQUIRED) find_package(fmt REQUIRED) -find_package(h5cpp 0.4.0 REQUIRED) +find_package(h5cpp 0.4.1 REQUIRED) find_package(Threads REQUIRED) add_subdirectory(core) diff --git a/source/consumers/Histogram2D.cpp b/source/consumers/Histogram2D.cpp index a2ca68dc..ede99ac0 100644 --- a/source/consumers/Histogram2D.cpp +++ b/source/consumers/Histogram2D.cpp @@ -21,10 +21,10 @@ Histogram2D::Histogram2D() SettingMeta app("appearance", SettingType::text, "Appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); - base_options.branches.add(flip); + base_options.branches.add(Setting(flip)); base_options.branches.add_a(value_latch_x_.settings(0, "X value")); base_options.branches.add_a(value_latch_y_.settings(1, "Y value")); diff --git a/source/consumers/Image2D.cpp b/source/consumers/Image2D.cpp index 39dea486..93fec4d7 100644 --- a/source/consumers/Image2D.cpp +++ b/source/consumers/Image2D.cpp @@ -19,10 +19,10 @@ Image2D::Image2D() SettingMeta app("appearance", SettingType::text, "Appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); - base_options.branches.add(flip); + base_options.branches.add(Setting(flip)); base_options.branches.add_a(value_latch_x_.settings(0, "X value")); base_options.branches.add_a(value_latch_y_.settings(1, "Y value")); diff --git a/source/consumers/Prebinned1D.cpp b/source/consumers/Prebinned1D.cpp index 10802b09..b46bf8df 100644 --- a/source/consumers/Prebinned1D.cpp +++ b/source/consumers/Prebinned1D.cpp @@ -16,20 +16,20 @@ Prebinned1D::Prebinned1D() SettingMeta app("appearance", SettingType::text, "Appearance"); app.set_flag("color"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta val_name("trace_id", SettingType::text); val_name.set_flag("preset"); val_name.set_flag("event_trace"); val_name.set_val("description", "Name of event trace to bin"); - base_options.branches.add(val_name); + base_options.branches.add(Setting(val_name)); SettingMeta mds("downsample", SettingType::integer, "Downsample by"); mds.set_val("units", "bits"); mds.set_flag("preset"); mds.set_val("min", 0); mds.set_val("max", 31); - base_options.branches.add(mds); + base_options.branches.add(Setting(mds)); metadata_.overwrite_all_attributes(base_options); } diff --git a/source/consumers/Spectrum.cpp b/source/consumers/Spectrum.cpp index d67c486d..14d0273d 100644 --- a/source/consumers/Spectrum.cpp +++ b/source/consumers/Spectrum.cpp @@ -10,40 +10,40 @@ Spectrum::Spectrum() Setting base_options = metadata_.attributes(); SettingMeta name("name", SettingType::text, "Name"); - base_options.branches.add(name); + base_options.branches.add(Setting(name)); SettingMeta altaxisname("alt_axis_name", SettingType::text, "Axis alias"); - base_options.branches.add(altaxisname); + base_options.branches.add(Setting(altaxisname)); SettingMeta vis("visible", SettingType::boolean, "Visible"); - base_options.branches.add(vis); + base_options.branches.add(Setting(vis)); SettingMeta grp("window_group", SettingType::integer, "Window group"); grp.set_val("min", 0); grp.set_val("max", 100); - base_options.branches.add(grp); + base_options.branches.add(Setting(grp)); SettingMeta sca("preferred_scale", SettingType::menu, "Plot scale for counts"); sca.set_enum(0, "Linear"); sca.set_enum(1, "Logarithmic"); - base_options.branches.add(sca); + base_options.branches.add(Setting(sca)); SettingMeta totalcount("total_count", SettingType::precise, "Total count"); totalcount.set_flag("readonly"); totalcount.set_val("min", 0); - base_options.branches.add(totalcount); + base_options.branches.add(Setting(totalcount)); SettingMeta start_time("start_time", SettingType::time, "Start time"); start_time.set_flag("readonly"); - base_options.branches.add(start_time); + base_options.branches.add(Setting(start_time)); SettingMeta live_time("live_time", SettingType::duration, "Live time"); live_time.set_flag("readonly"); - base_options.branches.add(live_time); + base_options.branches.add(Setting(live_time)); SettingMeta real_time("real_time", SettingType::duration, "Real time"); real_time.set_flag("readonly"); - base_options.branches.add(real_time); + base_options.branches.add(Setting(real_time)); base_options.branches.add(recent_rate_.update(Status(), 0)); diff --git a/source/consumers/StatsScalar.cpp b/source/consumers/StatsScalar.cpp index 38b173af..99fbfe38 100644 --- a/source/consumers/StatsScalar.cpp +++ b/source/consumers/StatsScalar.cpp @@ -16,7 +16,7 @@ StatsScalar::StatsScalar() SettingMeta app("appearance", SettingType::text, "Appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta stat("what_stats", SettingType::text, "Stat of choice"); stat.set_flag("stat_value"); diff --git a/source/consumers/TOF1D.cpp b/source/consumers/TOF1D.cpp index 92914d2f..dedcf2c2 100644 --- a/source/consumers/TOF1D.cpp +++ b/source/consumers/TOF1D.cpp @@ -22,7 +22,7 @@ TOF1D::TOF1D() res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -30,7 +30,7 @@ TOF1D::TOF1D() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); metadata_.overwrite_all_attributes(base_options); } diff --git a/source/consumers/TOF1DCorrelate.cpp b/source/consumers/TOF1DCorrelate.cpp index 70494210..d9aa0446 100644 --- a/source/consumers/TOF1DCorrelate.cpp +++ b/source/consumers/TOF1DCorrelate.cpp @@ -21,7 +21,7 @@ TOF1DCorrelate::TOF1DCorrelate() res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -29,12 +29,12 @@ TOF1DCorrelate::TOF1DCorrelate() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); stream.set_flag("preset"); stream.set_flag("stream"); - base_options.branches.add(stream); + base_options.branches.add(Setting(stream)); metadata_.overwrite_all_attributes(base_options); } diff --git a/source/consumers/TOFVal2D.cpp b/source/consumers/TOFVal2D.cpp index e82f1e67..d6432dad 100644 --- a/source/consumers/TOFVal2D.cpp +++ b/source/consumers/TOFVal2D.cpp @@ -15,16 +15,16 @@ TOFVal2D::TOFVal2D() SettingMeta app("appearance", SettingType::text, "Plot appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); - base_options.branches.add(flip); + base_options.branches.add(Setting(flip)); SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -32,7 +32,7 @@ TOFVal2D::TOFVal2D() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); base_options.branches.add(value_latch_.settings(-1, "Value to bin")); diff --git a/source/consumers/TOFVal2DCorrelate.cpp b/source/consumers/TOFVal2DCorrelate.cpp index ab5cbbff..81f6a624 100644 --- a/source/consumers/TOFVal2DCorrelate.cpp +++ b/source/consumers/TOFVal2DCorrelate.cpp @@ -15,16 +15,16 @@ TOFVal2DCorrelate::TOFVal2DCorrelate() SettingMeta app("appearance", SettingType::text, "Plot appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); - base_options.branches.add(flip); + base_options.branches.add(Setting(flip)); SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -32,12 +32,12 @@ TOFVal2DCorrelate::TOFVal2DCorrelate() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); stream.set_flag("preset"); stream.set_flag("stream"); - base_options.branches.add(stream); + base_options.branches.add(Setting(stream)); base_options.branches.add(value_latch_.settings(-1, "Value to bin")); diff --git a/source/consumers/TimeDelta1D.cpp b/source/consumers/TimeDelta1D.cpp index b64af76e..2b9069db 100644 --- a/source/consumers/TimeDelta1D.cpp +++ b/source/consumers/TimeDelta1D.cpp @@ -22,7 +22,7 @@ TimeDelta1D::TimeDelta1D() res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -30,7 +30,7 @@ TimeDelta1D::TimeDelta1D() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); metadata_.overwrite_all_attributes(base_options); } diff --git a/source/consumers/TimeDomain.cpp b/source/consumers/TimeDomain.cpp index d5b533fe..8a0d84ed 100644 --- a/source/consumers/TimeDomain.cpp +++ b/source/consumers/TimeDomain.cpp @@ -23,13 +23,13 @@ TimeDomain::TimeDomain() win.set_val("min", 1); win.set_val("units", "units (see below)"); win.set_val("description", "Infinite if =0"); - base_options.branches.add(win); + base_options.branches.add(Setting(win)); SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -37,10 +37,10 @@ TimeDomain::TimeDomain() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); SettingMeta trim("trim", SettingType::boolean, "Trim last bin"); - base_options.branches.add(trim); + base_options.branches.add(Setting(trim)); metadata_.overwrite_all_attributes(base_options); } diff --git a/source/consumers/TimeSpectrum.cpp b/source/consumers/TimeSpectrum.cpp index c0dc6119..2894ef75 100644 --- a/source/consumers/TimeSpectrum.cpp +++ b/source/consumers/TimeSpectrum.cpp @@ -14,16 +14,16 @@ TimeSpectrum::TimeSpectrum() SettingMeta app("appearance", SettingType::text, "Plot appearance"); app.set_flag("gradient-name"); - base_options.branches.add(app); + base_options.branches.add(Setting(app)); SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); - base_options.branches.add(flip); + base_options.branches.add(Setting(flip)); SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); res.set_flag("preset"); res.set_val("min", 1); res.set_val("units", "Time units (see below)"); - base_options.branches.add(res); + base_options.branches.add(Setting(res)); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -31,7 +31,7 @@ TimeSpectrum::TimeSpectrum() units.set_enum(3, "\u03BCs"); units.set_enum(6, "ms"); units.set_enum(9, "s"); - base_options.branches.add(units); + base_options.branches.add(Setting(units)); base_options.branches.add(value_latch_.settings(-1, "Value to bin")); diff --git a/source/core/Consumer.cpp b/source/core/Consumer.cpp index c3103ed8..52bd0b51 100644 --- a/source/core/Consumer.cpp +++ b/source/core/Consumer.cpp @@ -13,7 +13,7 @@ Consumer::Consumer() SettingMeta stream("stream_id", SettingType::text, "Stream ID"); stream.set_flag("preset"); stream.set_flag("stream"); - attributes.branches.add(stream); + attributes.branches.add(Setting(stream)); metadata_.overwrite_all_attributes(attributes); } diff --git a/source/core/Detector.cpp b/source/core/Detector.cpp index 8ef75054..a848a3f6 100644 --- a/source/core/Detector.cpp +++ b/source/core/Detector.cpp @@ -53,7 +53,7 @@ void Detector::add_optimizations(const std::list& l, Setting Detector::get_setting(std::string id) const { - return settings_.find({id}, Match::id); + return settings_.find(Setting(id), Match::id); } void Detector::clear_optimizations() diff --git a/source/core/Engine.cpp b/source/core/Engine.cpp index 38b7533d..bcb1d329 100644 --- a/source/core/Engine.cpp +++ b/source/core/Engine.cpp @@ -30,15 +30,15 @@ Setting Engine::default_settings() { Setting ret {SettingMeta("Engine", SettingType::stem)}; ret.branches.add(Setting::text("ProfileDescr", "(no description)")); - ret.branches.add(SettingMeta("DropPackets", SettingType::menu)); - ret.branches.add(SettingMeta("MaxPackets", SettingType::integer)); + ret.branches.add(Setting(SettingMeta("DropPackets", SettingType::menu))); + ret.branches.add(Setting(SettingMeta("MaxPackets", SettingType::integer))); return ret; } void Engine::initialize(const json &profile) { - //printf("initialize engine\n"); + //TRC("Engine::initialize"); UNIQUE_LOCK_EVENTUALLY_ST Setting tree = profile; @@ -123,9 +123,9 @@ StreamManifest Engine::stream_manifest() const continue; for (auto m : q.second->stream_manifest()) ret[m.first] = m.second; - ret["engine"].stats.branches.add(SettingMeta("queue_size", SettingType::integer)); - ret["engine"].stats.branches.add(SettingMeta("dropped_spills", SettingType::integer)); - ret["engine"].stats.branches.add(SettingMeta("dropped_events", SettingType::integer)); + ret["engine"].stats.branches.add(Setting(SettingMeta("queue_size", SettingType::integer))); + ret["engine"].stats.branches.add(Setting(SettingMeta("dropped_spills", SettingType::integer))); + ret["engine"].stats.branches.add(Setting(SettingMeta("dropped_events", SettingType::integer))); } return ret; } diff --git a/source/core/TimeBase.h b/source/core/TimeBase.h index adf0e021..4f4f9691 100644 --- a/source/core/TimeBase.h +++ b/source/core/TimeBase.h @@ -168,8 +168,8 @@ class TimeBasePlugin : public Plugin void settings(const Setting& setting) override { std::string r{plugin_name()}; - uint32_t mult = setting.find({r + "/multiplier"}).get_int(); - uint32_t div = setting.find({r + "/divider"}).get_int(); + uint32_t mult = setting.find(Setting(r + "/multiplier")).get_int(); + uint32_t div = setting.find(Setting(r + "/divider")).get_int(); timebase_ = TimeBase(mult ? mult : 1, div ? div : 1); } diff --git a/source/core/calibration/CoefFunctionFactory.cpp b/source/core/calibration/CoefFunctionFactory.cpp index 1eaf1472..befc20ff 100644 --- a/source/core/calibration/CoefFunctionFactory.cpp +++ b/source/core/calibration/CoefFunctionFactory.cpp @@ -5,9 +5,9 @@ namespace DAQuiri { -void CoefFunctionFactory::register_type(std::function constructor) +void CoefFunctionFactory::register_type(std::string name, + std::function constructor) { - auto name = CoefFunctionPtr(constructor())->type(); if (name.empty()) WARN(" failed to register nameless type"); else if (constructors_.count(name)) @@ -24,8 +24,10 @@ CoefFunctionPtr CoefFunctionFactory::create_type(std::string type) const auto it = constructors_.find(type); if (it != constructors_.end()) return CoefFunctionPtr(it->second()); - else + else { + WARN("CoefFunctionFactory failed to create type={}", type); return CoefFunctionPtr(); + } } CoefFunctionPtr CoefFunctionFactory::create_copy(CoefFunctionPtr other) const diff --git a/source/core/calibration/CoefFunctionFactory.h b/source/core/calibration/CoefFunctionFactory.h index dbc28aac..999e9fc5 100644 --- a/source/core/calibration/CoefFunctionFactory.h +++ b/source/core/calibration/CoefFunctionFactory.h @@ -19,7 +19,8 @@ class CoefFunctionFactory CoefFunctionPtr create_copy(CoefFunctionPtr other) const; CoefFunctionPtr create_from_json(const nlohmann::json&) const; - void register_type(std::function constructor); + void register_type(std::string name, + std::function constructor); std::vector types() const; void clear(); @@ -39,7 +40,8 @@ class CoefFunctionRegistrar public: CoefFunctionRegistrar() { - CoefFunctionFactory::singleton().register_type([](void) -> CoefFunction* { return new T(); }); + CoefFunctionFactory::singleton().register_type(T().type(), + [](void) -> CoefFunction* { return new T(); }); } }; diff --git a/source/core/calibration/Parameter.cpp b/source/core/calibration/Parameter.cpp index c90204fd..d9dd35ba 100644 --- a/source/core/calibration/Parameter.cpp +++ b/source/core/calibration/Parameter.cpp @@ -1,6 +1,12 @@ #include #include -#include + +#include + +double median(double a, double b, double c) +{ + return std::max(std::min(a, b), std::min(std::max(a, b), c)); +} namespace DAQuiri { @@ -31,9 +37,9 @@ void Parameter::value(double v) void Parameter::set(double v1, double v2, double v3) { - lower_ = min(v1, v2, v3); - upper_ = max(v1, v2, v3); - value_ = mid(v1, v2, v3); + lower_ = std::min({v1, v2, v3}); + upper_ = std::max({v1, v2, v3}); + value_ = median(v1, v2, v3); } void Parameter::constrain(double v1, double v2) diff --git a/source/core/calibration/Polynomial.h b/source/core/calibration/Polynomial.h index 4abee750..5ac11f84 100644 --- a/source/core/calibration/Polynomial.h +++ b/source/core/calibration/Polynomial.h @@ -9,6 +9,7 @@ class Polynomial : public CoefFunction { public: using CoefFunction::CoefFunction; + Polynomial() : CoefFunction::CoefFunction() {} std::string type() const override { return "Polynomial"; } Polynomial* clone() const override { return new Polynomial(*this); } diff --git a/source/core/plugin/Container.h b/source/core/plugin/Container.h index 426e4fd8..0bae6c55 100644 --- a/source/core/plugin/Container.h +++ b/source/core/plugin/Container.h @@ -17,22 +17,22 @@ TT class Container using iterator = typename container_t::iterator; using const_iterator = typename container_t::const_iterator; - Container() {} + Container() = default; - void join(const Container other); + void join(const Container& other); - inline bool empty() const { return data_.empty(); } - inline size_t size() const { return data_.size(); } - inline void clear() { data_.clear(); } - inline std::list& data() { return data_; } - inline const std::list& data() const { return data_; } + [[nodiscard]] bool empty() const { return data_.empty(); } + [[nodiscard]] size_t size() const { return data_.size(); } + void clear() { data_.clear(); } + std::list& data() { return data_; } + const std::list& data() const { return data_; } - inline iterator begin() { return data_.begin(); } - inline iterator end() { return data_.end(); } - inline const_iterator begin() const { return data_.begin(); } - inline const_iterator end() const { return data_.end(); } - inline const_iterator cbegin() const { return data_.cbegin(); } - inline const_iterator cend() const { return data_.cend(); } + iterator begin() { return data_.begin(); } + iterator end() { return data_.end(); } + const_iterator begin() const { return data_.begin(); } + const_iterator end() const { return data_.end(); } + const_iterator cbegin() const { return data_.cbegin(); } + const_iterator cend() const { return data_.cend(); } bool operator!= (const Container& other) const; bool operator== (const Container& other) const; @@ -58,21 +58,23 @@ TT class Container std::vector to_vector() const; void from_vector(std::vector vec); - inline friend void to_json(json& j, const Container& t) + friend void to_json(json& j, const Container& t) { j = t.data_; // for (auto k : t.data_) // j.push_back(json(k)); } - inline friend void from_json(const json& j, Container& t) + friend void from_json(const json& j, Container& t) { for (auto it : j) t.data_.push_back(it); } }; -TT void Container::join(const Container other) +// \todo: move implementations to tpp file + +TT void Container::join(const Container& other) { data_.insert(data_.end(), other.data_.begin(), other.data_.end()); } @@ -141,7 +143,7 @@ TT void Container::replace(T t) TT void Container::replace(size_t i, T t) { - if ((i >= 0) && (i < size())) { + if (i < size()) { typename std::list::iterator it = std::next(data_.begin(), i); (*it) = t; } @@ -169,7 +171,7 @@ TT void Container::remove_a(const T &t) //using shallow compare TT void Container::remove(size_t i) { - if ((i >= 0) && (i < size())) { + if (i < size()) { typename std::list::iterator it = std::next(data_.begin(), i); data_.erase(it); } @@ -185,7 +187,7 @@ TT T Container::get(T t) const TT T Container::get(size_t i) const { - if ((i >= 0) && (i < size())) { + if (i < size()) { typename std::list::const_iterator it = std::next(data_.begin(), i); return *it; } @@ -194,7 +196,7 @@ TT T Container::get(size_t i) const TT void Container::up(size_t i) { - if ((i > 0) && (i < size())) { + if (i < size()) { typename std::list::iterator it = std::next(data_.begin(), i-1); std::swap( *it, *std::next( it ) ); } @@ -202,7 +204,7 @@ TT void Container::up(size_t i) TT void Container::down(size_t i) { - if ((i >= 0) && ((i+1) < size())) { + if ((i+1) < size()) { typename std::list::iterator it = std::next(data_.begin(), i); std::swap( *it, *std::next( it ) ); } diff --git a/source/core/plugin/Pattern.h b/source/core/plugin/Pattern.h index 87175649..e7eac547 100644 --- a/source/core/plugin/Pattern.h +++ b/source/core/plugin/Pattern.h @@ -7,21 +7,23 @@ #include using json = nlohmann::json; +/// \todo: move implementation to cpp file + namespace DAQuiri { class Pattern { public: - inline Pattern() {} + inline Pattern() = default; inline Pattern(size_t thresh, std::vector gts) { set(thresh, gts); } - inline const std::vector& gates() const { return gates_; } - inline size_t threshold() const { return threshold_; } + [[nodiscard]] inline const std::vector& gates() const { return gates_; } + [[nodiscard]] inline size_t threshold() const { return threshold_; } - inline bool relevant(size_t chan) const + [[nodiscard]] inline bool relevant(size_t chan) const { return ((chan < gates_.size()) && gates_[chan]); } @@ -32,7 +34,7 @@ class Pattern threshold_ = std::min(sz, threshold_); } - inline void set_gates(std::vector gts) + inline void set_gates(const std::vector& gts) { gates_ = gts; threshold_ = std::min(gates_.size(), threshold_); @@ -44,25 +46,25 @@ class Pattern threshold_ = std::min(gates_.size(), threshold_); } - inline void set(size_t thresh, std::vector gts) + inline void set(size_t thresh, const std::vector& gts) { threshold_ = thresh; gates_ = gts; threshold_ = std::min(gates_.size(), threshold_); } - inline bool operator==(const Pattern other) const + inline bool operator==(const Pattern& other) const { return ((gates_ == other.gates_) && (threshold_ == other.threshold_)); } - inline bool operator!=(const Pattern other) const + inline bool operator!=(const Pattern& other) const { return !operator ==(other); } - inline std::string debug() const + [[nodiscard]] inline std::string debug() const { std::stringstream ss; ss << threshold_; diff --git a/source/core/plugin/PreciseFloat.h b/source/core/plugin/PreciseFloat.h index 41fc56bb..ecb393a2 100644 --- a/source/core/plugin/PreciseFloat.h +++ b/source/core/plugin/PreciseFloat.h @@ -56,11 +56,6 @@ using PreciseFloat = boost::multiprecision::number -//using PreciseFloat = boost::multiprecision::mpfr_float_50; -//#include -//using PreciseFloat = __float128; - #ifdef PF_MP inline double to_double(PreciseFloat pf) diff --git a/source/core/plugin/Setting.cpp b/source/core/plugin/Setting.cpp index 39b9c4f3..d935f3f0 100644 --- a/source/core/plugin/Setting.cpp +++ b/source/core/plugin/Setting.cpp @@ -3,17 +3,17 @@ #include #include #include -#include +#include #include namespace DAQuiri { -Setting::Setting(std::string id) +Setting::Setting(const std::string& id) : Setting(SettingMeta(id, SettingType::none)) {} -Setting::Setting(SettingMeta meta) +Setting::Setting(const SettingMeta& meta) { metadata_ = meta; } @@ -43,13 +43,13 @@ void Setting::clear_indices() indices_.clear(); } -void Setting::set_indices(std::set l) +void Setting::set_indices(const std::set& l) { clear_indices(); add_indices(l); } -void Setting::add_indices(std::set l) +void Setting::add_indices(const std::set& l) { for (auto ll : l) indices_.insert(ll); @@ -65,7 +65,7 @@ std::set Setting::indices() const return indices_; } -Setting::Setting(std::string sid, hr_time_t v) +Setting::Setting(const std::string& sid, hr_time_t v) : Setting(SettingMeta(sid, SettingType::time)) { value_time = v; @@ -81,7 +81,7 @@ hr_time_t Setting::time() const return value_time; } -Setting::Setting(std::string sid, hr_duration_t v) +Setting::Setting(const std::string& sid, hr_duration_t v) : Setting(SettingMeta(sid, SettingType::duration)) { value_duration = v; @@ -97,7 +97,7 @@ hr_duration_t Setting::duration() const return value_duration; } -Setting::Setting(std::string sid, Pattern v) +Setting::Setting(const std::string& sid, Pattern v) : Setting(SettingMeta(sid, SettingType::pattern)) { value_pattern = v; @@ -185,9 +185,9 @@ std::string Setting::indices_to_string(bool showblanks) const if (showblanks && idcs.size() < max) for (auto i = idcs.size(); i < max; ++i) - idcs.push_back("-"); + idcs.emplace_back("-"); - if (idcs.size()) + if (!idcs.empty()) return "{" + join(idcs, " ") + "}"; return ""; @@ -292,7 +292,7 @@ Setting Setting::find(Setting address, Match m) const if (find_dfs(address, *this, m)) return address; else - return Setting(); + return {}; } std::list Setting::find_all(const Setting &setting, Match m) const @@ -338,7 +338,7 @@ void Setting::enrich(const std::map &setting_definitio metadata_ = setting_definitions.at(id()); auto idm = metadata_.enum_map(); - if (idm.size()) + if (!idm.empty()) { Container new_branches; auto idss = metadata_.enum_names(); @@ -354,7 +354,7 @@ void Setting::enrich(const std::map &setting_definitio ids.erase(old.id()); } - for (auto id : idm) + for (const auto& id : idm) { if (!ids.count(id.second)) continue; @@ -482,19 +482,19 @@ void Setting::strip_metadata() metadata_ = metadata_.stripped(); } -Setting Setting::text(std::string sid, std::string val) +Setting Setting::text(const std::string& sid, const std::string& val) { Setting ret(SettingMeta(sid, SettingType::text)); ret.value_text = val; return ret; } -Setting Setting::stem(std::string sid) +Setting Setting::stem(const std::string& sid) { return Setting(SettingMeta(sid, SettingType::stem)); } -void Setting::set_text(std::string val) +void Setting::set_text(const std::string& val) { value_text = val; } @@ -506,35 +506,35 @@ std::string Setting::get_text() const // Numerics -Setting Setting::floating(std::string sid, floating_t val) +Setting Setting::floating(const std::string& sid, floating_t val) { Setting ret(SettingMeta(sid, SettingType::floating)); ret.value_dbl = val; return ret; } -Setting Setting::precise(std::string sid, precise_t val) +Setting Setting::precise(const std::string& sid, precise_t val) { Setting ret(SettingMeta(sid, SettingType::precise)); ret.value_precise = val; return ret; } -Setting Setting::boolean(std::string sid, bool val) +Setting Setting::boolean(const std::string& sid, bool val) { Setting ret(SettingMeta(sid, SettingType::boolean)); ret.value_int = val; return ret; } -Setting Setting::integer(std::string sid, integer_t val) +Setting Setting::integer(const std::string& sid, integer_t val) { Setting ret(SettingMeta(sid, SettingType::integer)); ret.value_int = val; return ret; } -Setting Setting::indicator(std::string sid, integer_t val) +Setting Setting::indicator(const std::string& sid, integer_t val) { Setting ret(SettingMeta(sid, SettingType::indicator)); ret.value_int = val; @@ -563,11 +563,11 @@ double Setting::get_number() const void Setting::set_number(double val) { if (is(SettingType::integer)) - value_int = val; + value_int = static_cast(val); else if (is(SettingType::floating)) - value_dbl = val; + value_dbl = static_cast(val); else if (is(SettingType::precise)) - value_precise = val; + value_precise = static_cast(val); enforce_limits(); } @@ -674,14 +674,14 @@ Setting& Setting::operator--() } // postfix -Setting Setting::operator++(int) +const Setting Setting::operator++(int) { Setting tmp(*this); operator++(); return tmp; } -Setting Setting::operator--(int) +const Setting Setting::operator--(int) { Setting tmp(*this); operator--(); @@ -736,16 +736,17 @@ std::string Setting::val_to_string() const return ss.str(); } -std::string Setting::debug(std::string prepend, bool verbose) const +std::string Setting::debug(const std::string& prepend, bool verbose) const { std::string ret; if (!id().empty()) - ret = col(BLUE, NONE, BRIGHT) + id() + col(); + ret = format(fg(fmt::terminal_color::bright_blue), "{}", id()); if (!indices_.empty()) - ret += col(RED) + indices_to_string(true) + col(); + ret += format(fg(fmt::terminal_color::red), "{}", indices_to_string(true)); if (!ret.empty()) ret += "="; - ret += col(GREEN, NONE, BRIGHT) + val_to_string() + col(); + ret += format(fg(fmt::terminal_color::bright_green), "{}", val_to_string()); + ret += " " + metadata_.debug(prepend, verbose); ret += "\n"; if (!branches.empty()) @@ -846,7 +847,7 @@ void from_json(const json& j, Setting &s) s.metadata_ = j["metadata"]; if (j.count("indices")) - for (auto it : j["indices"]) + for (const auto& it : j["indices"]) s.indices_.insert(it.get()); if (s.is(SettingType::stem)) diff --git a/source/core/plugin/Setting.h b/source/core/plugin/Setting.h index e5295efc..922ac260 100644 --- a/source/core/plugin/Setting.h +++ b/source/core/plugin/Setting.h @@ -45,85 +45,85 @@ class Setting public: Container branches; - Setting() {} - Setting(std::string id); - Setting(SettingMeta meta); - Setting(std::string sid, hr_time_t v); - Setting(std::string sid, hr_duration_t v); - Setting(std::string sid, Pattern v); - static Setting floating(std::string sid, floating_t val); - static Setting precise(std::string sid, precise_t val); - static Setting boolean(std::string sid, bool val); - static Setting integer(std::string sid, integer_t val); - static Setting indicator(std::string sid, integer_t val); - static Setting text(std::string sid, std::string val); - static Setting stem(std::string sid); + Setting() = default; + explicit Setting(const std::string& id); + explicit Setting(const SettingMeta& meta); + Setting(const std::string& sid, hr_time_t v); + Setting(const std::string& sid, hr_duration_t v); + Setting(const std::string& sid, Pattern v); + static Setting floating(const std::string& sid, floating_t val); + static Setting precise(const std::string& sid, precise_t val); + static Setting boolean(const std::string& sid, bool val); + static Setting integer(const std::string& sid, integer_t val); + static Setting indicator(const std::string& sid, integer_t val); + static Setting text(const std::string& sid, const std::string& val); + static Setting stem(const std::string& sid); // id, type, metadata explicit operator bool() const; - std::string id() const; - bool is(SettingType type) const; - SettingMeta metadata() const; + [[nodiscard]] std::string id() const; + [[nodiscard]] bool is(SettingType type) const; + [[nodiscard]] SettingMeta metadata() const; void strip_metadata(); void enrich(const std::map &, bool impose_limits = false); // equality - bool shallow_equals(const Setting &other) const; + [[nodiscard]] bool shallow_equals(const Setting &other) const; bool operator==(const Setting &other) const; bool operator!=(const Setting &other) const; - bool compare(const Setting &other, Match m) const; + [[nodiscard]] bool compare(const Setting &other, Match m) const; //time void set_time(hr_time_t v); - hr_time_t time() const; + [[nodiscard]] hr_time_t time() const; //duration void set_duration(hr_duration_t v); - hr_duration_t duration() const; + [[nodiscard]] hr_duration_t duration() const; //pattern void set_pattern(Pattern v); - Pattern pattern() const; + [[nodiscard]] Pattern pattern() const; //numerics - bool numeric() const; - double get_number() const; + [[nodiscard]] bool numeric() const; + [[nodiscard]] double get_number() const; void set_number(double); // prefix Setting &operator++(); Setting &operator--(); // postfix - Setting operator++(int); - Setting operator--(int); + const Setting operator++(int); + const Setting operator--(int); // Precise float void set_precise(PreciseFloat pf); - PreciseFloat precise() const; + [[nodiscard]] PreciseFloat precise() const; // menu/indicator/integer void set_int(integer_t v); - integer_t get_int() const; + [[nodiscard]] integer_t get_int() const; void select(integer_t v); - integer_t selection() const; + [[nodiscard]] integer_t selection() const; //command/boolean - bool get_bool() const; + [[nodiscard]] bool get_bool() const; void set_bool(bool); - bool triggered() const; + [[nodiscard]] bool triggered() const; void trigger(); void reset(); //text - void set_text(std::string val); - std::string get_text() const; + void set_text(const std::string& val); + [[nodiscard]] std::string get_text() const; // indices void clear_indices(); - void set_indices(std::set l); - void add_indices(std::set l); - bool has_index(int32_t i) const; - std::set indices() const; + void set_indices(const std::set& l); + void add_indices(const std::set& l); + [[nodiscard]] bool has_index(int32_t i) const; + [[nodiscard]] std::set indices() const; // assign value void set_val(const Setting &other); @@ -133,10 +133,10 @@ class Setting void set(const Setting &s, Match m = Match::id, bool greedy = false); //template for all containers? void set(const std::list &s, Match m = Match::id, bool greedy = false); - bool has(Setting address, Match m = Match::id) const; + [[nodiscard]] bool has(Setting address, Match m = Match::id) const; void erase(Setting address, Match m = Match::id); - Setting find(Setting address, Match m = Match::id) const; - std::list find_all(const Setting &setting, Match m = Match::id) const; + [[nodiscard]] Setting find(Setting address, Match m = Match::id) const; + [[nodiscard]] std::list find_all(const Setting &setting, Match m = Match::id) const; // metadata-related convenience functions void enable_if_flag(bool enable, const std::string &flag); @@ -147,16 +147,16 @@ class Setting void enforce_limits(); // to string - std::string debug(std::string prepend = "", bool verbose = true) const; - std::string val_to_string() const; - std::string indices_to_string(bool showblanks = false) const; + [[nodiscard]] std::string debug(const std::string& prepend = "", bool verbose = true) const; + [[nodiscard]] std::string val_to_string() const; + [[nodiscard]] std::string indices_to_string(bool showblanks = false) const; // serialization friend void to_json(json &j, const Setting &s); friend void from_json(const json &j, Setting &s); private: - bool compare_indices(const Setting &other) const; + [[nodiscard]] bool compare_indices(const Setting &other) const; bool find_dfs(Setting &result, const Setting &root, Match m) const; void erase_matches(const Setting &, Setting &, Match m); @@ -166,7 +166,7 @@ class Setting bool replace_first(const Setting &setting, Match m); void replace_all(const Setting &setting, Match m); - json val_to_json() const; + [[nodiscard]] json val_to_json() const; void val_from_json(const json &j); SettingMeta metadata_; diff --git a/source/core/plugin/SettingMeta.cpp b/source/core/plugin/SettingMeta.cpp index 721211bf..88a21470 100644 --- a/source/core/plugin/SettingMeta.cpp +++ b/source/core/plugin/SettingMeta.cpp @@ -1,6 +1,8 @@ #include -#include #include +#include + +#include namespace DAQuiri { @@ -68,13 +70,13 @@ std::string to_string(const SettingType &t) return ""; } -SettingMeta::SettingMeta(std::string id, SettingType type) +SettingMeta::SettingMeta(const std::string& id, SettingType type) : SettingMeta(id, type, id) {} SettingMeta::SettingMeta(std::string id, SettingType type, - std::string name) - : id_(id) + const std::string& name) + : id_(std::move(id)) , type_ (type) { values_["name"] = name; @@ -104,10 +106,10 @@ bool SettingMeta::is_numeric() const void SettingMeta::set_enum(int32_t idx, std::string val) { - enum_map_[idx] = val; + enum_map_[idx] = std::move(val); } -void SettingMeta::set_enums(int32_t start_idx, std::list vals) +void SettingMeta::set_enums(int32_t start_idx, const std::list& vals) { for (const auto& v : vals) set_enum(start_idx++, v); @@ -138,7 +140,7 @@ std::map SettingMeta::enum_map() const return enum_map_; } -std::string SettingMeta::get_string(std::string name, std::string default_val) const +std::string SettingMeta::get_string(const std::string& name, std::string default_val) const { if (values_.count(name) && values_.at(name).is_string()) return values_[name]; @@ -182,17 +184,17 @@ bool SettingMeta::meaningful() const !enum_map_.empty()); } -std::string SettingMeta::debug(std::string prepend, bool verbose) const +std::string SettingMeta::debug(const std::string& prepend, bool verbose) const { - std::string ret = col(GREEN) + to_string(type_) + col(); + std::string ret = format(fg(fmt::terminal_color::green), "{}", + to_string(type_)); if (is_numeric()) - ret += " " + col(CYAN) + value_range() + col(); + ret += format(fg(fmt::terminal_color::cyan), " {}", value_range()); if (!flags_.empty()) - ret += " " + col(WHITE, NONE, DIM) - + join(flags_, " ") - + col(); + ret += format(fg(fmt::terminal_color::bright_black), " {}", + join(flags_, " ")); json cont; if (verbose) @@ -216,7 +218,7 @@ std::string SettingMeta::debug(std::string prepend, bool verbose) const + it.value().dump(); } - if (verbose && enum_map_.size()) + if (verbose && !enum_map_.empty()) { ret += "\n" + prepend + " "; for (auto &i : enum_map_) @@ -238,7 +240,7 @@ std::string SettingMeta::value_range() const return ss.str(); } -std::string SettingMeta::mins(std::string def) const +std::string SettingMeta::mins(const std::string& def) const { if (is(SettingType::integer)) return min_str(def); @@ -249,7 +251,7 @@ std::string SettingMeta::mins(std::string def) const return "?"; } -std::string SettingMeta::maxs(std::string def) const +std::string SettingMeta::maxs(const std::string& def) const { if (is(SettingType::integer)) return max_str(def); @@ -286,7 +288,7 @@ void from_json(const json& j, SettingMeta &s) s.enum_map_[it["val"]] = it["meaning"]; if (j.count("flags")) - for (auto it : j["flags"]) + for (const auto& it : j["flags"]) s.flags_.insert(it.get()); if (j.count("contents")) diff --git a/source/core/plugin/SettingMeta.h b/source/core/plugin/SettingMeta.h index f5ed161e..e9259293 100644 --- a/source/core/plugin/SettingMeta.h +++ b/source/core/plugin/SettingMeta.h @@ -54,18 +54,18 @@ std::string to_string(const SettingType& t); class SettingMeta { public: - SettingMeta() {} - SettingMeta(std::string id, SettingType type); - SettingMeta(std::string id, SettingType type, std::string name); + SettingMeta() = default; + SettingMeta(const std::string& id, SettingType type); + SettingMeta(std::string id, SettingType type, const std::string& name); - SettingMeta stripped() const; - bool meaningful() const; + [[nodiscard]] SettingMeta stripped() const; + [[nodiscard]] bool meaningful() const; - std::string id() const; - SettingType type() const; + [[nodiscard]] std::string id() const; + [[nodiscard]] SettingType type() const; - bool is(SettingType type) const; - bool is_numeric() const; + [[nodiscard]] bool is(SettingType type) const; + [[nodiscard]] bool is_numeric() const; void set_flag(std::string f); bool has_flag(std::string f); @@ -73,13 +73,13 @@ class SettingMeta void set_flags(std::initializer_list fs); void set_enum(int32_t idx, std::string val); - void set_enums(int32_t start_idx, std::list vals); - bool has_enum(int32_t idx) const; - std::string enum_name(int32_t idx) const; - std::list enum_names() const; - std::map enum_map() const; + void set_enums(int32_t start_idx, const std::list& vals); + [[nodiscard]] bool has_enum(int32_t idx) const; + [[nodiscard]] std::string enum_name(int32_t idx) const; + [[nodiscard]] std::list enum_names() const; + [[nodiscard]] std::map enum_map() const; - std::string get_string(std::string name, std::string default_val) const; + [[nodiscard]] std::string get_string(const std::string& name, std::string default_val) const; TT T get_num(std::string name, T default_val) const; TT void set_val(std::string name, T val); @@ -89,8 +89,8 @@ class SettingMeta TT T max() const; TT T step() const; - std::string value_range() const; - std::string debug(std::string prepend = "", bool verbose = true) const; + [[nodiscard]] std::string value_range() const; + [[nodiscard]] std::string debug(const std::string& prepend = "", bool verbose = true) const; friend void to_json(json& j, const SettingMeta &s); friend void from_json(const json& j, SettingMeta &s); @@ -102,13 +102,14 @@ class SettingMeta json values_; std::map enum_map_; - std::string mins(std::string def) const; - std::string maxs(std::string def) const; + [[nodiscard]] std::string mins(const std::string& def) const; + [[nodiscard]] std::string maxs(const std::string& def) const; - TT std::string min_str(std::string def) const; - TT std::string max_str(std::string def) const; + TT [[nodiscard]] std::string min_str(std::string def) const; + TT [[nodiscard]] std::string max_str(std::string def) const; }; +// \todo move these to tpp file TT std::string SettingMeta::min_str(std::string def) const { diff --git a/source/core/util/CMakeLists.txt b/source/core/util/CMakeLists.txt index 373c16a5..bf32db56 100644 --- a/source/core/util/CMakeLists.txt +++ b/source/core/util/CMakeLists.txt @@ -10,8 +10,6 @@ set(SOURCES set(HEADERS ${dir}/ascii_tree.h ${dir}/bin_hex_print.h - ${dir}/color_bash.h - ${dir}/compare.h ${dir}/logger.h ${dir}/h5json.h ${dir}/json_file.h diff --git a/source/core/util/Timer.cpp b/source/core/util/Timer.cpp index c3480309..069e4f15 100644 --- a/source/core/util/Timer.cpp +++ b/source/core/util/Timer.cpp @@ -60,7 +60,7 @@ bool Timer::timeout() const std::string Timer::elapsed_str() const { - uint64_t e_tot = static_cast(s()); + auto e_tot = static_cast(s()); uint64_t e_h = e_tot / 3600; uint64_t e_m = (e_tot % 3600) / 60; uint64_t e_s = (e_tot % 60); @@ -76,7 +76,7 @@ std::string Timer::elapsed_str() const std::string Timer::ETA_str() const { - uint64_t ETA_tot = static_cast( + auto ETA_tot = static_cast( ceil(static_cast(timeout_limit) - s()) ); uint64_t ETA_h = ETA_tot / 3600; diff --git a/source/core/util/Timer.h b/source/core/util/Timer.h index ca8f44b4..2f254571 100644 --- a/source/core/util/Timer.h +++ b/source/core/util/Timer.h @@ -15,20 +15,20 @@ class Timer public: - Timer(bool start = false); - Timer(double timeout, bool start = false); + explicit Timer(bool start = false); + explicit Timer(double timeout, bool start = false); void restart(); - double s() const; - double ms() const; - double us() const; + [[nodiscard]] double s() const; + [[nodiscard]] double ms() const; + [[nodiscard]] double us() const; - bool timeout() const; + [[nodiscard]] bool timeout() const; - std::string elapsed_str() const; + [[nodiscard]] std::string elapsed_str() const; - std::string ETA_str() const; + [[nodiscard]] std::string ETA_str() const; static void wait_s(double); static void wait_ms(double); diff --git a/source/core/util/color_bash.h b/source/core/util/color_bash.h deleted file mode 100644 index b09cd3b8..00000000 --- a/source/core/util/color_bash.h +++ /dev/null @@ -1,59 +0,0 @@ -// \todo replace this with fmt/color.h - -#pragma once - -#include -#include - -enum BashColor -{ - NONE = 0, - BLACK, RED, GREEN, - YELLOW, BLUE, MAGENTA, - CYAN, WHITE -}; - -enum BashSpecial -{ - RESET = 0, - BRIGHT, DIM, UNDER, - BLINK, REVERSE, HIDDEN -}; - - -inline std::string col(BashColor foreground = NONE, - BashColor background = NONE, - BashSpecial special = RESET) -{ - std::stringstream s; - -#ifdef NOCOLORBASH - return s.str(); -#endif - - s << "\033["; - - if (!foreground && !background && !special) - s << "0"; // reset colors if no params - - if (special) - { - s << special << "m"; - if (foreground || background) - s << "\033["; - } - - if (foreground) - { - s << 29 + foreground; - if (background) - s << ";"; - } - - if (background) - s << 39 + background; - - s << "m"; - - return s.str(); -} diff --git a/source/core/util/compare.h b/source/core/util/compare.h deleted file mode 100644 index c63dd9ee..00000000 --- a/source/core/util/compare.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -// \todo min/max may exist in std for newer compilers - -inline double min(double a, double b, double c) -{ - return std::min(a, std::min(b, c)); -} - -inline double max(double a, double b, double c) -{ - return std::max(a, std::max(b, c)); -} - -inline double mid(double a, double b, double c) -{ - // Compare each three number to find middle - // number. Enter only if a > b - if (a > b) - { - if (b > c) - return b; - else if (a > c) - return c; - else - return a; - } - else - { - // Decided a is not greater than b. - if (a > c) - return a; - else if (b > c) - return c; - else - return b; - } -} diff --git a/source/core/util/json_file.h b/source/core/util/json_file.h index a00b2eaa..41e290e2 100644 --- a/source/core/util/json_file.h +++ b/source/core/util/json_file.h @@ -3,16 +3,16 @@ #include #include -inline nlohmann::json from_json_file(std::string fname) +inline nlohmann::json from_json_file(const std::string& file_name) { - std::ifstream ifs(fname, std::ofstream::in); + std::ifstream ifs(file_name, std::ofstream::in); nlohmann::json j; if (ifs.good()) ifs >> j; return j; } -inline void to_json_file(const nlohmann::json& j, std::string fname) +inline void to_json_file(const nlohmann::json& j, const std::string& file_name) { - std::ofstream(fname, std::ofstream::trunc) << j.dump(1); + std::ofstream(file_name, std::ofstream::trunc) << j.dump(1); } diff --git a/source/core/util/lexical_extensions.h b/source/core/util/lexical_extensions.h index 885e61ce..9b03c266 100644 --- a/source/core/util/lexical_extensions.h +++ b/source/core/util/lexical_extensions.h @@ -77,8 +77,8 @@ struct FloatDeconstructed } } - FloatDeconstructed() {} - FloatDeconstructed(std::string s) + FloatDeconstructed() = default; + explicit FloatDeconstructed(std::string s) { parse(s); } diff --git a/source/core/util/string_extensions.h b/source/core/util/string_extensions.h index 8846ebc4..6a90af40 100644 --- a/source/core/util/string_extensions.h +++ b/source/core/util/string_extensions.h @@ -59,7 +59,7 @@ inline std::string trim_all(std::string text) std::string s; while (iss >> s) { - if (text != "") + if (!text.empty()) text += " " + s; else text = s; } @@ -67,7 +67,7 @@ inline std::string trim_all(std::string text) } template -inline std::string join(T strings, std::string delimiter) +inline std::string join(T strings, const std::string& delimiter) { std::string ret; for (const auto& s : strings) diff --git a/source/gui/ProfilesForm.cpp b/source/gui/ProfilesForm.cpp index a5e1742e..47e9feb2 100644 --- a/source/gui/ProfilesForm.cpp +++ b/source/gui/ProfilesForm.cpp @@ -114,7 +114,7 @@ void ProfilesForm::update_profiles() if (!tree) continue; - auto description = tree.find({"ProfileDescr"}, Match::id); + auto description = tree.find(Setting("ProfileDescr"), Match::id); profiles_.push_back({q, QS(description.get_text())}); } diff --git a/source/gui/Server.cpp b/source/gui/Server.cpp index d0faf1b1..8f16d452 100644 --- a/source/gui/Server.cpp +++ b/source/gui/Server.cpp @@ -71,9 +71,7 @@ void CommandServer::send_response(QString msg) { if (!server_socket) return; - QByteArray out; - out.append(msg); - server_socket->write(out); + server_socket->write(msg.toLocal8Bit()); } diff --git a/source/gui/SettingsTreeModel.cpp b/source/gui/SettingsTreeModel.cpp index 8b1e34f3..e2bbe901 100644 --- a/source/gui/SettingsTreeModel.cpp +++ b/source/gui/SettingsTreeModel.cpp @@ -228,6 +228,7 @@ bool SettingsTreeItem::setData(int column, const QVariant& value) if ((column == 1) && (itemData.metadata().get_num("chans", 0) > 0)) { QString val = value.toString(); + /// \todo replace with Qt::SkipEmptyParts for new Qt version QStringList ilist = val.split(QRegExp("\\W+"), QString::SkipEmptyParts); if (ilist.isEmpty()) { @@ -376,7 +377,7 @@ QVariant SettingsTreeModel::data(const QModelIndex& index, int role) const Qt::ItemFlags SettingsTreeModel::flags(const QModelIndex& index) const { if (!index.isValid()) - return 0; + return {}; SettingsTreeItem* item = getItem(index); if (edit_read_only_ && (index.column() == 2)) diff --git a/source/gui/UnitConverter.cpp b/source/gui/UnitConverter.cpp index bb6fc89d..7f8316b5 100644 --- a/source/gui/UnitConverter.cpp +++ b/source/gui/UnitConverter.cpp @@ -73,25 +73,17 @@ PreciseFloat UnitConverter::convert_units(PreciseFloat value, std::string from, std::string UnitConverter::get_prefix(std::string full_unit) const { -// std::u32string ucs4 = boost::locale::conv::utf_to_utf(full_unit); -// std::u32string prefix = ucs4; - auto prefix = full_unit; if (full_unit.size() > 1) prefix = full_unit.substr(0, 1); -// return boost::locale::conv::utf_to_utf(prefix); return prefix; } std::string UnitConverter::strip_unit(std::string full_unit) const { -// std::u32string ucs4 = boost::locale::conv::utf_to_utf(full_unit); -// std::u32string stripped_unit = ucs4; - auto stripped_unit = full_unit; if (full_unit.size() > 1) stripped_unit = full_unit.substr(1, full_unit.size()-1); -// return boost::locale::conv::utf_to_utf(stripped_unit); return stripped_unit; } diff --git a/source/gui/daquiri.cpp b/source/gui/daquiri.cpp index 0ce8c6d7..0d157083 100644 --- a/source/gui/daquiri.cpp +++ b/source/gui/daquiri.cpp @@ -191,7 +191,7 @@ void daquiri::update_settings(Setting sets, { engine_status_ = status; stream_manifest_ = manifest; - auto description = sets.find({"ProfileDescr"}, Match::id); + auto description = sets.find(Setting("ProfileDescr"), Match::id); profile_description_ = QS(description.get_text()); if (profile_description_.isEmpty()) profile_description_ = Profiles::singleton().current_profile_name(); diff --git a/source/producers/DummyDevice/DummyDevice.cpp b/source/producers/DummyDevice/DummyDevice.cpp index d257b554..8346fcfe 100644 --- a/source/producers/DummyDevice/DummyDevice.cpp +++ b/source/producers/DummyDevice/DummyDevice.cpp @@ -18,9 +18,9 @@ DummyDevice::DummyDevice() manifest_["Stream1"].event_model.add_value("val1", 1000); manifest_["Stream1"].event_model.add_value("val2", 2000); - manifest_["Stream1"].stats.branches.add(SettingMeta("float_val", SettingType::floating)); - manifest_["Stream1"].stats.branches.add(SettingMeta("int_val", SettingType::integer)); - manifest_["Stream1"].stats.branches.add(SettingMeta("precise_val", SettingType::precise)); + manifest_["Stream1"].stats.branches.add(Setting(SettingMeta("float_val", SettingType::floating))); + manifest_["Stream1"].stats.branches.add(Setting(SettingMeta("int_val", SettingType::integer))); + manifest_["Stream1"].stats.branches.add(Setting(SettingMeta("precise_val", SettingType::precise))); manifest_["Stream2"].event_model.add_value("val_a", 500); manifest_["Stream2"].event_model.add_trace("trc_a", {2, 3, 4}); @@ -66,7 +66,7 @@ Setting DummyDevice::settings() const set.set(Setting(r + "Pattern", pattern_)); set.set(Setting::boolean(r + "Boolean", bool_)); - auto sb = set.find({r + "Binary"}); + auto sb = set.find(Setting(r + "Binary")); sb.set_int(binary_); set.set(sb); @@ -88,38 +88,38 @@ void DummyDevice::settings(const Setting& settings) std::string r{plugin_name() + "/DummySettings/"}; auto set = enrich_and_toggle_presets(settings); - dummy_selection_ = set.find({r + "Menu"}).selection(); - read_only_ = !set.find({r + "Enabled"}).triggered(); - - int_unbounded_ = set.find({r + "IntUnbounded"}).get_int(); - int_lower_bounded_ = set.find({r + "IntLB"}).get_int(); - int_upper_bounded_ = set.find({r + "IntUB"}).get_int(); - int_bounded_ = set.find({r + "IntBounded"}).get_int(); - - float_unbounded_ = set.find({r + "FloatUnbounded"}).get_number(); - float_lower_bounded_ = set.find({r + "FloatLB"}).get_number(); - float_upper_bounded_ = set.find({r + "FloatUB"}).get_number(); - float_bounded_ = set.find({r + "FloatBounded"}).get_number(); - - precise_unbounded_ = set.find({r + "PreciseUnbounded"}).precise(); - precise_lower_bounded_ = set.find({r + "PreciseLB"}).precise(); - precise_upper_bounded_ = set.find({r + "PreciseUB"}).precise(); - precise_bounded_ = set.find({r + "PreciseBounded"}).precise(); - - time_ = set.find({r + "Time"}).time(); - duration_ = set.find({r + "Duration"}).duration(); - - pattern_ = set.find({r + "Pattern"}).pattern(); - bool_ = set.find({r + "Boolean"}).get_bool(); - - text_ = set.find({r + "Text"}).get_text(); - color_ = set.find({r + "Color"}).get_text(); - file_ = set.find({r + "File"}).get_text(); - directory_ = set.find({r + "Directory"}).get_text(); - detector_ = set.find({r + "Detector"}).get_text(); - gradient_ = set.find({r + "Gradient"}).get_text(); - - binary_ = set.find({r + "Binary"}).get_int(); + dummy_selection_ = set.find(Setting(r + "Menu")).selection(); + read_only_ = !set.find(Setting(r + "Enabled")).triggered(); + + int_unbounded_ = set.find(Setting(r + "IntUnbounded")).get_int(); + int_lower_bounded_ = set.find(Setting(r + "IntLB")).get_int(); + int_upper_bounded_ = set.find(Setting(r + "IntUB")).get_int(); + int_bounded_ = set.find(Setting(r + "IntBounded")).get_int(); + + float_unbounded_ = set.find(Setting(r + "FloatUnbounded")).get_number(); + float_lower_bounded_ = set.find(Setting(r + "FloatLB")).get_number(); + float_upper_bounded_ = set.find(Setting(r + "FloatUB")).get_number(); + float_bounded_ = set.find(Setting(r + "FloatBounded")).get_number(); + + precise_unbounded_ = set.find(Setting(r + "PreciseUnbounded")).precise(); + precise_lower_bounded_ = set.find(Setting(r + "PreciseLB")).precise(); + precise_upper_bounded_ = set.find(Setting(r + "PreciseUB")).precise(); + precise_bounded_ = set.find(Setting(r + "PreciseBounded")).precise(); + + time_ = set.find(Setting(r + "Time")).time(); + duration_ = set.find(Setting(r + "Duration")).duration(); + + pattern_ = set.find(Setting(r + "Pattern")).pattern(); + bool_ = set.find(Setting(r + "Boolean")).get_bool(); + + text_ = set.find(Setting(r + "Text")).get_text(); + color_ = set.find(Setting(r + "Color")).get_text(); + file_ = set.find(Setting(r + "File")).get_text(); + directory_ = set.find(Setting(r + "Directory")).get_text(); + detector_ = set.find(Setting(r + "Detector")).get_text(); + gradient_ = set.find(Setting(r + "Gradient")).get_text(); + + binary_ = set.find(Setting(r + "Binary")).get_int(); } StreamManifest DummyDevice::stream_manifest() const diff --git a/source/producers/ESSStream/ESSGeometryPlugin.cpp b/source/producers/ESSStream/ESSGeometryPlugin.cpp index 3f183460..b36e1629 100644 --- a/source/producers/ESSStream/ESSGeometryPlugin.cpp +++ b/source/producers/ESSStream/ESSGeometryPlugin.cpp @@ -43,10 +43,10 @@ Setting ESSGeometryPlugin::settings() const void ESSGeometryPlugin::settings(const Setting& settings) { std::string r{plugin_name()}; - geometry_.nx(settings.find({r + "/extent_x"}).get_number()); - geometry_.ny(settings.find({r + "/extent_y"}).get_number()); - geometry_.nz(settings.find({r + "/extent_z"}).get_number()); - geometry_.np(settings.find({r + "/panels"}).get_number()); + geometry_.nx(settings.find(Setting(r + "/extent_x")).get_number()); + geometry_.ny(settings.find(Setting(r + "/extent_y")).get_number()); + geometry_.nz(settings.find(Setting(r + "/extent_z")).get_number()); + geometry_.np(settings.find(Setting(r + "/panels")).get_number()); } void ESSGeometryPlugin::define(EventModel& definition) diff --git a/source/producers/ESSStream/ESSStream.cpp b/source/producers/ESSStream/ESSStream.cpp index 791d66e4..c522b9f5 100644 --- a/source/producers/ESSStream/ESSStream.cpp +++ b/source/producers/ESSStream/ESSStream.cpp @@ -150,9 +150,9 @@ void ESSStream::settings(const Setting& settings) std::string r {plugin_name()}; auto set = enrich_and_toggle_presets(settings); - kafka_config_.settings(set.find({kafka_config_.plugin_name()})); + kafka_config_.settings(set.find(Setting(kafka_config_.plugin_name()))); - size_t total = set.find({r + "/TopicCount"}).get_int(); + size_t total = set.find(Setting(r + "/TopicCount")).get_int(); if (!total) total = 1; @@ -166,14 +166,14 @@ void ESSStream::settings(const Setting& settings) if (v.id() != (r + "/Topic")) continue; - auto parser_set = enrich_and_toggle_presets(v.find({r + "/Parser"})); + auto parser_set = enrich_and_toggle_presets(v.find(Setting(r + "/Parser"))); auto parser = parser_set.metadata().enum_name(parser_set.selection()); - streams_[i].config.settings(v.find(streams_[i].config.plugin_name())); + streams_[i].config.settings(v.find(Setting(streams_[i].config.plugin_name()))); select_parser(i, parser); if (streams_[i].parser && (streams_[i].parser->plugin_name() == parser)) - streams_[i].parser->settings(v.find({parser})); + streams_[i].parser->settings(v.find(Setting(parser))); i++; } } @@ -370,7 +370,7 @@ std::string ESSStream::get_fb_id(Kafka::MessagePtr message) ERR("Could not extract id. Flatbuffer was only {} bytes. Expected ≥ 8 bytes.", message->low_level->len()); return {}; } - auto ch = reinterpret_cast(message->low_level->payload()); + auto ch = reinterpret_cast(message->low_level->payload()); return std::string(ch + 4, 4); } diff --git a/source/producers/ESSStream/KafkaPlugin.cpp b/source/producers/ESSStream/KafkaPlugin.cpp index d3ff74bf..a78be05b 100644 --- a/source/producers/ESSStream/KafkaPlugin.cpp +++ b/source/producers/ESSStream/KafkaPlugin.cpp @@ -109,9 +109,9 @@ Setting KafkaConfigPlugin::settings() const void KafkaConfigPlugin::settings(const Setting& set) { std::string r {plugin_name()}; - kafka_broker_name_ = set.find({r + "/KafkaBroker"}).get_text(); - kafka_timeout_ = set.find({r + "/KafkaTimeout"}).get_int(); - kafka_decomission_wait_ = set.find({r + "/KafkaDecomission"}).get_int(); + kafka_broker_name_ = set.find(Setting(r + "/KafkaBroker")).get_text(); + kafka_timeout_ = set.find(Setting(r + "/KafkaTimeout")).get_int(); + kafka_decomission_wait_ = set.find(Setting(r + "/KafkaDecomission")).get_int(); } std::string KafkaConfigPlugin::random_string( size_t length ) @@ -273,7 +273,7 @@ Setting KafkaStreamConfig::settings() const void KafkaStreamConfig::settings(const Setting& set) { std::string r{plugin_name()}; - kafka_topic_name_ = set.find({r + "/KafkaTopic"}).get_text(); - kafka_ff_ = set.find({r + "/KafkaFF"}).get_bool(); - kafka_max_backlog_ = set.find({r + "/KafkaMaxBacklog"}).get_int(); + kafka_topic_name_ = set.find(Setting(r + "/KafkaTopic")).get_text(); + kafka_ff_ = set.find(Setting(r + "/KafkaFF")).get_bool(); + kafka_max_backlog_ = set.find(Setting(r + "/KafkaMaxBacklog")).get_int(); } diff --git a/source/producers/ESSStream/SenvParser.cpp b/source/producers/ESSStream/SenvParser.cpp index d493faa6..f67803d2 100644 --- a/source/producers/ESSStream/SenvParser.cpp +++ b/source/producers/ESSStream/SenvParser.cpp @@ -43,12 +43,12 @@ StreamManifest SenvParser::stream_manifest() const for (size_t i=0; i < 4; ++i) { auto sid = stream_id_base_ + std::to_string(i); ret[sid].event_model = event_model_; - ret[sid].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[sid].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); - ret[sid].stats.branches.add(SettingMeta("senv_name", SettingType::text)); - ret[sid].stats.branches.add(SettingMeta("senv_chan", SettingType::integer)); - ret[sid].stats.branches.add(SettingMeta("senv_delta", SettingType::floating)); - ret[sid].stats.branches.add(SettingMeta("senv_counter", SettingType::integer)); + ret[sid].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[sid].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_name", SettingType::text))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_chan", SettingType::integer))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_delta", SettingType::floating))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_counter", SettingType::integer))); } return ret; } @@ -72,12 +72,12 @@ void SenvParser::settings(const Setting& settings) { std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - stream_id_base_ = set.find({r + "/StreamBase"}).get_text(); - filter_source_name_ = set.find({r + "/FilterSourceName"}).triggered(); - source_name_ = set.find({r + "/SourceName"}).get_text(); + stream_id_base_ = set.find(Setting(r + "/StreamBase")).get_text(); + filter_source_name_ = set.find(Setting(r + "/FilterSourceName")).triggered(); + source_name_ = set.find(Setting(r + "/SourceName")).get_text(); TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); event_model_.timebase = tbs.timebase(); } diff --git a/source/producers/ESSStream/SenvParserWrong.cpp b/source/producers/ESSStream/SenvParserWrong.cpp index 7a0afabb..41585a8f 100644 --- a/source/producers/ESSStream/SenvParserWrong.cpp +++ b/source/producers/ESSStream/SenvParserWrong.cpp @@ -41,12 +41,12 @@ StreamManifest SenvParserWrong::stream_manifest() const for (size_t i=0; i < 4; ++i) { auto sid = stream_id_base_ + std::to_string(i); ret[sid].event_model = event_model_; - ret[sid].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[sid].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); - ret[sid].stats.branches.add(SettingMeta("senv_name", SettingType::text)); - ret[sid].stats.branches.add(SettingMeta("senv_chan", SettingType::integer)); - ret[sid].stats.branches.add(SettingMeta("senv_delta", SettingType::floating)); - ret[sid].stats.branches.add(SettingMeta("senv_counter", SettingType::integer)); + ret[sid].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[sid].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_name", SettingType::text))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_chan", SettingType::integer))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_delta", SettingType::floating))); + ret[sid].stats.branches.add(Setting(SettingMeta("senv_counter", SettingType::integer))); } return ret; } @@ -70,12 +70,12 @@ void SenvParserWrong::settings(const Setting& settings) { std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - stream_id_base_ = set.find({r + "/StreamBase"}).get_text(); - filter_source_name_ = set.find({r + "/FilterSourceName"}).triggered(); - source_name_ = set.find({r + "/SourceName"}).get_text(); + stream_id_base_ = set.find(Setting(r + "/StreamBase")).get_text(); + filter_source_name_ = set.find(Setting(r + "/FilterSourceName")).triggered(); + source_name_ = set.find(Setting(r + "/SourceName")).get_text(); TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); event_model_.timebase = tbs.timebase(); } diff --git a/source/producers/ESSStream/ev42_parser.cpp b/source/producers/ESSStream/ev42_parser.cpp index 0d1f7cc9..9adf7149 100644 --- a/source/producers/ESSStream/ev42_parser.cpp +++ b/source/producers/ESSStream/ev42_parser.cpp @@ -72,20 +72,20 @@ void ev42_events::settings(const Setting& settings) std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - filter_source_name_ = set.find({r + "/FilterSourceName"}).triggered(); - source_name_ = set.find({r + "/SourceName"}).get_text(); - stream_id_ = set.find({r + "/StreamID"}).get_text(); - spoof_clock_ = static_cast(set.find({r + "/SpoofClock"}).get_int()); - heartbeat_ = set.find({r + "/Heartbeat"}).triggered(); - ordering_ = static_cast(set.find({r + "/MessageOrdering"}).get_int()); + filter_source_name_ = set.find(Setting(r + "/FilterSourceName")).triggered(); + source_name_ = set.find(Setting(r + "/SourceName")).get_text(); + stream_id_ = set.find(Setting(r + "/StreamID")).get_text(); + spoof_clock_ = static_cast(set.find(Setting(r + "/SpoofClock")).get_int()); + heartbeat_ = set.find(Setting(r + "/Heartbeat")).triggered(); + ordering_ = static_cast(set.find(Setting(r + "/MessageOrdering")).get_int()); event_definition_ = EventModel(); TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); event_definition_ = EventModel(); event_definition_.timebase = tbs.timebase(); - geometry_.settings(set.find({geometry_.plugin_name()})); + geometry_.settings(set.find(Setting(geometry_.plugin_name()))); geometry_.define(event_definition_); } @@ -93,9 +93,9 @@ StreamManifest ev42_events::stream_manifest() const { StreamManifest ret; ret[stream_id_].event_model = event_definition_; - ret[stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); - ret[stream_id_].stats.branches.add(SettingMeta("pulse_time", SettingType::precise)); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("pulse_time", SettingType::precise))); return ret; } @@ -228,8 +228,8 @@ uint64_t ev42_events::process_payload(SpillMultiqueue * spill_queue, void* msg) size_t ev42_events::events_in_buffer(const EventMessage* em) { - auto t_len = em->time_of_flight()->Length(); - auto p_len = em->detector_id()->Length(); + auto t_len = em->time_of_flight()->size(); + auto p_len = em->detector_id()->size(); if ((t_len != p_len) || !t_len) return 0; @@ -252,8 +252,8 @@ std::string ev42_events::debug(const EventMessage* em) ss << em->source_name()->str() << " #" << em->message_id() << " time=" << em->pulse_time() - << " tof_size=" << em->time_of_flight()->Length() - << " det_size=" << em->detector_id()->Length(); + << " tof_size=" << em->time_of_flight()->size() + << " det_size=" << em->detector_id()->size(); return ss.str(); } diff --git a/source/producers/ESSStream/f142_parser.cpp b/source/producers/ESSStream/f142_parser.cpp index 80d2db80..71ba49c7 100644 --- a/source/producers/ESSStream/f142_parser.cpp +++ b/source/producers/ESSStream/f142_parser.cpp @@ -36,8 +36,8 @@ StreamManifest ChopperTDC::stream_manifest() const { StreamManifest ret; ret[stream_id_].event_model = event_model_; - ret[stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); return ret; } @@ -60,12 +60,12 @@ void ChopperTDC::settings(const Setting& settings) { std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - stream_id_ = set.find({r + "/EventsStream"}).get_text(); - filter_source_name_ = set.find({r + "/FilterSourceName"}).triggered(); - source_name_ = set.find({r + "/SourceName"}).get_text(); + stream_id_ = set.find(Setting(r + "/EventsStream")).get_text(); + filter_source_name_ = set.find(Setting(r + "/FilterSourceName")).triggered(); + source_name_ = set.find(Setting(r + "/SourceName")).get_text(); TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); event_model_.timebase = tbs.timebase(); } diff --git a/source/producers/ESSStream/mo01_parser.cpp b/source/producers/ESSStream/mo01_parser.cpp index b0f24a05..13cf1f65 100644 --- a/source/producers/ESSStream/mo01_parser.cpp +++ b/source/producers/ESSStream/mo01_parser.cpp @@ -83,15 +83,15 @@ void mo01_nmx::settings(const Setting& settings) std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - hists_stream_id_ = set.find({r + "/HistsStream"}).get_text(); - x_stream_id_ = set.find({r + "/XStream"}).get_text(); - y_stream_id_ = set.find({r + "/YStream"}).get_text(); - hit_stream_id_ = set.find({r + "/HitsStream"}).get_text(); - filter_source_name_ = set.find({r + "/FilterSourceName"}).triggered(); - source_name_ = set.find({r + "/SourceName"}).get_text(); + hists_stream_id_ = set.find(Setting(r + "/HistsStream")).get_text(); + x_stream_id_ = set.find(Setting(r + "/XStream")).get_text(); + y_stream_id_ = set.find(Setting(r + "/YStream")).get_text(); + hit_stream_id_ = set.find(Setting(r + "/HitsStream")).get_text(); + filter_source_name_ = set.find(Setting(r + "/FilterSourceName")).triggered(); + source_name_ = set.find(Setting(r + "/SourceName")).get_text(); TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); hists_model_.timebase = tbs.timebase(); } @@ -99,20 +99,20 @@ StreamManifest mo01_nmx::stream_manifest() const { StreamManifest ret; ret[hists_stream_id_].event_model = hists_model_; - ret[hists_stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[hists_stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); + ret[hists_stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[hists_stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); ret[x_stream_id_].event_model = track_model_; - ret[x_stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[x_stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); + ret[x_stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[x_stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); ret[y_stream_id_].event_model = track_model_; - ret[y_stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[y_stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); + ret[y_stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[y_stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); ret[hit_stream_id_].event_model = hits_model_; - ret[hit_stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::precise)); - ret[hit_stream_id_].stats.branches.add(SettingMeta("dropped_buffers", SettingType::precise)); + ret[hit_stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::precise))); + ret[hit_stream_id_].stats.branches.add(Setting(SettingMeta("dropped_buffers", SettingType::precise))); return ret; } @@ -220,11 +220,11 @@ uint64_t mo01_nmx::process_payload(SpillMultiqueue * spill_queue, void* msg) uint64_t mo01_nmx::produce_hists(const GEMHist& hist, SpillMultiqueue * queue) { - if (!hist.xstrips()->Length() && - !hist.xstrips()->Length() && - !hist.xspectrum()->Length() && - !hist.yspectrum()->Length() && - !hist.cluster_spectrum()->Length()) + if (!hist.xstrips()->size() && + !hist.xstrips()->size() && + !hist.xspectrum()->size() && + !hist.yspectrum()->size() && + !hist.cluster_spectrum()->size()) return 0; auto ret = std::make_shared(hists_stream_id_, Spill::Type::running); @@ -257,13 +257,13 @@ uint64_t mo01_nmx::produce_tracks(const GEMTrack& track, SpillMultiqueue * queue { uint64_t pushed_spills {0}; - if (track.xtrack()->Length()) + if (track.xtrack()->size()) { queue->enqueue(grab_track(track.xtrack(), x_stream_id_)); pushed_spills ++; } - if (track.ytrack()->Length()) + if (track.ytrack()->size()) { queue->enqueue(grab_track(track.ytrack(), y_stream_id_)); pushed_spills ++; @@ -278,9 +278,9 @@ uint64_t mo01_nmx::produce_hits(const MONHit& hits, SpillMultiqueue * queue) spill->state.branches.add(Setting::precise("native_time", spoofed_time_)); spill->state.branches.add(Setting::precise("dropped_buffers", stats.dropped_buffers)); spill->event_model = hits_model_; - spill->events.reserve(hits.plane()->Length(), hits_model_); + spill->events.reserve(hits.plane()->size(), hits_model_); - for (size_t i=0; i < hits.plane()->Length(); ++i) + for (size_t i=0; i < hits.plane()->size(); ++i) { auto& e = spill->events.last(); e.set_time(spoofed_time_ + hits.time()->Get(i)); @@ -292,7 +292,7 @@ uint64_t mo01_nmx::produce_hits(const MONHit& hits, SpillMultiqueue * queue) spill->events.finalize(); - if (hits.plane()->Length()) + if (hits.plane()->size()) { queue->enqueue(spill); return 1; @@ -303,13 +303,13 @@ uint64_t mo01_nmx::produce_hits(const MONHit& hits, SpillMultiqueue * queue) void mo01_nmx::grab_hist(Event& e, size_t idx, const flatbuffers::Vector* data) { - if (!data->Length()) + if (!data->size()) return; -// std::vector vals(data->Length(), 0); +// std::vector vals(data->size(), 0); auto& trace = e.trace(idx); - for (size_t i=0; i < data->Length(); ++i) + for (size_t i=0; i < data->size(); ++i) trace[i] = data->Get(i); -// DBG( "Added hist " << idx << " length " << data->Length(); +// DBG( "Added hist " << idx << " length " << data->size(); } SpillPtr mo01_nmx::grab_track(const flatbuffers::Vector>* data, @@ -320,9 +320,9 @@ SpillPtr mo01_nmx::grab_track(const flatbuffers::Vector ret->state.branches.add(Setting::precise("native_time", spoofed_time_)); ret->state.branches.add(Setting::precise("dropped_buffers", stats.dropped_buffers)); ret->event_model = track_model_; - ret->events.reserve(data->Length(), track_model_); + ret->events.reserve(data->size(), track_model_); - for (size_t i=0; i < data->Length(); ++i) + for (size_t i=0; i < data->size(); ++i) { auto& e = ret->events.last(); e.set_time(spoofed_time_); @@ -340,15 +340,15 @@ SpillPtr mo01_nmx::grab_track(const flatbuffers::Vector std::string mo01_nmx::debug(const GEMHist& hist) { std::stringstream ss; - if (hist.xstrips()->Length()) + if (hist.xstrips()->size()) ss << " strips_x: " << print_hist(hist.xstrips()) << "\n"; - if (hist.ystrips()->Length()) + if (hist.ystrips()->size()) ss << " strips_y: " << print_hist(hist.ystrips()) << "\n"; - if (hist.xspectrum()->Length()) + if (hist.xspectrum()->size()) ss << " adc_x: " << print_hist(hist.xspectrum()) << "\n"; - if (hist.yspectrum()->Length()) + if (hist.yspectrum()->size()) ss << " adc_y: " << print_hist(hist.yspectrum()) << "\n"; - if (hist.cluster_spectrum()->Length()) + if (hist.cluster_spectrum()->size()) ss << " adc_cluster: " << print_hist(hist.cluster_spectrum()) << "\n"; return ss.str(); } @@ -356,7 +356,7 @@ std::string mo01_nmx::debug(const GEMHist& hist) std::string mo01_nmx::print_hist(const flatbuffers::Vector* data) { std::stringstream ss; - for (size_t i=0; i < data->Length(); ++i) + for (size_t i=0; i < data->size(); ++i) ss << " " << data->Get(i); return ss.str(); } @@ -364,9 +364,9 @@ std::string mo01_nmx::print_hist(const flatbuffers::Vector* data) std::string mo01_nmx::debug(const GEMTrack& track) { std::stringstream ss; - if (track.xtrack()->Length()) + if (track.xtrack()->size()) ss << " x: " << print_track(track.xtrack()) << "\n"; - if (track.ytrack()->Length()) + if (track.ytrack()->size()) ss << " y: " << print_track(track.ytrack()) << "\n"; return ss.str(); } @@ -374,7 +374,7 @@ std::string mo01_nmx::debug(const GEMTrack& track) std::string mo01_nmx::print_track(const flatbuffers::Vector>* data) { std::stringstream ss; - for (size_t i=0; i < data->Length(); ++i) + for (size_t i=0; i < data->size(); ++i) { auto element = data->Get(i); ss << "(" << element->strip() diff --git a/source/producers/MockProducer/MockProducer.cpp b/source/producers/MockProducer/MockProducer.cpp index 2614e63f..443aeaa7 100644 --- a/source/producers/MockProducer/MockProducer.cpp +++ b/source/producers/MockProducer/MockProducer.cpp @@ -73,10 +73,10 @@ StreamManifest MockProducer::stream_manifest() const { StreamManifest ret; ret[stream_id_].event_model = event_definition_; - ret[stream_id_].stats.branches.add(SettingMeta("native_time", SettingType::floating)); - ret[stream_id_].stats.branches.add(SettingMeta("live_time", SettingType::floating)); - ret[stream_id_].stats.branches.add(SettingMeta("live_trigger", SettingType::floating)); - ret[stream_id_].stats.branches.add(SettingMeta("pulse_time", SettingType::floating)); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("native_time", SettingType::floating))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("live_time", SettingType::floating))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("live_trigger", SettingType::floating))); + ret[stream_id_].stats.branches.add(Setting(SettingMeta("pulse_time", SettingType::floating))); return ret; } @@ -145,19 +145,19 @@ void MockProducer::settings(const Setting& settings) std::string r{plugin_name()}; auto set = enrich_and_toggle_presets(settings); - stream_id_ = set.find({r + "/StreamID"}).get_text(); - spill_interval_ = set.find({r + "/SpillInterval"}).get_number(); - count_rate_ = set.find({r + "/CountRate"}).get_number(); - lambda_ = set.find({r + "/Lambda"}).get_number(); - spill_lambda_ = set.find({r + "/SpillLambda"}).get_number(); - dead_ = set.find({r + "/DeadTime"}).get_number() * 0.01; + stream_id_ = set.find(Setting(r + "/StreamID")).get_text(); + spill_interval_ = set.find(Setting(r + "/SpillInterval")).get_number(); + count_rate_ = set.find(Setting(r + "/CountRate")).get_number(); + lambda_ = set.find(Setting(r + "/Lambda")).get_number(); + spill_lambda_ = set.find(Setting(r + "/SpillLambda")).get_number(); + dead_ = set.find(Setting(r + "/DeadTime")).get_number() * 0.01; TimeBasePlugin tbs; - tbs.settings(set.find({tbs.plugin_name()})); + tbs.settings(set.find(Setting(tbs.plugin_name()))); event_definition_ = EventModel(); event_definition_.timebase = tbs.timebase(); - uint16_t val_count_ = std::max(int(set.find({r + "/ValueCount"}).get_number()), 1); + uint16_t val_count_ = std::max(int(set.find(Setting(r + "/ValueCount")).get_number()), 1); if (val_defs_.size() != val_count_) val_defs_.resize(val_count_); diff --git a/source/producers/MockProducer/ValueDefinition.cpp b/source/producers/MockProducer/ValueDefinition.cpp index 87ca522a..f8c8306c 100644 --- a/source/producers/MockProducer/ValueDefinition.cpp +++ b/source/producers/MockProducer/ValueDefinition.cpp @@ -69,11 +69,11 @@ void ValueDefinition::settings(const Setting& v) { std::string r{plugin_name()}; - center_ = v.find({r + "/PeakCenter"}).get_number() * 0.01; - spread_ = v.find({r + "/PeakSpread"}).get_number(); - trace_length_ = v.find({r + "/TraceLength"}).get_int(); - name_ = v.find({r + "/Name"}).get_text(); - bits_ = v.find({r + "/Resolution"}).get_int(); + center_ = v.find(Setting(r + "/PeakCenter")).get_number() * 0.01; + spread_ = v.find(Setting(r + "/PeakSpread")).get_number(); + trace_length_ = v.find(Setting(r + "/TraceLength")).get_int(); + name_ = v.find(Setting(r + "/Name")).get_text(); + bits_ = v.find(Setting(r + "/Resolution")).get_int(); max_ = pow(2, uint32_t(bits_)); } diff --git a/tests/core/calibration/CalibrationTest.cpp b/tests/core/calibration/CalibrationTest.cpp index 5406783c..58229f09 100644 --- a/tests/core/calibration/CalibrationTest.cpp +++ b/tests/core/calibration/CalibrationTest.cpp @@ -2,6 +2,7 @@ #include #include #include +#include class CalibID : public TestBase { @@ -72,8 +73,8 @@ TEST_F(CalibID, Json) class FakeFunction : public DAQuiri::CoefFunction { public: - // Inherit constructors - using DAQuiri::CoefFunction::CoefFunction; + using CoefFunction::CoefFunction; + FakeFunction() : DAQuiri::CoefFunction::CoefFunction() {} FakeFunction* clone() const override { return new FakeFunction(*this); } std::string type() const override { return "FakeFunction"; } @@ -201,6 +202,8 @@ TEST_F(Calibration, equals) c.function("Polynomial" , {5.0, 2.0, 1.0}); c2.function("FakeFunction" , {5.0, 2.0, 1.0}); + DBG("c={}", c.debug()); + DBG("c2={}", c2.debug()); EXPECT_NE(c, c2); EXPECT_NE(c2, c); diff --git a/tests/core/calibration/CoefFunctionTest.cpp b/tests/core/calibration/CoefFunctionTest.cpp index 89228e12..9cf70eee 100644 --- a/tests/core/calibration/CoefFunctionTest.cpp +++ b/tests/core/calibration/CoefFunctionTest.cpp @@ -17,8 +17,8 @@ class MockFunction : public DAQuiri::CoefFunction double derivative(double) const override { return 1; } std::string debug() const override { return ""; } - std::string to_UTF8(int precision, bool with_rsq) const override { return ""; } - std::string to_markup(int precision, bool with_rsq) const override { return ""; } + std::string to_UTF8([[maybe_unused]] int precision,[[maybe_unused]] bool with_rsq) const override { return ""; } + std::string to_markup([[maybe_unused]] int precision,[[maybe_unused]] bool with_rsq) const override { return ""; } }; TEST_F(CoefFunction, InitDefault) diff --git a/tests/core/plugin/SettingTest.cpp b/tests/core/plugin/SettingTest.cpp index 8d335eb0..0a4e8644 100644 --- a/tests/core/plugin/SettingTest.cpp +++ b/tests/core/plugin/SettingTest.cpp @@ -1,8 +1,13 @@ #include #include #include +#include "gtest_color_print.h" -TEST(Setting, Init) +class Setting : public TestBase +{ +}; + +TEST_F(Setting, Init) { DAQuiri::Setting s; ASSERT_FALSE(bool(s)); @@ -14,7 +19,7 @@ TEST(Setting, Init) ASSERT_TRUE(bool(s)); } -TEST(Setting, Indices) +TEST_F(Setting, Indices) { DAQuiri::Setting s; s.add_indices({0,1}); @@ -35,7 +40,7 @@ TEST(Setting, Indices) ASSERT_TRUE(s.has_index(4)); } -TEST(Setting, Time) +TEST_F(Setting, Time) { auto t = std::chrono::system_clock::now(); DAQuiri::Setting s("a", t); @@ -46,7 +51,7 @@ TEST(Setting, Time) ASSERT_EQ(s.time(), t); } -TEST(Setting, Duration) +TEST_F(Setting, Duration) { auto t1 = std::chrono::system_clock::now(); std::this_thread::sleep_for(std::chrono::microseconds(1000)); @@ -63,7 +68,7 @@ TEST(Setting, Duration) ASSERT_EQ(s.duration(), d); } -TEST(Setting, Pattern) +TEST_F(Setting, Pattern) { DAQuiri::Pattern p(2, {true, true}); DAQuiri::Setting s("a", p); @@ -74,7 +79,7 @@ TEST(Setting, Pattern) ASSERT_EQ(s.pattern(), p); } -TEST(Setting, Text) +TEST_F(Setting, Text) { auto s = DAQuiri::Setting::text("a", "a"); ASSERT_EQ(s.get_text(), "a"); @@ -82,7 +87,7 @@ TEST(Setting, Text) ASSERT_EQ(s.get_text(), "b"); } -TEST(Setting, Numeric) +TEST_F(Setting, Numeric) { auto s = DAQuiri::Setting::floating("a", 1.23); ASSERT_EQ(s.get_number(), 1.23); @@ -127,7 +132,7 @@ TEST(Setting, Numeric) ASSERT_FALSE(s.triggered()); } -TEST(Setting, Compare) +TEST_F(Setting, Compare) { auto a = DAQuiri::Setting::text("a", "a"); auto b = DAQuiri::Setting::text("b", "b"); @@ -142,6 +147,11 @@ TEST(Setting, Compare) aa.set_text("a"); ASSERT_TRUE(a == aa); ASSERT_FALSE(a != aa); - } +TEST_F(Setting, Print) +{ + auto a = DAQuiri::Setting::text("setting_id", "text_value"); + a.set_indices({3,4}); + MESSAGE() << "\n" << a.debug("", true) << "\n"; +} diff --git a/tests/core/util/CMakeLists.txt b/tests/core/util/CMakeLists.txt index 1bd7bae6..44ed34dd 100644 --- a/tests/core/util/CMakeLists.txt +++ b/tests/core/util/CMakeLists.txt @@ -2,7 +2,6 @@ set(dir ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES ${dir}/bin_hex_print.cpp - ${dir}/compare.cpp ${dir}/h5json.cpp ${dir}/json_file.cpp ${dir}/lexical_extensions.cpp diff --git a/tests/core/util/compare.cpp b/tests/core/util/compare.cpp deleted file mode 100644 index 1d796e92..00000000 --- a/tests/core/util/compare.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "gtest_color_print.h" -#include - -class Compare : public TestBase -{ -}; - -TEST_F(Compare, mid3equal) -{ - EXPECT_EQ(mid(1.0, 1.0, 1.0), 1.0); -} - -TEST_F(Compare, mid3ordered) -{ - EXPECT_EQ(mid(1.0, 2.0, 3.0), 2.0); - EXPECT_EQ(mid(1.0, 2.0, 2.0), 2.0); - EXPECT_EQ(mid(2.0, 2.0, 3.0), 2.0); -} - -TEST_F(Compare, mid3reversed) -{ - EXPECT_EQ(mid(3.0, 2.0, 1.0), 2.0); - EXPECT_EQ(mid(3.0, 2.0, 2.0), 2.0); - EXPECT_EQ(mid(2.0, 2.0, 1.0), 2.0); -} - -TEST_F(Compare, mid3unordered) -{ - EXPECT_EQ(mid(2.0, 3.0, 1.0), 2.0); - EXPECT_EQ(mid(2.0, 3.0, 2.0), 2.0); -} - -TEST_F(Compare, mid3unordered_b) -{ - EXPECT_EQ(mid(2.0, 1.0, 3.0), 2.0); - EXPECT_EQ(mid(2.0, 1.0, 2.0), 2.0); -} - -TEST_F(Compare, mid3unordered_c) -{ - EXPECT_EQ(mid(3.0, 1.0, 2.0), 2.0); -} - -TEST_F(Compare, mid3unordered_d) -{ - EXPECT_EQ(mid(1.0, 3.0, 2.0), 2.0); -} - -TEST_F(Compare, mid3same2a) -{ - EXPECT_EQ(mid(4.0, 3.0, 4.0), 4.0); - EXPECT_EQ(mid(4.0, 5.0, 4.0), 4.0); -} - -TEST_F(Compare, mid3same2b) -{ - EXPECT_EQ(mid(3.0, 4.0, 4.0), 4.0); - EXPECT_EQ(mid(5.0, 4.0, 4.0), 4.0); -} - -TEST_F(Compare, mid3same2c) -{ - EXPECT_EQ(mid(4.0, 4.0, 3.0), 4.0); - EXPECT_EQ(mid(4.0, 4.0, 5.0), 4.0); -} - -TEST_F(Compare, mid3same3) -{ - EXPECT_EQ(mid(4.0, 4.0, 4.0), 4.0); -} diff --git a/tests/gtest_color_print.h b/tests/gtest_color_print.h index a95a11ee..90429d3b 100644 --- a/tests/gtest_color_print.h +++ b/tests/gtest_color_print.h @@ -1,12 +1,10 @@ #pragma once #include -#include +#include -namespace testing { -namespace internal { +namespace testing::internal { -extern void ColoredPrintf(GTestColor color, const char* fmt, ...); -} +extern void ColoredPrintf(GTestColor color, const char* format, ...); } class TestBase : public ::testing::Test @@ -17,8 +15,8 @@ class TestBase : public ::testing::Test public: ~Message() { - std::cout << col(BashColor::GREEN) << "[ ] "; - std::cout << col(BashColor::YELLOW) << str(); + fmt::print(fg(fmt::terminal_color::green), "[ ] "); + fmt::print(fg(fmt::terminal_color::yellow), "{}", str()); } }; #define MESSAGE Message diff --git a/utils/first_build.sh b/utils/first_build.sh index ebba8071..a7c3fa7e 100755 --- a/utils/first_build.sh +++ b/utils/first_build.sh @@ -16,8 +16,6 @@ function detectos() detectos if [[ $SYSTEM == "centos" ]]; then - conan install --build=boost_filesystem --options boost_filesystem:shared=True \ - --options boost_system:shared=True boost_filesystem/1.69.0@bincrafters/stable || exit 1 conan install --build=outdated .. || exit 1 cmake -DCONAN=MANUAL .. elif [[ $SYSTEM == "macos" ]]; then