Avro C++
Schema.hh
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * https://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef avro_Schema_hh__
20 #define avro_Schema_hh__
21 
22 #include "Config.hh"
23 #include "NodeImpl.hh"
24 #include "CustomFields.hh"
25 #include <string>
26 
32 
33 namespace avro {
34 
36 
37 class AVRO_DECL Schema {
38 public:
39  virtual ~Schema() = default;
40 
41  Type type() const {
42  return node_->type();
43  }
44 
45  const NodePtr &root() const {
46  return node_;
47  }
48 
49  NodePtr &root() {
50  return node_;
51  }
52 
53 protected:
54  explicit Schema(NodePtr node) : node_(std::move(node)) {}
55  explicit Schema(Node *node) : node_(node) {}
56 
57  NodePtr node_;
58 };
59 
60 class AVRO_DECL NullSchema : public Schema {
61 public:
63 };
64 
65 class AVRO_DECL BoolSchema : public Schema {
66 public:
68 };
69 
70 class AVRO_DECL IntSchema : public Schema {
71 public:
73 };
74 
75 class AVRO_DECL LongSchema : public Schema {
76 public:
78 };
79 
80 class AVRO_DECL FloatSchema : public Schema {
81 public:
83 };
84 
85 class AVRO_DECL DoubleSchema : public Schema {
86 public:
88 };
89 
90 class AVRO_DECL StringSchema : public Schema {
91 public:
93 };
94 
95 class AVRO_DECL BytesSchema : public Schema {
96 public:
98 };
99 
100 class AVRO_DECL RecordSchema : public Schema {
101 public:
102  explicit RecordSchema(const std::string &name);
103  void addField(const std::string &name, const Schema &fieldSchema);
104  // Add a field with custom attributes
105  void addField(const std::string &name, const Schema &fieldSchema,
106  const CustomFields &customFields);
107 
108  std::string getDoc() const;
109  void setDoc(const std::string &);
110 };
111 
112 class AVRO_DECL EnumSchema : public Schema {
113 public:
114  explicit EnumSchema(const std::string &name);
115  void addSymbol(const std::string &symbol);
116 };
117 
118 class AVRO_DECL ArraySchema : public Schema {
119 public:
120  explicit ArraySchema(const Schema &itemsSchema);
121  ArraySchema(const ArraySchema &itemsSchema);
122 };
123 
124 class AVRO_DECL MapSchema : public Schema {
125 public:
126  explicit MapSchema(const Schema &valuesSchema);
127  MapSchema(const MapSchema &itemsSchema);
128 };
129 
130 class AVRO_DECL UnionSchema : public Schema {
131 public:
132  UnionSchema();
133  void addType(const Schema &typeSchema);
134 };
135 
136 class AVRO_DECL FixedSchema : public Schema {
137 public:
138  FixedSchema(int size, const std::string &name);
139 };
140 
141 class AVRO_DECL SymbolicSchema : public Schema {
142 public:
143  SymbolicSchema(const Name &name, const NodePtr &link);
144 };
145 } // namespace avro
146 
147 #endif
avro::AVRO_NULL
@ AVRO_NULL
Definition: Types.hh:40
avro::ArraySchema
Definition: Schema.hh:118
avro::UnionSchema
Definition: Schema.hh:130
avro::Node
Node is the building block for parse trees.
Definition: Node.hh:91
avro::AVRO_LONG
@ AVRO_LONG
Definition: Types.hh:36
avro::FixedSchema
Definition: Schema.hh:136
avro::StringSchema
Definition: Schema.hh:90
avro::AVRO_FLOAT
@ AVRO_FLOAT
Definition: Types.hh:37
avro::AVRO_BOOL
@ AVRO_BOOL
Definition: Types.hh:39
avro::NullSchema
Definition: Schema.hh:60
avro::AVRO_STRING
@ AVRO_STRING
Definition: Types.hh:33
avro::Name
Definition: Node.hh:42
avro::IntSchema
Definition: Schema.hh:70
avro::BoolSchema
Definition: Schema.hh:65
avro::AVRO_BYTES
@ AVRO_BYTES
Definition: Types.hh:34
avro::CustomFields
Definition: CustomFields.hh:31
avro::SymbolicSchema
Definition: Schema.hh:141
avro::RecordSchema
Definition: Schema.hh:100
avro::NodePrimitive
Definition: NodeImpl.hh:242
avro::AVRO_INT
@ AVRO_INT
Definition: Types.hh:35
avro
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
avro::DoubleSchema
Definition: Schema.hh:85
avro::AVRO_DOUBLE
@ AVRO_DOUBLE
Definition: Types.hh:38
avro::Schema
The root Schema object is a base class. Nobody constructs this class directly.
Definition: Schema.hh:37
avro::MapSchema
Definition: Schema.hh:124
avro::Type
Type
The "type" for the schema.
Definition: Types.hh:31
avro::FloatSchema
Definition: Schema.hh:80
avro::BytesSchema
Definition: Schema.hh:95
avro::EnumSchema
Definition: Schema.hh:112
avro::LongSchema
Definition: Schema.hh:75