16#include <unordered_map>
32 template<
typename CharT>
34 template<
typename CharT>
36 template<
typename CharT>
38 template<
typename CharT>
40 template<
typename CharT>
41 using Array = std::vector<Value<CharT>>;
42 template<
typename CharT>
56 template<
typename CharT>
59 static inline bool format_json_ =
false;
60 static inline int tabsize_ = 4;
62 using jFormat = std::ios_base& (*)(std::ios_base&);
67 format_json_ = tabsize >= 0;
70 return [](std::ios_base& os)->std::ios_base& {
85 template<
typename CharT>
87 static inline const CharT null_[]{
'n',
'u',
'l',
'l', 0 };
88 static inline const CharT true_[]{
't',
'r',
'u',
'e', 0 };
89 static inline const CharT fals_[]{
'f',
'a',
'l',
's', 0 };
90 static inline const CharT false_[]{
'f',
'a',
'l',
's',
'e', 0 };
91 static inline const CharT invaild_[]{
92 '/',
'*',
'I',
'n',
'v',
'a',
'i',
'l',
'd',
' ',
'v',
'a',
'l',
'u',
'e',
'*',
'/', 0 };
100 if (is.peek() ==
'/') {
102 if (is.peek() ==
'/') {
103 is.ignore(std::string().max_size(),
'\n');
105 else if (is.peek() ==
'*') {
107 while (is.peek() ==
'/')
109 while (is.peek() !=
'/')
110 is.ignore(std::string().max_size(),
'*');
149 double d = std::get<double>(value_);
150 return d == std::floor(d);
155 double&
asNumber() {
return std::get<double>(value_); }
160 const bool&
asBoolean()
const {
return std::get<bool>(value_); }
161 const int&
asInteger()
const {
return std::get<int>(value_); }
162 const double&
asNumber()
const {
return std::get<double>(value_); }
167 bool toBool()
const {
return std::get<bool>(value_); }
168 int toInt()
const {
return static_cast<int>(std::get<double>(value_)); }
169 double toFloat()
const {
return std::get<double>(value_); }
178 static inline int indent_ = 0;
195 os << '[' << (Format::isFormat() ? StdString<CharT>(1,
'\n') :
StdString<CharT>());
197 for (std::size_t i = 0; i < v.
asArray().size(); ++i)
213 for (
const auto& [key, value] : v.
asObject()) {
239 v.removeRedundantComma(is);
244 CharT null[4] = { 0 };
247 is.setstate(std::ios_base::failbit);
255 CharT
boolean[5] = { 0 };
264 is.setstate(std::ios_base::failbit);
282 while (!is_end)
switch (is.peek()) {
283 case '0':
case '1':
case '2':
case '3':
case '4':
284 case '5':
case '6':
case '7':
case '8':
case '9':
285 case '.':
case '+':
case '-':
case 'e':
case 'E':
292 try { v = std::stod(number); }
293 catch (
const std::exception&) {
294 is.setstate(std::ios_base::failbit);
302 std::getline(is, v.
asString(), (CharT)
'"');
308 while (is.peek() !=
']') {
309 v.removeRedundantComma(is);
312 v.
asArray().push_back(std::move(value));
313 v.removeRedundantComma(is);
314 if (is.peek() ==
']') {
317 if (is.peek() !=
',') {
318 is.setstate(std::ios_base::failbit);
322 v.removeRedundantComma(is);
324 if (is.get() !=
']') {
325 is.setstate(std::ios_base::failbit);
333 while (is.peek() !=
'}') {
334 v.removeRedundantComma(is);
338 is.setstate(std::ios_base::failbit);
341 v.removeRedundantComma(is);
342 if (is.get() !=
':') {
343 is.setstate(std::ios_base::failbit);
348 v[key.
toString()] = std::move(value);
349 v.removeRedundantComma(is);
350 if (is.peek() ==
'}') {
353 if (is.peek() !=
',') {
354 is.setstate(std::ios_base::failbit);
358 v.removeRedundantComma(is);
360 if (is.get() !=
'}') {
361 is.setstate(std::ios_base::failbit);
366 is.setstate(std::ios_base::failbit);
const int & asInteger() const
定义 json.hpp:161
bool isArray() const
定义 json.hpp:144
Value(bool b)
定义 json.hpp:120
bool isNumber() const
定义 json.hpp:146
Value(const StdString< CharT > &s)
定义 json.hpp:125
Value & operator=(const Object< CharT > &o)
定义 json.hpp:136
const StdString< CharT > & asString() const
定义 json.hpp:163
double & asNumber()
定义 json.hpp:155
Value(const Object< CharT > &o)
定义 json.hpp:127
Value & operator=(double d)
定义 json.hpp:130
bool isInteger() const
定义 json.hpp:147
int toInt() const
定义 json.hpp:168
Value & operator=(const CharT *s)
定义 json.hpp:133
const bool & asBoolean() const
定义 json.hpp:160
bool isFloat() const
定义 json.hpp:152
Value(const Array< CharT > &a)
定义 json.hpp:126
const Object< CharT > & asObject() const
定义 json.hpp:165
bool isObject() const
定义 json.hpp:145
bool isBool() const
定义 json.hpp:142
Value(double d)
定义 json.hpp:121
Value(const CharT(&s)[N])
定义 json.hpp:123
Value & operator[](const StdString< CharT > &key)
定义 json.hpp:173
bool & asBoolean()
定义 json.hpp:154
bool isString() const
定义 json.hpp:143
const Value & operator[](size_t i) const
定义 json.hpp:172
Value(const CharT *s)
定义 json.hpp:124
const Value & at(const StdString< CharT > &key) const
定义 json.hpp:176
bool isNull() const
定义 json.hpp:141
Array< CharT > & asArray()
定义 json.hpp:157
const Array< CharT > & asArray() const
定义 json.hpp:164
Value & operator[](size_t i)
定义 json.hpp:171
const Value & operator[](const StdString< CharT > &key) const
定义 json.hpp:174
Value & operator=(const CharT(&s)[N])
定义 json.hpp:132
Type type() const
获取当前 JSON 值对象持有的 JSON 值类型
定义 json.hpp:139
friend StdOStream< CharT > & operator<<(StdOStream< CharT > &os, const Value< CharT > &v)
向流中写入 JSON 值对象
定义 json.hpp:181
friend StdIStream< CharT > & operator>>(StdIStream< CharT > &is, Value< CharT > &v)
从流中读取 JSON 值对象
定义 json.hpp:238
Value & at(const StdString< CharT > &key)
定义 json.hpp:175
bool toBool() const
定义 json.hpp:167
double toFloat() const
定义 json.hpp:169
StdString< CharT > & asString()
定义 json.hpp:156
const double & asNumber() const
定义 json.hpp:162
Object< CharT > & asObject()
定义 json.hpp:158
Value & operator=(const StdString< CharT > &s)
定义 json.hpp:134
const StdString< CharT > & toString() const
定义 json.hpp:170
Value & operator=(bool b)
定义 json.hpp:129
Value & operator=(const Array< CharT > &a)
定义 json.hpp:135
std::basic_istream< CharT > StdIStream
定义 json.hpp:37
std::vector< Value< CharT > > Array
定义 json.hpp:41
std::basic_string< CharT > StdString
定义 json.hpp:35
std::basic_ostream< CharT > StdOStream
定义 json.hpp:39
std::unordered_map< StdString< CharT >, Value< CharT > > Object
定义 json.hpp:43
GraceFt库的命名空间
定义 _private.inl:64
std::size_t size
定义 Matrix.hpp:19