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;
46 size_t Pos()
const {
return pos_; }
64 if (cursor_.Pos() == raw_str_.
size()) {
67 char ch = raw_str_[cursor_.Pos()];
73 if (cursor_.Pos() == raw_str_.
size()) {
76 char ch = raw_str_[cursor_.Pos()];
86 char result = GetNextNonSpaceChar();
87 if (result != c) { Expect(c, result); }
91 void Error(std::string msg)
const;
95 std::string msg =
"Expecting: \"";
98 msg += std::string {got} +
" \"";
102 virtual Json ParseString();
103 virtual Json ParseObject();
104 virtual Json ParseArray();
105 virtual Json ParseNumber();
106 virtual Json ParseBoolean();
107 virtual Json ParseNull();
121 static constexpr
size_t kIndentSize = 2;
125 std::ostream* stream_;
130 n_spaces_{0}, stream_{stream}, pretty_{pretty} {}
136 *stream_ << u8
"\n" << std::string(n_spaces_,
' ');
141 n_spaces_ += kIndentSize;
144 n_spaces_ -= kIndentSize;
154 void Save(
Json json);
156 virtual void Visit(
JsonArray const* arr);
160 virtual void Visit(
JsonNull const* null);
166 #endif // XGBOOST_JSON_IO_H_ char PeekNextChar()
Definition: json_io.h:72
void Expect(char c, char got)
Definition: json_io.h:94
void BeginIndent()
Definition: json_io.h:140
void Write(StringView str)
Definition: json_io.h:150
Describes both true and false.
Definition: json.h:252
JsonWriter(std::ostream *stream, bool pretty)
Definition: json_io.h:129
StringView raw_str_
Definition: json_io.h:58
char GetNextNonSpaceChar()
Definition: json_io.h:80
void Write(std::string str)
Definition: json_io.h:147
size_t Pos() const
Definition: json_io.h:46
void NewLine()
Definition: json_io.h:134
size_t size() const
Definition: json.h:297
SourceLocation & Forward()
Definition: json_io.h:48
namespace of xgboost
Definition: base.h:102
SourceLocation & Forward(uint32_t n)
Definition: json_io.h:52
char GetNextChar()
Definition: json_io.h:63
JsonReader(StringView str)
Definition: json_io.h:112
Definition: json_io.h:120
Data structure representing JSON format.
Definition: json.h:326
FixedPrecisionStreamContainer()
Definition: json_io.h:23
char const * c_str() const
Definition: json.h:306
char GetChar(char c)
Definition: json_io.h:85
void EndIndent()
Definition: json_io.h:143