Skip to content

Json tweaks #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 10, 2018
Merged
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
58 changes: 55 additions & 3 deletions src/util/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Author: Daniel Kroening, [email protected]
#include <iosfwd>
#include <string>

#include "irep.h"

class json_objectt;
class json_arrayt;

Expand Down Expand Up @@ -117,7 +119,7 @@ class jsont
{
}

jsont(kindt _kind, const std::string &_value):kind(_kind), value(_value)
jsont(kindt _kind, std::string _value) : kind(_kind), value(std::move(_value))
{
}

Expand Down Expand Up @@ -169,13 +171,63 @@ class json_arrayt:public jsont
array.push_back(jsont());
return array.back();
}

template <typename... argumentst>
void emplace_back(argumentst &&... arguments)
{
array.emplace_back(std::forward<argumentst>(arguments)...);
}

std::vector<jsont>::iterator begin()
{
return array.begin();
}

std::vector<jsont>::const_iterator begin() const
{
return array.begin();
}

std::vector<jsont>::const_iterator cbegin() const
{
return array.cbegin();
}

std::vector<jsont>::iterator end()
{
return array.end();
}

std::vector<jsont>::const_iterator end() const
{
return array.end();
}

std::vector<jsont>::const_iterator cend() const
{
return array.cend();
}

typedef jsont value_type; // NOLINT(readability/identifiers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make more complaint with std algorithms

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might help to add some concrete examples in the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this with @thk123 in person. He hadn't actually read the existing message on this commit. I will however come up with a simple example to add to the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tautschnig Added.

};

class json_stringt:public jsont
{
public:
explicit json_stringt(const std::string &_value):
jsont(kindt::J_STRING, _value)
explicit json_stringt(std::string _value)
: jsont(kindt::J_STRING, std::move(_value))
{
}

#ifndef USE_STD_STRING
explicit json_stringt(const irep_idt &_value)
: jsont(kindt::J_STRING, id2string(_value))
{
}
#endif

/// Constructon from string literal.
explicit json_stringt(const char *_value) : jsont(kindt::J_STRING, _value)
{
}
};
Expand Down