1 /* 2 * FDBOptions.h 3 * 4 * This source file is part of the FoundationDB open source project 5 * 6 * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 #pragma once 22 #ifndef FDBCLIENT_FDBOPTIONS_H 23 #define FDBCLIENT_FDBOPTIONS_H 24 25 #include <string> 26 #include <map> 27 28 struct FDBOptionInfo { 29 std::string name; 30 std::string comment; 31 std::string parameterComment; 32 33 bool hasParameter; 34 bool hidden; 35 FDBOptionInfoFDBOptionInfo36 FDBOptionInfo(std::string name, std::string comment, std::string parameterComment, bool hasParameter, bool hidden) 37 : name(name), comment(comment), parameterComment(parameterComment), hasParameter(hasParameter), hidden(hidden) { } 38 FDBOptionInfoFDBOptionInfo39 FDBOptionInfo() { } 40 }; 41 42 template<class T> 43 class FDBOptionInfoMap { 44 private: 45 std::map<typename T::Option, FDBOptionInfo> optionInfo; 46 47 public: begin()48 typename std::map<typename T::Option, FDBOptionInfo>::iterator begin() { return optionInfo.begin(); } end()49 typename std::map<typename T::Option, FDBOptionInfo>::iterator end() { return optionInfo.end(); } find(const typename T::Option & key)50 typename std::map<typename T::Option, FDBOptionInfo>::iterator find(const typename T::Option& key) { return optionInfo.find(key); } 51 52 FDBOptionInfo& operator[] (const typename T::Option& key) { return optionInfo[key]; } 53 FDBOptionInfoMap()54 FDBOptionInfoMap() { T::init(); } 55 }; 56 57 #define ADD_OPTION_INFO( type, var, name, comment, parameterComment, hasParameter, hidden ) type::optionInfo[var] = FDBOptionInfo(name, comment, parameterComment, hasParameter, hidden); 58 59 #endif