19 #ifndef avro_Node_hh__
20 #define avro_Node_hh__
24 #include <boost/noncopyable.hpp>
29 #include "CustomFields.hh"
30 #include "Exception.hh"
31 #include "LogicalType.hh"
32 #include "SchemaResolution.hh"
40 using NodePtr = std::shared_ptr<Node>;
44 std::string simpleName_;
48 explicit Name(
const std::string &fullname);
49 Name(std::string simpleName, std::string ns) : ns_(std::move(ns)), simpleName_(std::move(simpleName)) { check(); }
51 std::string fullname()
const;
52 const std::string &ns()
const {
return ns_; }
53 const std::string &simpleName()
const {
return simpleName_; }
55 void ns(std::string n) { ns_ = std::move(n); }
56 void simpleName(std::string n) { simpleName_ = std::move(n); }
57 void fullname(
const std::string &n);
59 bool operator<(
const Name &n)
const;
61 bool operator==(
const Name &n)
const;
62 bool operator!=(
const Name &n)
const {
return !((*this) == n); }
67 explicit operator std::string()
const {
72 inline std::ostream &operator<<(std::ostream &os,
const Name &n) {
73 return os << n.fullname();
91 class AVRO_DECL
Node :
private boost::noncopyable {
93 explicit Node(
Type type) : type_(type),
94 logicalType_(LogicalType::NONE),
113 bool locked()
const {
117 virtual bool hasName()
const = 0;
119 void setName(
const Name &name) {
124 virtual const Name &name()
const = 0;
126 virtual const std::string &getDoc()
const = 0;
127 void setDoc(
const std::string &doc) {
132 void addLeaf(
const NodePtr &newLeaf) {
136 virtual size_t leaves()
const = 0;
137 virtual const NodePtr &leafAt(
size_t index)
const = 0;
138 virtual const GenericDatum &defaultValueAt(
size_t index) {
139 throw Exception(boost::format(
"No default value at: %1%") % index);
142 void addName(
const std::string &name) {
144 checkName(
Name(name));
147 virtual size_t names()
const = 0;
148 virtual const std::string &nameAt(
size_t index)
const = 0;
149 virtual bool nameIndex(
const std::string &name,
size_t &index)
const = 0;
151 void setFixedSize(
size_t size) {
153 doSetFixedSize(size);
155 virtual size_t fixedSize()
const = 0;
157 void addCustomAttributesForField(
const CustomFields& customAttributes) {
159 doAddCustomAttribute(customAttributes);
162 virtual bool isValid()
const = 0;
166 virtual void printJson(std::ostream &os,
size_t depth)
const = 0;
168 virtual void printBasicInfo(std::ostream &os)
const = 0;
170 virtual void setLeafToSymbolic(
size_t index,
const NodePtr &node) = 0;
174 virtual void printDefaultToJson(
const GenericDatum &g, std::ostream &os,
175 size_t depth)
const = 0;
178 void checkLock()
const {
180 throw Exception(
"Cannot modify locked schema");
184 virtual void checkName(
const Name &name)
const {
188 virtual void doSetName(
const Name &name) = 0;
189 virtual void doSetDoc(
const std::string &name) = 0;
191 virtual void doAddLeaf(
const NodePtr &newLeaf) = 0;
192 virtual void doAddName(
const std::string &name) = 0;
193 virtual void doSetFixedSize(
size_t size) = 0;
194 virtual void doAddCustomAttribute(
const CustomFields& customFields) = 0;
205 inline std::ostream &operator<<(std::ostream &os,
const avro::Node &n) {