From c5169863e1ec3060d3bdc3b8c0317710ce8c3ee3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Dec 2022 20:54:29 +0200 Subject: [PATCH] Use std::function instead of sigc::slot in BooleanEvaluator --- source/booleanevaluator.cpp | 8 ++++---- source/booleanevaluator.h | 8 ++++---- source/conditionalloader.cpp | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/booleanevaluator.cpp b/source/booleanevaluator.cpp index 0103741..074956a 100644 --- a/source/booleanevaluator.cpp +++ b/source/booleanevaluator.cpp @@ -5,8 +5,8 @@ using namespace std; /* I'd rather have overloads with different slots, but that creates an ambiguity because slots have template constructors. */ -BooleanEvaluator::BooleanEvaluator(const Slot &s, bool allow_compare): - slot(s), +BooleanEvaluator::BooleanEvaluator(const Function &f, bool allow_compare): + func(f), ops(allow_compare ? "&|!=^" : "&|!") { } @@ -31,7 +31,7 @@ bool BooleanEvaluator::evaluate(const string &str) op_stack.pop_back(); string var = var_stack.back(); var_stack.pop_back(); - bool value = (slot(var, &buf) == (op=='=')); + bool value = (func(var, &buf) == (op=='=')); value_stack.push_back(value); } else @@ -81,7 +81,7 @@ bool BooleanEvaluator::pop_value() { string var = var_stack.back(); var_stack.pop_back(); - return slot(var, 0); + return func(var, 0); } else if(!value_stack.empty()) { diff --git a/source/booleanevaluator.h b/source/booleanevaluator.h index 08ed432..7c2af6f 100644 --- a/source/booleanevaluator.h +++ b/source/booleanevaluator.h @@ -1,17 +1,17 @@ #ifndef BOOLEANEVALUATOR_H_ #define BOOLEANEVALUATOR_H_ +#include #include #include -#include class BooleanEvaluator { public: - typedef sigc::slot Slot; + using Function = std::function; private: - Slot slot; + Function func; std::string ops; std::vector var_stack; std::vector value_stack; @@ -19,7 +19,7 @@ private: bool last_was_op; public: - BooleanEvaluator(const Slot &, bool = true); + BooleanEvaluator(const Function &, bool = true); bool evaluate(const std::string &); private: diff --git a/source/conditionalloader.cpp b/source/conditionalloader.cpp index 43e613b..731c559 100644 --- a/source/conditionalloader.cpp +++ b/source/conditionalloader.cpp @@ -16,7 +16,8 @@ ArchitectureConditional::ArchitectureConditional(const Builder &b, const string void ArchitectureConditional::if_arch(const string &cond) { - BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&builder.get_current_arch(), &Architecture::match_name)), false); + const Architecture &arch = builder.get_current_arch(); + BooleanEvaluator eval([&arch](const string &value, const string *){ return arch.match_name(value); }, false); bool match = eval.evaluate(cond); builder.get_logger().log("configure", format("%s: arch %s %smatched", log_prefix, cond, (match ? "" : "not "))); if(match) @@ -33,7 +34,7 @@ FeatureConditional::FeatureConditional(const SourcePackage &p, const string &l): void FeatureConditional::if_feature(const string &cond) { - BooleanEvaluator eval(sigc::mem_fun(&package, &SourcePackage::match_feature)); + BooleanEvaluator eval([this](const string &feat, const string *value){ return package.match_feature(feat, value); }); bool match = eval.evaluate(cond); package.get_builder().get_logger().log("configure", format("%s: feature %s %smatched", log_prefix, cond, (match ? "" : "not "))); if(match) -- 2.43.0