MongoDB  2.7.0
option_section.h
1 /* Copyright 2013 10gen 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 #pragma once
17 #include "mongo/util/options_parser/option_description.h"
18 
19 #include <boost/program_options.hpp>
20 #include <boost/shared_ptr.hpp>
21 #include <iostream>
22 #include <list>
23 
24 #include "mongo/base/status.h"
25 
26 namespace mongo {
27 namespace optionenvironment {
28 
29  namespace po = boost::program_options;
30 
67  class OptionSection {
68  public:
69  OptionSection(const std::string& name) : _name(name) { }
70  OptionSection() { }
71 
72  // Construction interface
73 
78  Status addSection(const OptionSection& subSection);
79 
103  OptionDescription& addOptionChaining(const std::string& dottedName,
104  const std::string& singleName,
105  const OptionType type,
106  const std::string& description);
107 
108  // These functions are used by the OptionsParser to make calls into boost::program_options
109  Status getBoostOptions(po::options_description* boostOptions,
110  bool visibleOnly = false,
111  bool includeDefaults = false,
112  OptionSources = SourceAll,
113  bool getEmptySections = true) const;
114  Status getBoostPositionalOptions(
115  po::positional_options_description* boostPositionalOptions) const;
116 
117  // This is needed so that the parser can iterate over all registered options to get the
118  // correct names when populating the Environment, as well as check that a parameter that was
119  // found has been registered and has the correct type
120  Status getAllOptions(std::vector<OptionDescription>* options) const;
121 
122  // Count the number of options in this section and all subsections
123  Status countOptions(int* numOptions, bool visibleOnly, OptionSources sources) const;
124 
129  Status getDefaults(std::map<Key, Value>* values) const;
130 
135  Status getConstraints(std::vector<boost::shared_ptr<Constraint > >* constraints) const;
136 
137  std::string positionalHelpString(const std::string& execName) const;
138  std::string helpString() const;
139 
140  // Debugging
141  void dump() const;
142 
143  private:
144  std::string _name;
145  std::list<OptionSection> _subSections;
146  std::list<OptionDescription> _options;
147  };
148 
149 } // namespace optionenvironment
150 } // namespace mongo
A container for OptionDescription instances as well as other OptionSection instances.
Definition: option_section.h:67
OptionDescription & addOptionChaining(const std::string &dottedName, const std::string &singleName, const OptionType type, const std::string &description)
Add an option to this section, and returns a reference to an OptionDescription to allow for chaining...
Definition: option_section.cpp:45
Status addSection(const OptionSection &subSection)
Add a sub section to this section.
Definition: option_section.cpp:30
The OptionDescription class is a container for information about the options we are expecting either ...
Definition: option_description.h:61
Status getConstraints(std::vector< boost::shared_ptr< Constraint > > *constraints) const
Populates the given vector with all the constraints for all options in this section and sub sections...
Definition: option_section.cpp:598
Status getDefaults(std::map< Key, Value > *values) const
Populates the given map with all the default values for any options in this option section and all su...
Definition: option_section.cpp:555