Commit Graph

948 Commits

Author SHA1 Message Date
Evan Driscoll
494be1c445 Refactor: rename the register_style overloads
I really really wanted to name these the same and overload them,
but I couldn't get the metaprogramming to work right. Here's a
comment I wrote that describes the problems and what I *planned*
to do:

// What we want is the register_style overloads below. I chose to
// keep them with the same name. But there are two problems with
// that. First, because I need to wrap them in a std::function
// when promoting to two arguments, I want to make register_style
// themselves take the function parameter by a template argument
// so it doesn't get type-erased "twice" (with two virtual
// calls). But then that means that both versions would have the
// generic signature "template <typename Predicate>
// ... (Predicate, style)" and that would lead to ambiguous calls.
//
// The second problem is that ever if you keep the first parameter
// a std::function, because 'json_pointer' is implicitly
// convertible to a 'json', if you rely on the implicit conversion
// to std::function then you'd get an ambugious call.
//
// So what we want is, using Concept terms:
//
//    template <JsonCallable Predicate> ... (Predicate, style)
//    template <JsonPointerCallable Predicate> ... (Predicate, style)
//
// where JsonCallable is additionally *not*
// JsonPointerCallable. The following is my attempt to get that.

I then wrote some code that is similar to this:

    #include <functional>

    struct Main {};
    struct Secondary { Secondary(Main); };

    // http://en.cppreference.com/w/cpp/types/void_t
    template<typename... Ts> struct make_void { typedef void type;};
    template<typename... Ts> using void_t = typename make_void<Ts...>::type;

    template <typename, typename = void>
    struct can_be_called_with_main : std::false_type { };

    template <typename T>
    struct can_be_called_with_main<
        T,
        void_t<decltype(std::declval<T>()(std::declval<Main>()))>
    >: std::true_type { };

    template <typename, typename = void>
    struct can_be_called_with_secondary : std::false_type { };

    template <typename T>
    struct can_be_called_with_secondary<
        T,
        void_t<decltype(std::declval<T>()(std::declval<Secondary>()))>
    >: std::true_type { };

    template <typename Functor>
    auto
    func(Functor f)
    -> typename std::enable_if<can_be_called_with_main<Functor>::value, int>::type
    {
        return 0;
    }

    template <typename Functor>
    auto
    func(Functor f)
    -> typename std::enable_if<
            can_be_called_with_secondary<Functor>::value
            && !can_be_called_with_main<Functor>::value
            , int>::type
    {
        return 0;
    }

    auto x1 = func([] (Main) {});
    auto x2 = func([] (Secondary) {});

where Main is like 'json' and Secondary like 'json_pointer'.

Problem is it doesn't work -- in the SFIANE context, it looks like
predicates of both `bool (json)` and `bool (json_pointer)` are callable
with both json and json_pointer objects.

In the case of `bool (json)` being called with a 'json_pointer', that
is via the implicit conversion discussed in the comment above. In the
caes of `bool (json_pointer)` being called with a `json`, my guess
as to what is going on is that `json` provides an implicit to-anything
conversion, which uses a `from_json` function. However, that isn't
implemented in a SFIANE-friendly way -- when you try to actually make
that conversion, there's a static_assert failure.

An alternative approach would be to extract the first argument to
the provided predicate via some technique like those described in
https://functionalcpp.wordpress.com/2013/08/05/function-traits/,
and then is_same them vs json and json_pointer.
2018-06-04 22:28:58 -05:00
Evan Driscoll
edb6b25569 Fancy printer predicate now takes current JSON object
The API is ugly at the moment. Will fix with an ugly
implementation soon.
2018-06-04 21:59:21 -05:00
Evan Driscoll
c7a64b8846 Example of more powerful matcher being useful 2018-06-03 22:41:42 -05:00
Evan Driscoll
5f0870ef34 Expose the matcher predicate from fancy stylizer 2018-06-03 22:26:55 -05:00
Evan Driscoll
91971e394f Provide accessors into json_pointer 2018-06-03 21:52:28 -05:00
Evan Driscoll
860661987f Spaces after commas (in [1, 2]) is controllable separately from multiline 2018-06-03 00:02:49 -05:00
Evan Driscoll
e7b02c10dd Spaces after a colon (in {"k": v}) controllable separately from multiline 2018-06-03 00:00:12 -05:00
Evan Driscoll
ec756e47ad Refactor: don't indent when multiline is false 2018-06-02 23:52:30 -05:00
Evan Driscoll
af8dd92a0c Refactor: introduce explicit multiline control
Instead of depending on indent_step
2018-06-02 23:48:26 -05:00
Evan Driscoll
ef679f8988 Fancy serializer: styles continue to propagate if not overridden
This is half a bug fix half just continuing work from befor
2018-06-02 23:17:42 -05:00
Evan Driscoll
186c7df25a Can style subobjects of a object differently, by key 2018-06-02 23:10:28 -05:00
Evan Driscoll
28e7eecf33 Fancy serializer can limit recursion depth
Elides objects with ... if that limit is exceeded
2018-06-02 22:22:24 -05:00
Evan Driscoll
cd0c225a50 Use raw literals for multi-line expected results
Prettyfies the test cases a bit, though there is a utiliity function
needed now.
2018-06-02 22:10:16 -05:00
Evan Driscoll
1c1c789084 Serializer edge case bug fix: very deep indents ignored indent_char 2018-06-02 21:34:55 -05:00
Evan Driscoll
0500d41fbb TODO note 2018-06-02 20:18:55 -05:00
Evan Driscoll
d54f4653ed It's now possible to limit the size of strings 2018-06-02 02:09:04 -05:00
Evan Driscoll
003f3e298b Introduce fancy_serializer_style 2018-06-02 01:18:55 -05:00
Evan Driscoll
e38b4e8031 Re-support indentation in fancy_serializer 2018-06-02 01:07:25 -05:00
Evan Driscoll
e9cb8f604d Split primitive serialization into own class 2018-06-02 00:16:08 -05:00
Evan Driscoll
a2231324e9 Start reworking fancy serialization tests 2018-06-01 23:41:15 -05:00
Evan Driscoll
607b973035 Fancy Serialization: copy serializer to fancy_serializer
1. Copy header and rename; add to Makefile; amalgamate
2. Add as friend to basic_json
3. Copy operator<< to 'fancy_dump' and simplify
4. Change test to refer to that
2018-06-01 23:13:49 -05:00
Evan Driscoll
b584000e7c Fancy serialiaztion: copy old serialization test file
Just copy unit-serialization to unit-fancy-serialization
2018-06-01 23:12:04 -05:00
Evan Driscoll
fe90fa5181 Run 'make almalgamate'
astyle reformatted some stuff... I... don't know why.
2018-06-01 23:11:34 -05:00
Niels Lohmann
e5a67fc3f8
Merge branch 'develop' of https://github.com/nlohmann/json into develop 2018-05-28 17:57:46 +02:00
Niels Lohmann
a49644ab74
🚑 adjusted Fuzzer to new parser
out_of_range exceptions where unexpected before - the parser used to crash in these situations...
2018-05-28 17:57:22 +02:00
Niels Lohmann
0efaf891e5
Merge pull request #1089 from theodelrieu/feature/map_conversion
Provide a from_json overload for std::map
2018-05-28 14:53:23 +02:00
Théo DELRIEU
c5e63fd684
Provide a from_json overload for std::map
This overload is chosen only when BasicJsonType::string_t
is not constructible from std::map::key_type.

Currently, converting a map to json treats it as an array of pairs.

fixes #1079
2018-05-28 11:06:24 +02:00
Niels Lohmann
1f84cc2c88
adjusted test cases 2018-05-17 16:50:37 +02:00
Niels Lohmann
717301d1bc
Merge branch 'testsuite' into feature/sax2 2018-05-17 16:36:43 +02:00
Niels Lohmann
4639bb2c8f
added more tests from recent nst's JSONTestSuite 2018-05-17 10:10:01 +02:00
Niels Lohmann
5ff2abb90d
Merge branch 'develop' into feature/sax2 2018-05-06 13:29:23 +02:00
Niels Lohmann
ed69e50ad2
📄 added SPDX-License-Identifier 2018-05-03 17:41:45 +02:00
Niels Lohmann
fa3e42f826
Merge branch 'develop' into feature/wstring 2018-04-29 13:16:12 +02:00
Niels Lohmann
b5d1755dfb
🔥 removed commented-out test cases #1060 2018-04-22 15:41:42 +02:00
Niels Lohmann
cf91b4f2bb
Merge branch 'develop' into feature/wstring 2018-04-08 11:36:58 +02:00
Niels Lohmann
e1ea8369ad
Merge branch 'develop' into feature/sax2 2018-04-08 09:31:59 +02:00
Niels Lohmann
18a0271a95
Merge branch 'develop' into feature/issue1021 2018-04-08 09:21:43 +02:00
Niels Lohmann
495436a5d5
Merge pull request #1026 from ktonon/develop
Added public target_compile_features for auto and constexpr
2018-04-03 17:34:42 +02:00
Niels Lohmann
aa89c5e048
🔨 removing unget_character() function from input adapters #834 2018-04-02 21:10:48 +02:00
Niels Lohmann
6678eb2b4a
improved test coverage #1031 2018-04-02 15:38:49 +02:00
Niels Lohmann
727dd4664b
🔨 trying to make tests run with MSVC #1031 2018-04-02 12:27:07 +02:00
Niels Lohmann
ab89ae4e50
🔨 trying to make tests run with MSVC #1031 2018-04-02 11:34:36 +02:00
Niels Lohmann
eb06d0531a
🚧 added input adapter for wide strings #1031 2018-04-01 19:12:36 +02:00
Niels Lohmann
4efa8cdb4c
💚 fixed Valgrind options #1030 2018-03-29 17:19:21 +02:00
Niels Lohmann
5f723bbec6
🔨 realized callback parser wirh SAX interface #971 2018-03-28 23:39:39 +02:00
Niels Lohmann
896a9db461
🔨 improved code #1021 2018-03-28 19:37:21 +02:00
Kevin Tonon
73cc5089e3 Using target_compile_features to specify C++ 11 standard 2018-03-28 13:11:49 -04:00
Niels Lohmann
a9baab76c2
🚑 fix for #1021 2018-03-28 18:20:55 +02:00
Niels Lohmann
4f6b2b6429
🔨 changed SAX interface 2018-03-21 20:12:06 +01:00
Niels Lohmann
2537677e4c
improved test coverage 2018-03-20 23:40:01 +01:00