Avro C++
CustomFields.hh
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  * http://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_CustomFields_hh__
20 #define avro_CustomFields_hh__
21 
22 #include <iostream>
23 
24 #include "../impl/json/JsonDom.hh"
25 
26 namespace avro {
27 
28 // CustomFields class stores avro custom attributes.
29 // Each field is represented by a unique name and value.
30 // User is supposed to create CustomFields object and then add it to Schema.
31 class AVRO_DECL CustomFields {
32  public:
33  // Retrieves the custom field json entity for that fieldName, returns an
34  // null Entity if the field doesn't exist.
35  json::Entity getField(const std::string &fieldName) const;
36 
37  // Adds a custom field. If the field already exists, throw an exception.
38  void addField(const std::string &fieldName, const json::Entity &fieldValue);
39  void addField(const std::string &fieldName, const std::string &fieldValue);
40 
41  // Provides a way to iterate over the custom fields or check field size.
42  const std::map<std::string, json::Entity> &fields() const {
43  return fields_;
44  }
45 
46  // Prints the json string for the specific field.
47  void printJson(std::ostream& os, const std::string &fieldName) const;
48 
49  private:
50  std::map<std::string, json::Entity> fields_;
51 };
52 
53 } // namespace avro
54 
55 #endif
avro::CustomFields
Definition: CustomFields.hh:31
avro
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30