4 #ifndef XGBOOST_JSON_IO_H_ 5 #define XGBOOST_JSON_IO_H_ 19 template <
typename Allocator>
21 char, std::char_traits<char>, Allocator> {
24 this->precision(std::numeric_limits<double>::max_digits10);
25 this->imbue(std::locale(
"C"));
26 this->setf(std::ios::scientific);
37 size_t constexpr
static kMaxNumLength =
38 std::numeric_limits<double>::max_digits10 + 1;
45 size_t Pos()
const {
return pos_; }
63 if (cursor_.Pos() == raw_str_.
size()) {
66 char ch = raw_str_[cursor_.Pos()];
72 if (cursor_.Pos() == raw_str_.
size()) {
75 char ch = raw_str_[cursor_.Pos()];
85 char result = GetNextNonSpaceChar();
86 if (result != c) { Expect(c, result); }
90 void Error(std::string msg)
const;
94 std::string msg =
"Expecting: \"";
97 msg += std::string {got} +
" \"";
101 virtual Json ParseString();
102 virtual Json ParseObject();
103 virtual Json ParseArray();
104 virtual Json ParseNumber();
105 virtual Json ParseBoolean();
106 virtual Json ParseNull();
120 static constexpr
size_t kIndentSize = 2;
124 std::ostream* stream_;
129 n_spaces_{0}, stream_{stream}, pretty_{pretty} {}
135 *stream_ << u8
"\n" << std::string(n_spaces_,
' ');
140 n_spaces_ += kIndentSize;
143 n_spaces_ -= kIndentSize;
153 void Save(
Json json);
155 virtual void Visit(
JsonArray const* arr);
159 virtual void Visit(
JsonNull const* null);
165 #endif // XGBOOST_JSON_IO_H_ char PeekNextChar()
Definition: json_io.h:71
size_t pos_
Definition: json_io.h:41
void Expect(char c, char got)
Definition: json_io.h:93
void BeginIndent()
Definition: json_io.h:139
void Write(StringView str)
Definition: json_io.h:149
Describes both true and false.
Definition: json.h:252
JsonWriter(std::ostream *stream, bool pretty)
Definition: json_io.h:128
StringView raw_str_
Definition: json_io.h:57
char GetNextNonSpaceChar()
Definition: json_io.h:79
void Write(std::string str)
Definition: json_io.h:146
size_t Pos() const
Definition: json_io.h:45
void NewLine()
Definition: json_io.h:133
size_t size() const
Definition: json.h:296
SourceLocation & Forward()
Definition: json_io.h:47
namespace of xgboost
Definition: base.h:102
SourceLocation & Forward(uint32_t n)
Definition: json_io.h:51
SourceLocation()
Definition: json_io.h:44
char GetNextChar()
Definition: json_io.h:62
JsonReader(StringView str)
Definition: json_io.h:111
Definition: json_io.h:119
Data structure representing JSON format.
Definition: json.h:325
FixedPrecisionStreamContainer()
Definition: json_io.h:23
char const * c_str() const
Definition: json.h:305
char GetChar(char c)
Definition: json_io.h:84
void EndIndent()
Definition: json_io.h:142