diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt index ff0627c..88a6c09 100644 --- a/cpp/examples/CMakeLists.txt +++ b/cpp/examples/CMakeLists.txt @@ -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 diff --git a/cpp/examples/ExampleBag/insert.cpp b/cpp/examples/ExampleBag/insert.cpp index b84cbd8..afbb901 100644 --- a/cpp/examples/ExampleBag/insert.cpp +++ b/cpp/examples/ExampleBag/insert.cpp @@ -6,7 +6,6 @@ #include "clippy/clippy.hpp" #include -static const std::string class_name = "ExampleBag"; static const std::string method_name = "insert"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleBag/remove.cpp b/cpp/examples/ExampleBag/remove.cpp index 450f53e..d4b5dcd 100644 --- a/cpp/examples/ExampleBag/remove.cpp +++ b/cpp/examples/ExampleBag/remove.cpp @@ -6,10 +6,8 @@ #include "clippy/clippy.hpp" #include #include -#include -#include -namespace boostjsn = boost::json; +#include static const std::string method_name = "remove"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleBag/remove_if.cpp b/cpp/examples/ExampleBag/remove_if.cpp index c2ed32b..702900a 100644 --- a/cpp/examples/ExampleBag/remove_if.cpp +++ b/cpp/examples/ExampleBag/remove_if.cpp @@ -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"; diff --git a/cpp/examples/ExampleBag/size.cpp b/cpp/examples/ExampleBag/size.cpp index 2ab35ab..36e68e8 100644 --- a/cpp/examples/ExampleBag/size.cpp +++ b/cpp/examples/ExampleBag/size.cpp @@ -6,9 +6,6 @@ #include "clippy/clippy.hpp" #include #include -#include - -namespace boostjsn = boost::json; static const std::string method_name = "size"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleGraph/__init__.cpp b/cpp/examples/ExampleGraph/__init__.cpp index 5b8f8c0..adab98d 100644 --- a/cpp/examples/ExampleGraph/__init__.cpp +++ b/cpp/examples/ExampleGraph/__init__.cpp @@ -7,8 +7,6 @@ #include "examplegraph.hpp" #include -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"; diff --git a/cpp/examples/ExampleGraph/__str__.cpp b/cpp/examples/ExampleGraph/__str__.cpp index 7a6a895..d18678f 100644 --- a/cpp/examples/ExampleGraph/__str__.cpp +++ b/cpp/examples/ExampleGraph/__str__.cpp @@ -8,8 +8,6 @@ #include #include -namespace boostjsn = boost::json; - static const std::string method_name = "__str__"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleGraph/add.cpp b/cpp/examples/ExampleGraph/add.cpp index 481b290..3735f36 100644 --- a/cpp/examples/ExampleGraph/add.cpp +++ b/cpp/examples/ExampleGraph/add.cpp @@ -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"}; diff --git a/cpp/examples/ExampleGraph/add_edge.cpp b/cpp/examples/ExampleGraph/add_edge.cpp index 18a11b2..1faebb9 100644 --- a/cpp/examples/ExampleGraph/add_edge.cpp +++ b/cpp/examples/ExampleGraph/add_edge.cpp @@ -7,8 +7,6 @@ #include "examplegraph.hpp" #include -namespace boostjsn = boost::json; - static const std::string method_name = "add_edge"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleGraph/add_node.cpp b/cpp/examples/ExampleGraph/add_node.cpp index b03638d..95361f7 100644 --- a/cpp/examples/ExampleGraph/add_node.cpp +++ b/cpp/examples/ExampleGraph/add_node.cpp @@ -7,8 +7,6 @@ #include "examplegraph.hpp" #include -namespace boostjsn = boost::json; - static const std::string method_name = "add_node"; static const std::string state_name = "INTERNAL"; diff --git a/cpp/examples/ExampleGraph/add_series.cpp b/cpp/examples/ExampleGraph/add_series.cpp index 9c58ff0..58d5ade 100644 --- a/cpp/examples/ExampleGraph/add_series.cpp +++ b/cpp/examples/ExampleGraph/add_series.cpp @@ -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"; diff --git a/cpp/examples/ExampleGraph/assign.cpp b/cpp/examples/ExampleGraph/assign.cpp index 9e958d4..1babf9d 100644 --- a/cpp/examples/ExampleGraph/assign.cpp +++ b/cpp/examples/ExampleGraph/assign.cpp @@ -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; diff --git a/cpp/examples/ExampleGraph/connected_components.cpp b/cpp/examples/ExampleGraph/connected_components.cpp index cb8c6f9..ae586d3 100644 --- a/cpp/examples/ExampleGraph/connected_components.cpp +++ b/cpp/examples/ExampleGraph/connected_components.cpp @@ -91,10 +91,10 @@ int main(int argc, char **argv) { std::vector 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 q; - q.push(i); + q.push(int64_t(i)); while (!q.empty()) { int64_t v = q.front(); q.pop(); diff --git a/cpp/examples/ExampleGraph/copy_series.cpp b/cpp/examples/ExampleGraph/copy_series.cpp index 922760b..69bcbef 100644 --- a/cpp/examples/ExampleGraph/copy_series.cpp +++ b/cpp/examples/ExampleGraph/copy_series.cpp @@ -6,14 +6,11 @@ #include #include #include -#include #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"; diff --git a/cpp/examples/ExampleGraph/count.cpp b/cpp/examples/ExampleGraph/count.cpp index e5ee5db..6d33b16 100644 --- a/cpp/examples/ExampleGraph/count.cpp +++ b/cpp/examples/ExampleGraph/count.cpp @@ -8,14 +8,12 @@ #include #include #include -#include #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, diff --git a/cpp/examples/ExampleGraph/mvmap.hpp b/cpp/examples/ExampleGraph/mvmap.hpp index 2643888..185781a 100644 --- a/cpp/examples/ExampleGraph/mvmap.hpp +++ b/cpp/examples/ExampleGraph/mvmap.hpp @@ -1,13 +1,11 @@ #pragma once #include -// #include #include #include #include #include #include #include -#include #include #include #include @@ -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 /*unused*/, - const boost::json::value &v) { +inline locator tag_invoke(boost::json::value_to_tag /*unused*/, + const boost::json::value &v) { return boost::json::value_to(v); } template @@ -174,14 +172,14 @@ class mvmap { for (auto el : series_r) { f(itk_r[el.first], locator(el.first), el.second); } - }; + } template 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 @@ -196,7 +194,7 @@ class mvmap { for (auto ltd : indices_to_delete) { erase(locator(ltd)); } - }; + } void erase(const locator &l) { auto i = l.loc; diff --git a/cpp/include/clippy/clippy-object.hpp b/cpp/include/clippy/clippy-object.hpp index d000371..e180e0c 100644 --- a/cpp/include/clippy/clippy-object.hpp +++ b/cpp/include/clippy/clippy-object.hpp @@ -8,39 +8,33 @@ #include 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 - void append_json(JsonType obj) - { - data.emplace_back(std::move(obj).json()); - } - template - 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 void append_json(JsonType obj) { + data.emplace_back(std::move(obj).json()); + } + + template 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; @@ -74,5 +68,4 @@ namespace clippy { private: json_type data; }; -} - + } // namespace clippy diff --git a/cpp/include/clippy/clippy.hpp b/cpp/include/clippy/clippy.hpp index 60322d3..6e8cb78 100644 --- a/cpp/include/clippy/clippy.hpp +++ b/cpp/include/clippy/clippy.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -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> @@ -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> &value) { +inline void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, + const std::vector> &value) { auto &outer_array = jv.emplace_array(); outer_array.resize(value.size()); @@ -517,9 +516,9 @@ void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, } } -std::vector> tag_invoke( - boost::json::value_to_tag>>, - const boost::json::value &jv) { +inline std::vector> +tag_invoke(boost::json::value_to_tag>>, + const boost::json::value &jv) { std::vector> value; auto &outer_array = jv.get_array(); @@ -532,8 +531,9 @@ std::vector> tag_invoke( return value; } -void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, - const std::vector> &value) { +inline void +tag_invoke(boost::json::value_from_tag, boost::json::value &jv, + const std::vector> &value) { auto &outer_array = jv.emplace_array(); outer_array.resize(value.size()); @@ -545,7 +545,7 @@ void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, } } -std::vector> tag_invoke( +inline std::vector> tag_invoke( boost::json::value_to_tag>>, const boost::json::value &jv) { std::vector> value; diff --git a/cpp/include/clippy/selector.hpp b/cpp/include/clippy/selector.hpp index af198ab..d475bb9 100644 --- a/cpp/include/clippy/selector.hpp +++ b/cpp/include/clippy/selector.hpp @@ -1,7 +1,6 @@ #pragma once -#include + #include -#include #include "boost/json.hpp" @@ -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 /*unused*/, - const boost::json::value &v) { +inline selector tag_invoke(boost::json::value_to_tag /*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 o {}; - // o["expression_type"] = "jsonlogic"; - // o["rule"] = {{"var", sel.sel_str}}; - // v = {"expression_type": "jsonlogic", "rule": {"var": - // "node.degree"}}}sel.sel_str; -} \ No newline at end of file +// 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 o {}; +// o["expression_type"] = "jsonlogic"; +// o["rule"] = {{"var", sel.sel_str}}; +// v = {"expression_type": "jsonlogic", "rule": {"var": +// "node.degree"}}}sel.sel_str; +//} \ No newline at end of file