diff --git a/CMakeLists.txt b/CMakeLists.txt index 91b1518..050667b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ cmake_policy(SET CMP0135 NEW) endif() project(CLIPPy - VERSION 0.2 + VERSION 0.5 DESCRIPTION "Command Line Interface Plus Python" LANGUAGES CXX) @@ -93,25 +93,18 @@ FetchContent_MakeAvailable(Boost) # # JSONLogic -# find_package(jsonlogic QUIET) -# if (NOT jsonlogic_FOUND) -# message(STATUS "jsonlogic not found, doing stuff") - set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic - - FetchContent_Declare(jsonlogic - GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git - GIT_TAG nojson - SOURCE_SUBDIR cpp - ) - # set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic) - FetchContent_MakeAvailable(jsonlogic) - message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}") +set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic - -# else() -# message(STATUS "jsonlogic found, weird") +FetchContent_Declare(jsonlogic + GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git + GIT_TAG v0.2.0 + SOURCE_SUBDIR cpp +) +# set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic) +FetchContent_MakeAvailable(jsonlogic) +message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}") -# endif() + ### Require out-of-source builds file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH) diff --git a/test/TestBag/remove_if.cpp b/test/TestBag/remove_if.cpp index 62b172c..87a8c52 100644 --- a/test/TestBag/remove_if.cpp +++ b/test/TestBag/remove_if.cpp @@ -32,11 +32,12 @@ int main(int argc, char **argv) { // // Expression here - auto apply_jl = [&expression](int value) { + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(expression["rule"]); + + auto apply_jl = [&jlrule](int value) { boostjsn::object data; data["value"] = value; - jsonlogic::any_expr res = jsonlogic::apply(expression["rule"], data); - return jsonlogic::unpack_value(res); + return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data)))); }; the_bag.remove_if(apply_jl); diff --git a/test/TestGraph/where.cpp b/test/TestGraph/where.cpp index d42a13e..47c5034 100644 --- a/test/TestGraph/where.cpp +++ b/test/TestGraph/where.cpp @@ -19,25 +19,17 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression, // boost::json::object submission_data{}; std::vector vars; - jsonlogic::any_expr expression_rule_; // we use expression_rule_ (and expression_rule; see below) in order to avoid // having to recompute this every time we call the lambda. - std::tie(expression_rule_, vars, std::ignore) = - jsonlogic::create_logic(exp2["rule"]); - - // this works around a deficiency in C++ compilers where - // unique pointers moved into a lambda cannot be moved into - // an std::function. - jsonlogic::expr* rawexpr = expression_rule_.release(); - std::shared_ptr expression_rule{rawexpr}; + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(exp2["rule"]); std::cerr << "parse_where: # of vars: " << vars.size() << std::endl; for (const auto& var : vars) { std::cerr << " apply_jl var dump: var: " << var << std::endl; } - auto apply_jl = [&expression, vars, expression_rule, &mvmap_, + auto apply_jl = [rule=std::move(jlrule), vars, &mvmap_, &submission_data](mvmap::locator loc) mutable { std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl; for (const auto& var : vars) { @@ -74,10 +66,9 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression, } std::cerr << " apply_jl: submission_data: " << submission_data << std::endl; - jsonlogic::any_expr res = jsonlogic::apply( - *expression_rule, jsonlogic::data_accessor(submission_data)); + jsonlogic::any_value res = rule.apply(jsonlogic::json_accessor(submission_data)); std::cerr << " apply_jl: res: " << res << std::endl; - return jsonlogic::unpack_value(res); + return truthy(res); }; return apply_jl; @@ -146,4 +137,4 @@ std::vector where_nodes(const testgraph::testgraph& g, }); return filtered_results; -} \ No newline at end of file +} diff --git a/test/TestSet/remove_if.cpp b/test/TestSet/remove_if.cpp index 28b69ea..15122c7 100644 --- a/test/TestSet/remove_if.cpp +++ b/test/TestSet/remove_if.cpp @@ -28,13 +28,13 @@ int main(int argc, char **argv) { auto expression = clip.get("expression"); auto the_set = clip.get_state>(state_name); + // // // Expression here - auto apply_jl = [&expression](int value) { - boostjsn::object data; - data["value"] = value; - jsonlogic::any_expr res = jsonlogic::apply(expression["rule"], data); - return jsonlogic::unpack_value(res); + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(expression["rule"]); + + auto apply_jl = [&jlrule](int value) { + return truthy(jlrule.apply(jsonlogic::json_accessor({{"value", value}}))); }; for (auto first = the_set.begin(), last = the_set.end(); first != last;) {