bmv2
Designing your own switch target with bmv2
target_parser.h
Go to the documentation of this file.
1 /* Copyright 2013-present Barefoot Networks, Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /*
17  * Antonin Bas (antonin@barefootnetworks.com)
18  *
19  */
20 
29 
30 #ifndef BM_BM_SIM_TARGET_PARSER_H_
31 #define BM_BM_SIM_TARGET_PARSER_H_
32 
33 #include <string>
34 #include <vector>
35 #include <memory>
36 #include <iosfwd>
37 
38 namespace bm {
39 
42  public:
43  virtual ~TargetParserIface() { }
44 
48  virtual int parse(const std::vector<std::string> &more_options,
49  std::ostream *errstream) = 0;
50 
53  virtual void help_msg(std::ostream *outstream) const = 0;
54 };
55 
56 class TargetParserBasicStore;
57 
61  public:
63  enum class ReturnCode {
65  SUCCESS = 0,
74  };
75 
79 
83  int parse(const std::vector<std::string> &more_options,
84  std::ostream *errstream) override;
85 
87  void help_msg(std::ostream *outstream) const override;
88 
92  ReturnCode add_string_option(const std::string &name,
93  const std::string &help_str);
97  ReturnCode add_int_option(const std::string &name,
98  const std::string &help_str);
102  ReturnCode add_uint_option(const std::string &name,
103  const std::string &help_str);
107  ReturnCode add_flag_option(const std::string &name,
108  const std::string &help_str);
109 
112  ReturnCode get_string_option(const std::string &name, std::string *v) const;
115  ReturnCode get_int_option(const std::string &name, int *v) const;
118  ReturnCode get_uint_option(const std::string &name, unsigned int *v) const;
121  ReturnCode get_flag_option(const std::string &name, bool *v) const;
122 
123  private:
124  std::unique_ptr<TargetParserBasicStore> var_store;
125 };
126 
134  public:
137 
141  int parse(const std::vector<std::string> &more_options,
142  std::ostream *errstream) override;
143 
144  private:
146  static constexpr char load_modules_option[] = "load-modules";
147 
148  int load_modules(std::ostream *errstream);
149 };
150 
151 } // namespace bm
152 
153 #endif // BM_BM_SIM_TARGET_PARSER_H_
bm::TargetParserBasic::get_int_option
ReturnCode get_int_option(const std::string &name, int *v) const
bm::TargetParserIface::help_msg
virtual void help_msg(std::ostream *outstream) const =0
bm::TargetParserBasic::ReturnCode
ReturnCode
Return codes for this class.
Definition: target_parser.h:63
bm::TargetParserBasic::TargetParserBasic
TargetParserBasic()
Constructor.
bm::TargetParserIface
Interface for target-specific command-line options parsers.
Definition: target_parser.h:41
bm::TargetParserBasic
Definition: target_parser.h:60
bm::TargetParserBasic::help_msg
void help_msg(std::ostream *outstream) const override
See bm::TargetParserIface::help_msg.
bm::TargetParserBasic::get_uint_option
ReturnCode get_uint_option(const std::string &name, unsigned int *v) const
bm::TargetParserBasic::parse
int parse(const std::vector< std::string > &more_options, std::ostream *errstream) override
bm::TargetParserBasic::ReturnCode::OPTION_NOT_PROVIDED
@ OPTION_NOT_PROVIDED
the option was not provided by the user
bm::TargetParserBasic::ReturnCode::INVALID_OPTION_NAME
@ INVALID_OPTION_NAME
option name not recognized (did not call add)
bm::TargetParserBasic::ReturnCode::DUPLICATE_OPTION
@ DUPLICATE_OPTION
option was already added to the parser
bm::TargetParserBasicWithDynModules
Definition: target_parser.h:133
bm::TargetParserBasic::get_flag_option
ReturnCode get_flag_option(const std::string &name, bool *v) const
bm::TargetParserBasic::get_string_option
ReturnCode get_string_option(const std::string &name, std::string *v) const
bm::TargetParserBasic::ReturnCode::INVALID_OPTION_TYPE
@ INVALID_OPTION_TYPE
type mismatch, you used the wrong get method
bm::TargetParserIface::parse
virtual int parse(const std::vector< std::string > &more_options, std::ostream *errstream)=0
bm::TargetParserBasic::add_string_option
ReturnCode add_string_option(const std::string &name, const std::string &help_str)
bm::TargetParserBasic::add_int_option
ReturnCode add_int_option(const std::string &name, const std::string &help_str)
bm::TargetParserBasic::add_uint_option
ReturnCode add_uint_option(const std::string &name, const std::string &help_str)
bm::TargetParserBasicWithDynModules::load_modules_option
static constexpr char load_modules_option[]
Name of the option.
Definition: target_parser.h:146
bm::TargetParserBasic::ReturnCode::SUCCESS
@ SUCCESS
successful operation
bm::TargetParserBasic::add_flag_option
ReturnCode add_flag_option(const std::string &name, const std::string &help_str)
bm::TargetParserBasicWithDynModules::parse
int parse(const std::vector< std::string > &more_options, std::ostream *errstream) override