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