19 #ifndef avro_Node_hh__ 20 #define avro_Node_hh__ 26 #include <boost/noncopyable.hpp> 28 #include "Exception.hh" 29 #include "LogicalType.hh" 31 #include "SchemaResolution.hh" 38 typedef std::shared_ptr<Node> NodePtr;
42 std::string simpleName_;
45 Name(
const std::string& fullname);
46 Name(
const std::string& simpleName,
const std::string& ns) : ns_(ns), simpleName_(simpleName) { check(); }
48 const std::string fullname()
const;
49 const std::string& ns()
const {
return ns_; }
50 const std::string& simpleName()
const {
return simpleName_; }
52 void ns(
const std::string& n) { ns_ = n; }
53 void simpleName(
const std::string& n) { simpleName_ = n; }
54 void fullname(
const std::string& n);
56 bool operator < (
const Name& n)
const;
58 bool operator == (
const Name& n)
const;
59 bool operator != (
const Name& n)
const {
return !((*this) == n); }
64 operator std::string()
const {
70 std::ostream& operator << (std::ostream& os,
const Name& n) {
71 return os << n.fullname();
89 class AVRO_DECL
Node :
private boost::noncopyable
95 logicalType_(LogicalType::NONE),
115 bool locked()
const {
119 virtual bool hasName()
const = 0;
121 void setName(
const Name &name) {
126 virtual const Name &name()
const = 0;
128 virtual const std::string &getDoc()
const = 0;
129 void setDoc(
const std::string &doc) {
134 void addLeaf(
const NodePtr &newLeaf) {
138 virtual size_t leaves()
const = 0;
139 virtual const NodePtr& leafAt(
int index)
const = 0;
141 throw Exception(boost::format(
"No default value at: %1%") % index);
144 void addName(
const std::string &name) {
149 virtual size_t names()
const = 0;
150 virtual const std::string &nameAt(
int index)
const = 0;
151 virtual bool nameIndex(
const std::string &name,
size_t &index)
const = 0;
153 void setFixedSize(
int size) {
155 doSetFixedSize(size);
157 virtual int fixedSize()
const = 0;
159 virtual bool isValid()
const = 0;
163 virtual void printJson(std::ostream &os,
int depth)
const = 0;
165 virtual void printBasicInfo(std::ostream &os)
const = 0;
167 virtual void setLeafToSymbolic(
int index,
const NodePtr &node) = 0;
171 virtual void printDefaultToJson(
const GenericDatum& g, std::ostream &os,
172 int depth)
const = 0;
176 void checkLock()
const {
178 throw Exception(
"Cannot modify locked schema");
182 virtual void checkName(
const Name &name)
const {
186 virtual void doSetName(
const Name &name) = 0;
187 virtual void doSetDoc(
const std::string &name) = 0;
189 virtual void doAddLeaf(
const NodePtr &newLeaf) = 0;
190 virtual void doAddName(
const std::string &name) = 0;
191 virtual void doSetFixedSize(
int size) = 0;
203 inline std::ostream& operator<<(std::ostream& os,
const avro::Node& n)
Node is the building block for parse trees.
Definition: Node.hh:89
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:30
SchemaResolution
Definition: SchemaResolution.hh:27
Definition: LogicalType.hh:28
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:61