mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 10:03:51 +01:00
drop StreamWriterBuilderFactory, for now
This commit is contained in:
parent
94665eab72
commit
fe3979cd8a
@ -30,26 +30,20 @@ Usage:
|
||||
|
||||
using namespace Json;
|
||||
Value value;
|
||||
StreamWriterBuilderFactory f;
|
||||
StreamWriter::Builder builder(&f);
|
||||
StreamWriter::Builder builder;
|
||||
builder.setCommentStyle(StreamWriter::CommentStyle::None);
|
||||
std::shared_ptr<StreamWriter> writer(
|
||||
builder.newStreamWriter(&std::cout));
|
||||
writer->write(value);
|
||||
std::cout.flush();
|
||||
*/
|
||||
class JSON_API StreamWriterBuilderFactory {
|
||||
public:
|
||||
virtual ~StreamWriterBuilderFactory();
|
||||
virtual StreamWriterBuilder* newStreamWriterBuilder() const;
|
||||
};
|
||||
|
||||
class JSON_API StreamWriter {
|
||||
protected:
|
||||
std::ostream& sout_; // not owned; will not delete
|
||||
public:
|
||||
enum class CommentStyle {None, Some, All};
|
||||
|
||||
/// Keep a reference, but do not take ownership of `sout`.
|
||||
StreamWriter(std::ostream* sout);
|
||||
virtual ~StreamWriter();
|
||||
/// Write Value into document as configured in sub-class.
|
||||
@ -62,8 +56,10 @@ public:
|
||||
/// \see http://stackoverflow.com/questions/14875052/pure-virtual-functions-and-binary-compatibility
|
||||
class Builder {
|
||||
StreamWriterBuilder* own_;
|
||||
Builder(Builder const&); // noncopyable
|
||||
void operator=(Builder const&); // noncopyable
|
||||
public:
|
||||
Builder(StreamWriterBuilderFactory const*);
|
||||
Builder();
|
||||
~Builder(); // delete underlying StreamWriterBuilder
|
||||
|
||||
void setCommentStyle(CommentStyle cs); /// default: All
|
||||
|
@ -184,8 +184,7 @@ static std::string useStyledStreamWriter(
|
||||
static std::string useBuiltStyledStreamWriter(
|
||||
Json::Value const& root)
|
||||
{
|
||||
Json::StreamWriterBuilderFactory f;
|
||||
Json::StreamWriter::Builder builder(&f);
|
||||
Json::StreamWriter::Builder builder;
|
||||
builder.setCommentStyle(Json::StreamWriter::CommentStyle::All);
|
||||
return writeString(root, builder);
|
||||
}
|
||||
|
@ -967,6 +967,13 @@ StreamWriter* StreamWriterBuilder::newStreamWriter(std::ostream* stream) const
|
||||
{
|
||||
return new BuiltStyledStreamWriter(stream, indentation_, cs_);
|
||||
}
|
||||
|
||||
// This might become public someday.
|
||||
class StreamWriterBuilderFactory {
|
||||
public:
|
||||
virtual ~StreamWriterBuilderFactory();
|
||||
virtual StreamWriterBuilder* newStreamWriterBuilder() const;
|
||||
};
|
||||
StreamWriterBuilderFactory::~StreamWriterBuilderFactory()
|
||||
{
|
||||
}
|
||||
@ -975,14 +982,19 @@ StreamWriterBuilder* StreamWriterBuilderFactory::newStreamWriterBuilder() const
|
||||
return new StreamWriterBuilder;
|
||||
}
|
||||
|
||||
StreamWriter::Builder::Builder(StreamWriterBuilderFactory const* f)
|
||||
: own_(f->newStreamWriterBuilder())
|
||||
StreamWriter::Builder::Builder()
|
||||
: own_(StreamWriterBuilderFactory().newStreamWriterBuilder())
|
||||
{
|
||||
}
|
||||
StreamWriter::Builder::~Builder()
|
||||
{
|
||||
delete own_;
|
||||
}
|
||||
StreamWriter::Builder::Builder(Builder const&)
|
||||
: own_(nullptr)
|
||||
{abort();}
|
||||
void StreamWriter::Builder::operator=(Builder const&)
|
||||
{abort();}
|
||||
void StreamWriter::Builder::setCommentStyle(CommentStyle v)
|
||||
{
|
||||
own_->setCommentStyle(v);
|
||||
@ -1006,8 +1018,7 @@ std::string writeString(Value const& root, StreamWriter::Builder const& builder)
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& sout, Value const& root) {
|
||||
StreamWriterBuilderFactory f;
|
||||
StreamWriter::Builder builder(&f);
|
||||
StreamWriter::Builder builder;
|
||||
builder.setCommentStyle(StreamWriter::CommentStyle::All);
|
||||
std::shared_ptr<StreamWriter> writer(builder.newStreamWriter(&sout));
|
||||
writer->write(root);
|
||||
|
Loading…
Reference in New Issue
Block a user