mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-04-06 02:45:02 +02:00
use new BuiltStyledStreamWriter in operator<<()
This commit is contained in:
parent
4d649402b0
commit
d49ab5aee1
@ -665,12 +665,29 @@ bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
|||||||
value.hasComment(commentAfter);
|
value.hasComment(commentAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& sout, const Value& root) {
|
struct BuiltStyledStreamWriter : public StreamWriter
|
||||||
Json::StyledStreamWriter writer;
|
{
|
||||||
writer.write(sout, root);
|
mutable StyledStreamWriter old_;
|
||||||
return sout;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
BuiltStyledStreamWriter(
|
||||||
|
std::ostream* sout,
|
||||||
|
std::string const& indentation,
|
||||||
|
StreamWriter::CommentStyle cs);
|
||||||
|
virtual int write(Value const& root) const;
|
||||||
|
};
|
||||||
|
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
||||||
|
std::ostream* sout,
|
||||||
|
std::string const& indentation,
|
||||||
|
StreamWriter::CommentStyle cs)
|
||||||
|
: StreamWriter(sout)
|
||||||
|
, old_(indentation)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
int BuiltStyledStreamWriter::write(Value const& root) const
|
||||||
|
{
|
||||||
|
old_.write(sout_, root);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
StreamWriter::StreamWriter(std::ostream* sout)
|
StreamWriter::StreamWriter(std::ostream* sout)
|
||||||
: sout_(*sout)
|
: sout_(*sout)
|
||||||
{
|
{
|
||||||
@ -720,8 +737,7 @@ void StreamWriterBuilder::setIndentation(std::string v)
|
|||||||
}
|
}
|
||||||
StreamWriter* StreamWriterBuilder::newStreamWriter(std::ostream* stream) const
|
StreamWriter* StreamWriterBuilder::newStreamWriter(std::ostream* stream) const
|
||||||
{
|
{
|
||||||
// return new StyledStreamWriter(stream);
|
return new BuiltStyledStreamWriter(stream, indentation_, cs_);
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
StreamWriterBuilderFactory::~StreamWriterBuilderFactory()
|
StreamWriterBuilderFactory::~StreamWriterBuilderFactory()
|
||||||
{
|
{
|
||||||
@ -761,4 +777,13 @@ std::string writeString(Value const& root, StreamWriterBuilder const& builder) {
|
|||||||
return sout.str();
|
return sout.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& sout, const Value& root) {
|
||||||
|
StreamWriterBuilderFactory f;
|
||||||
|
StreamWriter::Builder builder(&f);
|
||||||
|
builder.setCommentStyle(StreamWriter::CommentStyle::Some);
|
||||||
|
std::shared_ptr<StreamWriter> writer(builder.newStreamWriter(&sout));
|
||||||
|
writer->write(root);
|
||||||
|
return sout;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user