Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions test/TestBag/remove_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(res);
return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data))));
};

the_bag.remove_if(apply_jl);
Expand Down
19 changes: 5 additions & 14 deletions test/TestGraph/where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,17 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression,

// boost::json::object submission_data{};
std::vector<boost::json::string> 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<jsonlogic::expr> 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) {
Expand Down Expand Up @@ -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<bool>(res);
return truthy(res);
};

return apply_jl;
Expand Down Expand Up @@ -146,4 +137,4 @@ std::vector<testgraph::node_t> where_nodes(const testgraph::testgraph& g,
});

return filtered_results;
}
}
10 changes: 5 additions & 5 deletions test/TestSet/remove_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ int main(int argc, char **argv) {
auto expression = clip.get<boostjsn::object>("expression");
auto the_set = clip.get_state<std::set<int>>(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<bool>(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;) {
Expand Down
Loading