3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
20 #define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
22 #include "src/compiler/config.h"
24 #include <initializer_list>
27 #include <ostream> // NOLINT
30 using std::initializer_list;
34 namespace grpc_ruby_generator {
36 // Converts an initializer list of the form { key0, value0, key1, value1, ... }
37 // into a map of key* to value*. Is merely a readability helper for later code.
38 inline std::map<grpc::string, grpc::string> ListToDict(
39 const initializer_list<grpc::string>& values) {
40 if (values.size() % 2 != 0) {
41 std::cerr << "Not every 'key' has a value in `values`." << std::endl;
43 std::map<grpc::string, grpc::string> value_map;
44 auto value_iter = values.begin();
45 for (unsigned i = 0; i < values.size() / 2; ++i) {
46 grpc::string key = *value_iter;
48 grpc::string value = *value_iter;
49 value_map[key] = value;
55 } // namespace grpc_ruby_generator
57 #endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H