-
Notifications
You must be signed in to change notification settings - Fork 273
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
Json tweaks #2171
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a589a56
Supply `value_type` typedef in `json_arrayt` for STL algorithm usage.
thomasspriggs 28117d2
Expose `emplace_back` method of underlying `std::vector` in `json_arr…
thomasspriggs ce674b5
Update constructor of `jsont` based on the copy and move idiom.
thomasspriggs 2907ba9
Allow constructon of `json_stringt` from `irep_idt`.
thomasspriggs 402bc56
Clang format updates.
thomasspriggs f3670e3
Expose `begin` and `end` methods of underlying `std::vector` in `json…
thomasspriggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ Author: Daniel Kroening, [email protected] | |
#include <iosfwd> | ||
#include <string> | ||
|
||
#include "irep.h" | ||
|
||
class json_objectt; | ||
class json_arrayt; | ||
|
||
|
@@ -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)) | ||
{ | ||
} | ||
|
||
|
@@ -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) | ||
}; | ||
|
||
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) | ||
{ | ||
} | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tautschnig Added.