• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LATINIME_DICT_TOOLKIT_ARGUMENTS_AND_OPTIONS_H
18 #define LATINIME_DICT_TOOLKIT_ARGUMENTS_AND_OPTIONS_H
19 
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "dict_toolkit_defines.h"
25 
26 namespace latinime {
27 namespace dicttoolkit {
28 
29 class ArgumentsAndOptions {
30  public:
ArgumentsAndOptions()31     ArgumentsAndOptions() : mIsValid(false), mOptions(), mArguments() {}
32 
ArgumentsAndOptions(std::unordered_map<std::string,std::string> && options,std::unordered_map<std::string,std::vector<std::string>> && arguments)33     ArgumentsAndOptions(std::unordered_map<std::string, std::string> &&options,
34             std::unordered_map<std::string, std::vector<std::string>> &&arguments)
35             : mIsValid(true), mOptions(std::move(options)), mArguments(std::move(arguments)) {}
36 
isValid()37     bool isValid() const {
38         return mIsValid;
39     }
40 
hasOption(const std::string & optionName)41     bool hasOption(const std::string &optionName) const {
42         return mOptions.find(optionName) != mOptions.end();
43     }
44 
getOptionValue(const std::string & optionName)45     const std::string &getOptionValue(const std::string &optionName) const {
46         const auto &it = mOptions.find(optionName);
47         ASSERT(it != mOptions.end());
48         return it->second;
49     }
50 
hasArgument(const std::string & name)51     bool hasArgument(const std::string &name) const {
52         const auto &it = mArguments.find(name);
53         return it != mArguments.end() && !it->second.empty();
54     }
55 
getSingleArgument(const std::string & name)56     const std::string &getSingleArgument(const std::string &name) const {
57         const auto &it = mArguments.find(name);
58         ASSERT(it != mArguments.end() && !it->second.empty());
59         return it->second.front();
60     }
61 
getVariableLengthArguments(const std::string & name)62     const std::vector<std::string> &getVariableLengthArguments(const std::string &name) const {
63         const auto &it = mArguments.find(name);
64         ASSERT(it != mArguments.end());
65         return it->second;
66     }
67 
68  private:
69     DISALLOW_ASSIGNMENT_OPERATOR(ArgumentsAndOptions);
70 
71     const bool mIsValid;
72     const std::unordered_map<std::string, std::string> mOptions;
73     const std::unordered_map<std::string, std::vector<std::string>> mArguments;
74 };
75 } // namespace dicttoolkit
76 } // namespace latinime
77 #endif // LATINIME_DICT_TOOLKIT_ARGUMENTS_AND_OPTIONS_H
78