Savarese Software Research Corporation
ServiceMainOptions.h
Go to the documentation of this file.
1 /* Copyright 2006-2013 Savarese Software Research Corporation.
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.savarese.com/software/ApacheLicense-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 
21 #ifndef __SSRC_WISP_UTILITY_SERVICE_MAIN_OPTIONS_H
22 #define __SSRC_WISP_UTILITY_SERVICE_MAIN_OPTIONS_H
23 
25 
26 #include <fstream>
27 
29 
31  boost::program_options::options_description _custom_description;
32 
33 protected:
34 
36  BasicServiceOptions(), _custom_description("Wisp Service"),
37  wisp_version(false)
38  {
39  using namespace boost::program_options;
40 
41  _custom_description.add_options()
42  ("config,f", value<std::vector<std::string> >()->composing(),
43  "Specify a configuration file from which to read additional options.")
44  ("wisp-version",
45  "Print Wisp version with which the service was compiled.");
46 
47  description.add(_custom_description);
48  }
49 
50  virtual void notify(boost::program_options::variables_map & vm) {
51  namespace po = boost::program_options;
52 
53  if(vm.count("config") > 0) {
54  std::vector<std::string> config =
55  vm.find("config")->second.as<std::vector<std::string> >();
56 
57  for(std::vector<std::string>::iterator file = config.begin(); file != config.end(); ++file) {
58  std::ifstream ifs(file->c_str());
59 
60  if(ifs.is_open())
61  po::store(po::parse_config_file(ifs, description), vm);
62  else
63  throw std::invalid_argument(*file);
64  }
65  }
66 
68  wisp_version = (vm.count("wisp-version") > 0);
69  }
70 
71 public:
72  bool wisp_version;
73 
74  virtual ~ServiceMainOptions() = default;
75 };
76 
78 
79 #endif

Savarese Software Research Corporation
Copyright © 2006-2012 Savarese Software Research Corporation. All rights reserved.