19 #ifndef avro_Node_hh__
20 #define avro_Node_hh__
25 #include <boost/noncopyable.hpp>
26 #include <boost/shared_ptr.hpp>
28 #include "Exception.hh"
30 #include "SchemaResolution.hh"
37 typedef boost::shared_ptr<Node> NodePtr;
41 std::string simpleName_;
44 Name(
const std::string& fullname);
45 Name(
const std::string& simpleName,
const std::string& ns) : ns_(ns), simpleName_(simpleName) { check(); }
47 const std::string fullname()
const;
48 const std::string& ns()
const {
return ns_; }
49 const std::string& simpleName()
const {
return simpleName_; }
51 void ns(
const std::string& n) { ns_ = n; }
52 void simpleName(
const std::string& n) { simpleName_ = n; }
53 void fullname(
const std::string& n);
55 bool operator < (
const Name& n)
const;
57 bool operator == (
const Name& n)
const;
58 bool operator != (
const Name& n)
const {
return !((*this) == n); }
63 operator std::string()
const {
69 std::ostream& operator << (std::ostream& os,
const Name& n) {
70 return os << n.fullname();
88 class AVRO_DECL
Node :
private boost::noncopyable
107 bool locked()
const {
111 virtual bool hasName()
const = 0;
113 void setName(
const Name &name) {
118 virtual const Name &name()
const = 0;
120 void addLeaf(
const NodePtr &newLeaf) {
124 virtual size_t leaves()
const = 0;
125 virtual const NodePtr& leafAt(
int index)
const = 0;
127 throw Exception(boost::format(
"No default value at: %1%") % index);
130 void addName(
const std::string &name) {
135 virtual size_t names()
const = 0;
136 virtual const std::string &nameAt(
int index)
const = 0;
137 virtual bool nameIndex(
const std::string &name,
size_t &index)
const = 0;
139 void setFixedSize(
int size) {
141 doSetFixedSize(size);
143 virtual int fixedSize()
const = 0;
145 virtual bool isValid()
const = 0;
149 virtual void printJson(std::ostream &os,
int depth)
const = 0;
151 virtual void printBasicInfo(std::ostream &os)
const = 0;
153 virtual void setLeafToSymbolic(
int index,
const NodePtr &node) = 0;
157 void checkLock()
const {
159 throw Exception(
"Cannot modify locked schema");
163 virtual void checkName(
const Name &name)
const {
167 virtual void doSetName(
const Name &name) = 0;
168 virtual void doAddLeaf(
const NodePtr &newLeaf) = 0;
169 virtual void doAddName(
const std::string &name) = 0;
170 virtual void doSetFixedSize(
int size) = 0;
181 inline std::ostream& operator<<(std::ostream& os,
const avro::Node& n)
Node is the building block for parse trees.
Definition: Node.hh:88
Type
The "type" for the schema.
Definition: Types.hh:31
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
SchemaResolution
Definition: SchemaResolution.hh:27
Wrapper for std::runtime_error that provides convenience constructor for boost::format objects...
Definition: Exception.hh:31
Generic datum which can hold any Avro type.
Definition: GenericDatum.hh:55