00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the 00007 * "License"); you may not use this file except in compliance 00008 * with the License. You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #ifndef avro_Schema_hh__ 00020 #define avro_Schema_hh__ 00021 00022 #include "NodeImpl.hh" 00023 00029 00030 namespace avro { 00031 00032 class ValidSchema; 00033 00034 00036 00037 class Schema 00038 { 00039 public: 00040 00041 virtual ~Schema(); 00042 00043 Type type() const { 00044 return node_->type(); 00045 } 00046 00047 const NodePtr &root() const { 00048 return node_; 00049 } 00050 00051 NodePtr &root() { 00052 return node_; 00053 } 00054 00055 protected: 00056 00057 friend void compileJsonSchema(std::istream &is, ValidSchema &schema); 00058 00059 Schema(); 00060 explicit Schema(const NodePtr &node); 00061 explicit Schema(Node *node); 00062 00063 NodePtr node_; 00064 }; 00065 00066 class NullSchema : public Schema 00067 { 00068 public: 00069 NullSchema(): Schema(new NodePrimitive(AVRO_NULL)) {} 00070 }; 00071 00072 class BoolSchema : public Schema 00073 { 00074 public: 00075 BoolSchema(): Schema(new NodePrimitive(AVRO_BOOL)) {} 00076 }; 00077 00078 class IntSchema : public Schema 00079 { 00080 public: 00081 IntSchema(): Schema(new NodePrimitive(AVRO_INT)) {} 00082 }; 00083 00084 class LongSchema : public Schema 00085 { 00086 public: 00087 LongSchema(): Schema(new NodePrimitive(AVRO_LONG)) {} 00088 }; 00089 00090 class FloatSchema : public Schema 00091 { 00092 public: 00093 FloatSchema(): Schema(new NodePrimitive(AVRO_FLOAT)) {} 00094 }; 00095 00096 class DoubleSchema : public Schema 00097 { 00098 public: 00099 DoubleSchema(): Schema(new NodePrimitive(AVRO_DOUBLE)) {} 00100 }; 00101 00102 class StringSchema : public Schema 00103 { 00104 public: 00105 StringSchema(): Schema(new NodePrimitive(AVRO_STRING)) {} 00106 }; 00107 00108 class BytesSchema : public Schema 00109 { 00110 public: 00111 BytesSchema(): Schema(new NodePrimitive(AVRO_BYTES)) {} 00112 }; 00113 00114 class RecordSchema : public Schema 00115 { 00116 public: 00117 00118 RecordSchema(const std::string &name); 00119 void addField(const std::string &name, const Schema &fieldSchema); 00120 }; 00121 00122 class EnumSchema : public Schema 00123 { 00124 public: 00125 00126 EnumSchema(const std::string &name); 00127 void addSymbol(const std::string &symbol); 00128 }; 00129 00130 class ArraySchema : public Schema 00131 { 00132 public: 00133 00134 ArraySchema(const Schema &itemsSchema); 00135 }; 00136 00137 class MapSchema : public Schema 00138 { 00139 public: 00140 00141 MapSchema(const Schema &valuesSchema); 00142 }; 00143 00144 00145 class UnionSchema : public Schema 00146 { 00147 public: 00148 00149 UnionSchema(); 00150 void addType(const Schema &typeSchema); 00151 }; 00152 00153 class FixedSchema : public Schema 00154 { 00155 public: 00156 00157 FixedSchema(int size, const std::string &name); 00158 }; 00159 00160 } // namespace avro 00161 00162 #endif