From 4f2d6a3db729248bbd9fccec9813b645a6d42151 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 22 Oct 2019 22:15:20 -0400 Subject: [PATCH] Revert "Add json.hpp." This reverts commit a007a41b0deb780eb5e923c3af5fe71e0c1339df. --- include/json.hpp | 139 ----------------------------------------------- include/rack.hpp | 1 - 2 files changed, 140 deletions(-) delete mode 100644 include/json.hpp diff --git a/include/json.hpp b/include/json.hpp deleted file mode 100644 index f6491435..00000000 --- a/include/json.hpp +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once -#include -#include - - -namespace rack { - - -/** JSON helpers */ -namespace json { - - -/** Checks that a JSON type can be cast to the C++ type */ -template -bool is(json_t* valueJ); -template <> -inline bool is(json_t* valueJ) { - return json_is_string(valueJ); -} -template <> -inline bool is(json_t* valueJ) { - return json_is_integer(valueJ); -} -template <> -inline bool is(json_t* valueJ) { - return json_is_integer(valueJ); -} -template <> -inline bool is(json_t* valueJ) { - return json_is_number(valueJ); -} -template <> -inline bool is(json_t* valueJ) { - return json_is_number(valueJ); -} -template <> -inline bool is(json_t* valueJ) { - return json_is_boolean(valueJ); -} - -/** Converts C++ types to the JSON type */ -template -json_t* to(T value); -template <> -inline json_t* to(const std::string& value) { - return json_stringn(value.c_str(), value.size()); -} -template <> -inline json_t* to(json_int_t value) { - return json_integer(value); -} -template <> -inline json_t* to(int value) { - return json_integer(value); -} -template <> -inline json_t* to(double value) { - return json_real(value); -} -template <> -inline json_t* to(float value) { - return json_real(value); -} -template <> -inline json_t* to(bool value) { - return json_boolean(value); -} - -/** Converts the JSON type to C++ types */ -template -T from(json_t* valueJ); -template <> -inline std::string from(json_t* valueJ) { - return std::string(json_string_value(valueJ), json_string_length(valueJ)); -} -template <> -inline json_int_t from(json_t* valueJ) { - return json_integer_value(valueJ); -} -template <> -inline int from(json_t* valueJ) { - return json_integer_value(valueJ); -} -template <> -inline double from(json_t* valueJ) { - return json_number_value(valueJ); -} -template <> -inline float from(json_t* valueJ) { - return json_number_value(valueJ); -} -template <> -inline bool from(json_t* valueJ) { - return json_boolean_value(valueJ); -} - -/** Helper template function for array functions */ -inline int multiplyDims() { - return 1; -} -template -int multiplyDims(int dim, Dims... dims) { - return dim * multiplyDims(dims...); -} - -/** Converts a C++ array to a JSON multidimensional array */ -template -json_t* toArray(const T* x) { - return to(*x); -} -template -json_t* toArray(const T* x, int dim, Dims... dims) { - int stride = multiplyDims(dims...); - json_t* arrayJ = json_array(); - for (int i = 0; i < dim; i++) { - json_array_insert_new(arrayJ, i, toArray(&x[i * stride], dims...)); - } - return arrayJ; -} - -/** Converts a JSON multidimensional array to a C++ array */ -template -void fromArray(json_t* arrayJ, T* x) { - *x = from(arrayJ); -} -template -void fromArray(json_t* arrayJ, T* x, int dim, Dims... dims) { - int stride = multiplyDims(dims...); - for (int i = 0; i < dim; i++) { - json_t* elJ = json_array_get(arrayJ, i); - if (elJ) { - fromArray(elJ, &x[i * stride], dims...); - } - } -} - - -} // namespace json -} // namespace rack diff --git a/include/rack.hpp b/include/rack.hpp index f8f652cf..d590dbaa 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include