Skip to content

Commit c817486

Browse files
author
Thomas Kiley
authored
Merge pull request #2171 from thomasspriggs/json_tweaks
Json tweaks
2 parents 1d0cd01 + f3670e3 commit c817486

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

src/util/json.h

+55-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Author: Daniel Kroening, [email protected]
1515
#include <iosfwd>
1616
#include <string>
1717

18+
#include "irep.h"
19+
1820
class json_objectt;
1921
class json_arrayt;
2022

@@ -117,7 +119,7 @@ class jsont
117119
{
118120
}
119121

120-
jsont(kindt _kind, const std::string &_value):kind(_kind), value(_value)
122+
jsont(kindt _kind, std::string _value) : kind(_kind), value(std::move(_value))
121123
{
122124
}
123125

@@ -169,13 +171,63 @@ class json_arrayt:public jsont
169171
array.push_back(jsont());
170172
return array.back();
171173
}
174+
175+
template <typename... argumentst>
176+
void emplace_back(argumentst &&... arguments)
177+
{
178+
array.emplace_back(std::forward<argumentst>(arguments)...);
179+
}
180+
181+
std::vector<jsont>::iterator begin()
182+
{
183+
return array.begin();
184+
}
185+
186+
std::vector<jsont>::const_iterator begin() const
187+
{
188+
return array.begin();
189+
}
190+
191+
std::vector<jsont>::const_iterator cbegin() const
192+
{
193+
return array.cbegin();
194+
}
195+
196+
std::vector<jsont>::iterator end()
197+
{
198+
return array.end();
199+
}
200+
201+
std::vector<jsont>::const_iterator end() const
202+
{
203+
return array.end();
204+
}
205+
206+
std::vector<jsont>::const_iterator cend() const
207+
{
208+
return array.cend();
209+
}
210+
211+
typedef jsont value_type; // NOLINT(readability/identifiers)
172212
};
173213

174214
class json_stringt:public jsont
175215
{
176216
public:
177-
explicit json_stringt(const std::string &_value):
178-
jsont(kindt::J_STRING, _value)
217+
explicit json_stringt(std::string _value)
218+
: jsont(kindt::J_STRING, std::move(_value))
219+
{
220+
}
221+
222+
#ifndef USE_STD_STRING
223+
explicit json_stringt(const irep_idt &_value)
224+
: jsont(kindt::J_STRING, id2string(_value))
225+
{
226+
}
227+
#endif
228+
229+
/// Constructon from string literal.
230+
explicit json_stringt(const char *_value) : jsont(kindt::J_STRING, _value)
179231
{
180232
}
181233
};

0 commit comments

Comments
 (0)