Schema.hh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef avro_Schema_hh__
  19. #define avro_Schema_hh__
  20. #include "Config.hh"
  21. #include "NodeImpl.hh"
  22. #include <string>
  23. /// \file
  24. ///
  25. /// Schemas for representing all the avro types. The compound schema objects
  26. /// allow composition from other schemas.
  27. ///
  28. namespace avro {
  29. /// The root Schema object is a base class. Nobody constructs this class directly.
  30. class AVRO_DECL Schema {
  31. public:
  32. virtual ~Schema() = default;
  33. Type type() const {
  34. return node_->type();
  35. }
  36. const NodePtr &root() const {
  37. return node_;
  38. }
  39. NodePtr &root() {
  40. return node_;
  41. }
  42. protected:
  43. explicit Schema(NodePtr node) : node_(std::move(node)) {}
  44. explicit Schema(Node *node) : node_(node) {}
  45. NodePtr node_;
  46. };
  47. class AVRO_DECL NullSchema : public Schema {
  48. public:
  49. NullSchema() : Schema(new NodePrimitive(AVRO_NULL)) {}
  50. };
  51. class AVRO_DECL BoolSchema : public Schema {
  52. public:
  53. BoolSchema() : Schema(new NodePrimitive(AVRO_BOOL)) {}
  54. };
  55. class AVRO_DECL IntSchema : public Schema {
  56. public:
  57. IntSchema() : Schema(new NodePrimitive(AVRO_INT)) {}
  58. };
  59. class AVRO_DECL LongSchema : public Schema {
  60. public:
  61. LongSchema() : Schema(new NodePrimitive(AVRO_LONG)) {}
  62. };
  63. class AVRO_DECL FloatSchema : public Schema {
  64. public:
  65. FloatSchema() : Schema(new NodePrimitive(AVRO_FLOAT)) {}
  66. };
  67. class AVRO_DECL DoubleSchema : public Schema {
  68. public:
  69. DoubleSchema() : Schema(new NodePrimitive(AVRO_DOUBLE)) {}
  70. };
  71. class AVRO_DECL StringSchema : public Schema {
  72. public:
  73. StringSchema() : Schema(new NodePrimitive(AVRO_STRING)) {}
  74. };
  75. class AVRO_DECL BytesSchema : public Schema {
  76. public:
  77. BytesSchema() : Schema(new NodePrimitive(AVRO_BYTES)) {}
  78. };
  79. class AVRO_DECL RecordSchema : public Schema {
  80. public:
  81. explicit RecordSchema(const std::string &name);
  82. void addField(const std::string &name, const Schema &fieldSchema);
  83. std::string getDoc() const;
  84. void setDoc(const std::string &);
  85. };
  86. class AVRO_DECL EnumSchema : public Schema {
  87. public:
  88. explicit EnumSchema(const std::string &name);
  89. void addSymbol(const std::string &symbol);
  90. };
  91. class AVRO_DECL ArraySchema : public Schema {
  92. public:
  93. explicit ArraySchema(const Schema &itemsSchema);
  94. ArraySchema(const ArraySchema &itemsSchema);
  95. };
  96. class AVRO_DECL MapSchema : public Schema {
  97. public:
  98. explicit MapSchema(const Schema &valuesSchema);
  99. MapSchema(const MapSchema &itemsSchema);
  100. };
  101. class AVRO_DECL UnionSchema : public Schema {
  102. public:
  103. UnionSchema();
  104. void addType(const Schema &typeSchema);
  105. };
  106. class AVRO_DECL FixedSchema : public Schema {
  107. public:
  108. FixedSchema(int size, const std::string &name);
  109. };
  110. class AVRO_DECL SymbolicSchema : public Schema {
  111. public:
  112. SymbolicSchema(const Name &name, const NodePtr &link);
  113. };
  114. } // namespace avro
  115. #endif