1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#ifndef ARROW_UTIL_KEY_VALUE_METADATA_H
19#define ARROW_UTIL_KEY_VALUE_METADATA_H
20
21#include <cstdint>
22#include <memory>
23#include <string>
24#include <unordered_map>
25#include <vector>
26
27#include "arrow/util/macros.h"
28#include "arrow/util/visibility.h"
29
30namespace arrow {
31
32class ARROW_EXPORT KeyValueMetadata {
33 public:
34 KeyValueMetadata();
35 KeyValueMetadata(const std::vector<std::string>& keys,
36 const std::vector<std::string>& values);
37 explicit KeyValueMetadata(const std::unordered_map<std::string, std::string>& map);
38 virtual ~KeyValueMetadata() = default;
39
40 void ToUnorderedMap(std::unordered_map<std::string, std::string>* out) const;
41
42 void Append(const std::string& key, const std::string& value);
43
44 void reserve(int64_t n);
45 int64_t size() const;
46
47 std::string key(int64_t i) const;
48 std::string value(int64_t i) const;
49
50 std::shared_ptr<KeyValueMetadata> Copy() const;
51
52 bool Equals(const KeyValueMetadata& other) const;
53 std::string ToString() const;
54
55 private:
56 std::vector<std::string> keys_;
57 std::vector<std::string> values_;
58
59 ARROW_DISALLOW_COPY_AND_ASSIGN(KeyValueMetadata);
60};
61
62/// \brief Create a KeyValueMetadata instance
63///
64/// \param pairs key-value mapping
65std::shared_ptr<KeyValueMetadata> ARROW_EXPORT
66key_value_metadata(const std::unordered_map<std::string, std::string>& pairs);
67
68} // namespace arrow
69
70#endif // ARROW_UTIL_KEY_VALUE_METADATA_H
71