19 #ifndef avro_Node_hh__
20 #define avro_Node_hh__
24 #include <boost/noncopyable.hpp>
29 #include "Exception.hh"
30 #include "LogicalType.hh"
31 #include "SchemaResolution.hh"
39 using NodePtr = std::shared_ptr<Node>;
43 std::string simpleName_;
47 explicit Name(
const std::string &fullname);
48 Name(std::string simpleName, std::string ns) : ns_(std::move(ns)), simpleName_(std::move(simpleName)) { check(); }
50 std::string fullname()
const;
51 const std::string &ns()
const {
return ns_; }
52 const std::string &simpleName()
const {
return simpleName_; }
54 void ns(std::string n) { ns_ = std::move(n); }
55 void simpleName(std::string n) { simpleName_ = std::move(n); }
56 void fullname(
const std::string &n);
58 bool operator<(
const Name &n)
const;
60 bool operator==(
const Name &n)
const;
61 bool operator!=(
const Name &n)
const {
return !((*this) == n); }
66 explicit operator std::string()
const {
71 inline std::ostream &operator<<(std::ostream &os,
const Name &n) {
72 return os << n.fullname();
90 class AVRO_DECL
Node :
private boost::noncopyable {
92 explicit Node(
Type type) : type_(type),
93 logicalType_(LogicalType::NONE),
112 bool locked()
const {
116 virtual bool hasName()
const = 0;
118 void setName(
const Name &name) {
123 virtual const Name &name()
const = 0;
125 virtual const std::string &getDoc()
const = 0;
126 void setDoc(
const std::string &doc) {
131 void addLeaf(
const NodePtr &newLeaf) {
135 virtual size_t leaves()
const = 0;
136 virtual const NodePtr &leafAt(
size_t index)
const = 0;
137 virtual const GenericDatum &defaultValueAt(
size_t index) {
138 throw Exception(boost::format(
"No default value at: %1%") % index);
141 void addName(
const std::string &name) {
143 checkName(
Name(name));
146 virtual size_t names()
const = 0;
147 virtual const std::string &nameAt(
size_t index)
const = 0;
148 virtual bool nameIndex(
const std::string &name,
size_t &index)
const = 0;
150 void setFixedSize(
size_t size) {
152 doSetFixedSize(size);
154 virtual size_t fixedSize()
const = 0;
156 virtual bool isValid()
const = 0;
160 virtual void printJson(std::ostream &os,
size_t depth)
const = 0;
162 virtual void printBasicInfo(std::ostream &os)
const = 0;
164 virtual void setLeafToSymbolic(
size_t index,
const NodePtr &node) = 0;
168 virtual void printDefaultToJson(
const GenericDatum &g, std::ostream &os,
169 size_t depth)
const = 0;
172 void checkLock()
const {
174 throw Exception(
"Cannot modify locked schema");
178 virtual void checkName(
const Name &name)
const {
182 virtual void doSetName(
const Name &name) = 0;
183 virtual void doSetDoc(
const std::string &name) = 0;
185 virtual void doAddLeaf(
const NodePtr &newLeaf) = 0;
186 virtual void doAddName(
const std::string &name) = 0;
187 virtual void doSetFixedSize(
size_t size) = 0;
198 inline std::ostream &operator<<(std::ostream &os,
const avro::Node &n) {