Skip to content
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
1 change: 1 addition & 0 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function ( add_test class_name method_name )
set(target "${class_name}_${method_name}")
add_executable(${target} ${source})
# target_include_directories(${target} PRIVATE ${Boost_INCLUDE_DIRS})
target_compile_options(${target} PRIVATE -Wall -Wextra -pedantic)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} include/)
set_target_properties(${target} PROPERTIES OUTPUT_NAME "${method_name}" )
target_include_directories(${target} PRIVATE
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/ExampleBag/insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "clippy/clippy.hpp"
#include <boost/json.hpp>

static const std::string class_name = "ExampleBag";
static const std::string method_name = "insert";
static const std::string state_name = "INTERNAL";

Expand Down
4 changes: 1 addition & 3 deletions cpp/examples/ExampleBag/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
#include "clippy/clippy.hpp"
#include <algorithm>
#include <boost/json.hpp>
#include <iostream>
#include <list>

namespace boostjsn = boost::json;
#include <list>

static const std::string method_name = "remove";
static const std::string state_name = "INTERNAL";
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/ExampleBag/remove_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace boostjsn = boost::json;

static const std::string class_name = "nClippyExample";
static const std::string method_name = "remove_if";
static const std::string state_name = "INTERNAL";

Expand Down
3 changes: 0 additions & 3 deletions cpp/examples/ExampleBag/size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "clippy/clippy.hpp"
#include <boost/json.hpp>
#include <cassert>
#include <iostream>

namespace boostjsn = boost::json;

static const std::string method_name = "size";
static const std::string state_name = "INTERNAL";
Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/__init__.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "examplegraph.hpp"
#include <boost/json.hpp>

namespace boostjsn = boost::json;

static const std::string method_name = "__init__";
static const std::string state_name = "INTERNAL";
static const std::string sel_state_name = "selectors";
Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/__str__.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <boost/json.hpp>
#include <iostream>

namespace boostjsn = boost::json;

static const std::string method_name = "__str__";
static const std::string state_name = "INTERNAL";

Expand Down
1 change: 0 additions & 1 deletion cpp/examples/ExampleGraph/add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace boostjsn = boost::json;

static const std::string method_name = "add";
static const std::string state_name = "INTERNAL";

int main(int argc, char **argv) {
clippy::clippy clip{method_name, "Adds a subselector"};
Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/add_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "examplegraph.hpp"
#include <boost/json.hpp>

namespace boostjsn = boost::json;

static const std::string method_name = "add_edge";
static const std::string state_name = "INTERNAL";

Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/add_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "examplegraph.hpp"
#include <boost/json.hpp>

namespace boostjsn = boost::json;

static const std::string method_name = "add_node";
static const std::string state_name = "INTERNAL";

Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/add_series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "clippy/selector.hpp"
#include "examplegraph.hpp"

namespace boostjsn = boost::json;

static const std::string method_name = "add_series";
static const std::string graph_state_name = "INTERNAL";
static const std::string sel_state_name = "selectors";
Expand Down
3 changes: 2 additions & 1 deletion cpp/examples/ExampleGraph/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ int main(int argc, char **argv) {

boost::json::object submission_data;

std::cerr << "val = " << val << ", val.kind() = " << val.kind() << std::endl;
// std::cerr << "val = " << val << ", val.kind() = " << val.kind() <<
// std::endl;
if (is_node_sel) {
if (the_graph.has_node_series(subsel)) {
std::cerr << "Selector already populated" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions cpp/examples/ExampleGraph/connected_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ int main(int argc, char **argv) {
std::vector<int64_t> components(the_graph.nv());
std::iota(components.begin(), components.end(), 0);

for (int64_t i = 0; i < the_graph.nv(); ++i) {
for (size_t i = 0; i < the_graph.nv(); ++i) {
if (!visited[i]) {
std::queue<int64_t> q;
q.push(i);
q.push(int64_t(i));
while (!q.empty()) {
int64_t v = q.front();
q.pop();
Expand Down
3 changes: 0 additions & 3 deletions cpp/examples/ExampleGraph/copy_series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
#include <boost/json.hpp>
#include <cassert>
#include <iostream>
#include <variant>

#include "clippy/clippy.hpp"
#include "clippy/selector.hpp"
#include "examplegraph.hpp"

namespace boostjsn = boost::json;

static const std::string method_name = "copy_series";
static const std::string graph_state_name = "INTERNAL";
static const std::string sel_state_name = "selectors";
Expand Down
2 changes: 0 additions & 2 deletions cpp/examples/ExampleGraph/count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#include <clippy/clippy.hpp>
#include <iostream>
#include <jsonlogic/src.hpp>
#include <variant>

#include "clippy/selector.hpp"
#include "examplegraph.hpp"

static const std::string method_name = "count";
static const std::string state_name = "INTERNAL";
static const std::string sel_state_name = "selectors";

int main(int argc, char **argv) {
clippy::clippy clip{method_name,
Expand Down
16 changes: 7 additions & 9 deletions cpp/examples/ExampleGraph/mvmap.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once
#include <boost/json.hpp>
// #include <boost/json/conversion.hpp>
#include <boost/json/src.hpp>
#include <cstdint>
#include <iostream>
#include <map>
#include <optional>
#include <ranges>
#include <set>
#include <string>
#include <utility>
#include <variant>
Expand Down Expand Up @@ -53,13 +51,13 @@ class locator {
}
}
};
void tag_invoke(boost::json::value_from_tag /*unused*/, boost::json::value &v,
locator l) {
inline void tag_invoke(boost::json::value_from_tag /*unused*/,
boost::json::value &v, locator l) {
v = l.loc;
}

locator tag_invoke(boost::json::value_to_tag<locator> /*unused*/,
const boost::json::value &v) {
inline locator tag_invoke(boost::json::value_to_tag<locator> /*unused*/,
const boost::json::value &v) {
return boost::json::value_to<index>(v);
}
template <typename K, typename... Vs>
Expand Down Expand Up @@ -174,14 +172,14 @@ class mvmap {
for (auto el : series_r) {
f(itk_r[el.first], locator(el.first), el.second);
}
};
}

template <typename F>
void for_all(F f) const {
for (auto el : series_r) {
f(itk_r[el.first], locator(el.first), el.second);
}
};
}

// F takes (K key, locator, V value)
template <typename F>
Expand All @@ -196,7 +194,7 @@ class mvmap {
for (auto ltd : indices_to_delete) {
erase(locator(ltd));
}
};
}

void erase(const locator &l) {
auto i = l.loc;
Expand Down
61 changes: 27 additions & 34 deletions cpp/include/clippy/clippy-object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,33 @@
#include <boost/json.hpp>

namespace clippy {
class object;
class array;

struct array {
using json_type = ::boost::json::array;

array() = default;
~array() = default;
array(const array&) = default;
array(array&&) = default;
array& operator=(const array&) = default;
array& operator=(array&&) = default;

template <class JsonType>
void append_json(JsonType obj)
{
data.emplace_back(std::move(obj).json());
}

template <class T>
void append_val(T obj)
{
data.emplace_back(std::move(obj));
}

json_type& json() & { return data; }
const json_type& json() const & { return data; }
json_type&& json() && { return std::move(data); }

private:
json_type data;
};

struct array {
using json_type = ::boost::json::array;

array() = default;
~array() = default;
array(const array &) = default;
array(array &&) = default;
array &operator=(const array &) = default;
array &operator=(array &&) = default;

template <class JsonType> void append_json(JsonType obj) {
data.emplace_back(std::move(obj).json());
}

template <class T> void append_val(T obj) {
data.emplace_back(std::move(obj));
}

json_type &json() & { return data; }
const json_type &json() const & { return data; }
json_type &&json() && { return std::move(data); }

private:
json_type data;
};

struct object {
using json_type = ::boost::json::object;

Expand Down Expand Up @@ -74,5 +68,4 @@ namespace clippy {
private:
json_type data;
};
}

} // namespace clippy
20 changes: 10 additions & 10 deletions cpp/include/clippy/clippy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <utility>
Expand Down Expand Up @@ -487,7 +486,7 @@ class clippy {
boost::json::object m_json_overwrite_args;
bool m_returns_self = false;

boost::json::object *m_json_input_state = nullptr;
// boost::json::object *m_json_input_state = nullptr;
size_t m_next_position = 0;

std::map<std::string, std::function<void(const boost::json::value &)>>
Expand All @@ -504,8 +503,8 @@ class clippy {
} // namespace clippy

namespace boost::json {
void tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
const std::vector<std::pair<int, int>> &value) {
inline void tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
const std::vector<std::pair<int, int>> &value) {
auto &outer_array = jv.emplace_array();
outer_array.resize(value.size());

Expand All @@ -517,9 +516,9 @@ void tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
}
}

std::vector<std::pair<int, int>> tag_invoke(
boost::json::value_to_tag<std::vector<std::pair<int, int>>>,
const boost::json::value &jv) {
inline std::vector<std::pair<int, int>>
tag_invoke(boost::json::value_to_tag<std::vector<std::pair<int, int>>>,
const boost::json::value &jv) {
std::vector<std::pair<int, int>> value;

auto &outer_array = jv.get_array();
Expand All @@ -532,8 +531,9 @@ std::vector<std::pair<int, int>> tag_invoke(
return value;
}

void tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
const std::vector<std::pair<std::string, std::string>> &value) {
inline void
tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
const std::vector<std::pair<std::string, std::string>> &value) {
auto &outer_array = jv.emplace_array();
outer_array.resize(value.size());

Expand All @@ -545,7 +545,7 @@ void tag_invoke(boost::json::value_from_tag, boost::json::value &jv,
}
}

std::vector<std::pair<std::string, std::string>> tag_invoke(
inline std::vector<std::pair<std::string, std::string>> tag_invoke(
boost::json::value_to_tag<std::vector<std::pair<std::string, std::string>>>,
const boost::json::value &jv) {
std::vector<std::pair<std::string, std::string>> value;
Expand Down
28 changes: 14 additions & 14 deletions cpp/include/clippy/selector.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <deque>

#include <iostream>
#include <ranges>

#include "boost/json.hpp"

Expand Down Expand Up @@ -49,22 +48,23 @@ class selector {
}
};

std::ostream &operator<<(std::ostream &os, const selector &sel) {
inline std::ostream &operator<<(std::ostream &os, const selector &sel) {
os << sel.sel_str;
return os;
}

selector tag_invoke(boost::json::value_to_tag<selector> /*unused*/,
const boost::json::value &v) {
inline selector tag_invoke(boost::json::value_to_tag<selector> /*unused*/,
const boost::json::value &v) {
return v.as_object();
}

void tag_invoke(boost::json::value_from_tag /*unused*/, boost::json::value &v,
const selector &sel) {
std::cerr << "This should not be called." << std::endl;
// std::map<std::string, std::string> o {};
// o["expression_type"] = "jsonlogic";
// o["rule"] = {{"var", sel.sel_str}};
// v = {"expression_type": "jsonlogic", "rule": {"var":
// "node.degree"}}}sel.sel_str;
}
// void tag_invoke([[maybe_unused]] boost::json::value_from_tag /*unused*/,
// [[maybe_unused]] boost::json::value &v,
// [[maybe_unused]] const selector &sel /*unused*/) {
// std::cerr << "This should not be called." << std::endl;
// std::map<std::string, std::string> o {};
// o["expression_type"] = "jsonlogic";
// o["rule"] = {{"var", sel.sel_str}};
// v = {"expression_type": "jsonlogic", "rule": {"var":
// "node.degree"}}}sel.sel_str;
//}
Loading