#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__
#define GOOGLE_PROTOBUF_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__
#include <memory>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/util/internal/object_writer.h>
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace util {
namespace converter {
class PROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter {
public:
~StructuredObjectWriter() override {}
protected:
class PROTOBUF_EXPORT BaseElement {
public:
explicit BaseElement(BaseElement* parent)
: parent_(parent),
level_(parent == nullptr ? 0 : parent->level() + 1) {}
virtual ~BaseElement() {}
template <typename ElementType>
ElementType* pop() {
return down_cast<ElementType*>(parent_.release());
}
bool is_root() const { return parent_ == nullptr; }
int level() const { return level_; }
protected:
virtual BaseElement* parent() const { return parent_.get(); }
private:
std::unique_ptr<BaseElement> parent_;
const int level_;
GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseElement);
};
StructuredObjectWriter() {}
virtual BaseElement* element() = 0;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StructuredObjectWriter);
};
} } } }
#include <google/protobuf/port_undef.inc>
#endif