Skip to content

Commit

Permalink
⏪ reverting first/second experiment nlohmann#350
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed May 15, 2017
1 parent 723c875 commit 0c3ffe1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 810 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ to the files you want to use JSON objects. That's it. Do not forget to set the n

:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.

If you are using the Meson Build System, then you can wrap this repo as a subproject.
If you are using the [Meson Build System](http://mesonbuild.com), then you can wrap this repo as a subproject.

:warning: [Version 3.0.0](https://github.com/nlohmann/json/wiki/Road-toward-3.0.0) is currently under development. Branch `develop` is used for the ongoing work and is probably **unstable**. Please use the `master` branch for the last stable version 2.1.1.

Expand Down Expand Up @@ -839,6 +839,7 @@ I deeply appreciate the help of the following people.
- [ftillier](https://github.com/ftillier) fixed a compiler warning.
- [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped.
- [Fytch](https://github.com/Fytch) found a bug in the documentation.
- [Jay Sistar](https://github.com/Type1J) implemented a Meson build description
Thanks a lot for helping out! Please [let me know](mailto:[email protected]) if I forgot someone.
Expand All @@ -865,7 +866,6 @@ The library itself contains of a single header file licensed under the MIT licen
- [**Github Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
- [**libFuzzer**](http://llvm.org/docs/LibFuzzer.html) to implement fuzz testing for OSS-Fuzz
- [**OSS-Fuzz**](https://github.com/google/oss-fuzz) for continuous fuzz testing of the library
- [**re2c**](http://re2c.org) to generate an automaton for the lexical analysis
- [**send_to_wandbox**](https://github.com/nlohmann/json/blob/develop/doc/scripts/send_to_wandbox.py) to send code examples to [Wandbox](http://melpon.org/wandbox)
- [**Travis**](https://travis-ci.org) for [continuous integration](https://travis-ci.org/nlohmann/json) on Linux and macOS
- [**Valgrind**](http://valgrind.org) to check for correct memory management
Expand Down
22 changes: 22 additions & 0 deletions doc/examples/iterator_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "json.hpp"

using json = nlohmann::json;

int main()
{
// create JSON values
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};

// example for an object
for (auto& x : json::iterator_wrapper(j_object))
{
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}

// example for an array
for (auto& x : json::iterator_wrapper(j_array))
{
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}
}
1 change: 1 addition & 0 deletions doc/examples/iterator_wrapper.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="https://wandbox.org/permlink/YkOQK9sqEfbKUF31"><b>online</b></a>
7 changes: 7 additions & 0 deletions doc/examples/iterator_wrapper.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
key: one, value: 1
key: two, value: 2
key: 0, value: 1
key: 1, value: 2
key: 2, value: 4
key: 3, value: 8
key: 4, value: 16
81 changes: 3 additions & 78 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5204,6 +5204,8 @@ class basic_json
reference to the JSON values is returned, so there is no access to the
underlying iterator.

@liveexample{The following code shows how the wrapper is used,iterator_wrapper}

@note The name of this function is not yet final and may change in the
future.
*/
Expand Down Expand Up @@ -7877,80 +7879,6 @@ class basic_json
class iteration_proxy
{
private:
/// helper class for first "property"
template<typename ProxyType>
class iterator_key_property
{
private:
/// the reference to the proxy
ProxyType& proxy;

public:
explicit iterator_key_property(ProxyType& proxyRef) noexcept
: proxy(proxyRef) {}

/// conversion operator (calls key())
operator typename basic_json::string_t() const
{
return proxy.key();
}

/// equal operator (calls key())
template<typename KeyType>
bool operator==(const KeyType& key) const
{
return proxy.key() == key;
}

/// not equal operator (calls key())
template<typename KeyType>
bool operator!=(const KeyType& key) const
{
return proxy.key() != key;
}
};

/// helper class for second "property"
template<typename ProxyType>
class iterator_value_property
{
private:
/// the reference to the proxy
ProxyType& proxy;

public:
explicit iterator_value_property(ProxyType& proxyRef) noexcept
: proxy(proxyRef) {}

/// conversion operator (calls value())
operator typename IteratorType::reference() const
{
return proxy.value();
}

/// equal operator (calls value())
template<typename ValueType>
bool operator==(const ValueType& value) const
{
return proxy.value() == value;
}

/// not equal operator (calls value())
template<typename ValueType>
bool operator!=(const ValueType& value) const
{
return proxy.value() != value;
}

/// assignment operator (calls value())
template<typename ValueType>
iterator_value_property<ProxyType>& operator=(const ValueType& value)
{
proxy.value() = value;
return *this;
}
};

/// helper class for iteration
class iteration_proxy_internal
{
Expand All @@ -7961,11 +7889,8 @@ class basic_json
size_t array_index = 0;

public:
iterator_key_property<iteration_proxy_internal> first;
iterator_value_property<iteration_proxy_internal> second;

explicit iteration_proxy_internal(IteratorType it) noexcept
: anchor(it), first(*this), second(*this)
: anchor(it)
{}

/// dereference operator (needed for range-based for)
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
"src/unit-element_access2.cpp"
"src/unit-inspection.cpp"
"src/unit-iterator_wrapper.cpp"
"src/unit-iterator_wrapper_first_second.cpp"
"src/unit-iterators1.cpp"
"src/unit-iterators2.cpp"
"src/unit-json_patch.cpp"
Expand Down
Loading

0 comments on commit 0c3ffe1

Please sign in to comment.