| Wisp 1.2.1 C++ Unit Test Coverage |
|
|
|
|
|
Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2008 Savarese Software Research Corporation
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.savarese.com/software/ApacheLicense-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 : : /**
18 : : * @file
19 : : * This header defines the ServiceMainOptions class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WISP_UTILITY_SERVICE_MAIN_OPTIONS_H
23 : : #define __SSRC_WISP_UTILITY_SERVICE_MAIN_OPTIONS_H
24 : :
25 : : #include <ssrc/wisp/utility/BasicServiceOptions.h>
26 : :
27 : : #include <fstream>
28 : :
29 : : __BEGIN_NS_SSRC_WISP_UTILITY
30 : :
31 : : class ServiceMainOptions : public BasicServiceOptions {
32 : : boost::program_options::options_description _custom_description;
33 : :
34 : : protected:
35 : :
36 : : ServiceMainOptions() :
37 : : BasicServiceOptions(), _custom_description("Wisp Service"),
38 : : wisp_version(false)
39 : : {
40 : : using namespace boost::program_options;
41 : :
42 : : _custom_description.add_options()
43 : : ("config,f", value<std::vector<std::string> >()->composing(),
44 : : "Specify a configuration file from which to read additional options.")
45 : : ("wisp-version",
46 : : "Print Wisp version with which the service was compiled.");
47 : :
48 : : description.add(_custom_description);
49 : : }
50 : :
51 : 0 : virtual void notify(boost::program_options::variables_map & vm) {
52 : : namespace po = boost::program_options;
53 : :
54 [ # # ][ # # ]: 0 : if(vm.count("config") > 0) {
[ # # ][ # # ]
55 : : std::vector<std::string> config =
56 [ # # ][ # # ]: 0 : vm.find("config")->second.as<std::vector<std::string> >();
[ # # ][ # # ]
[ # # ][ # # ]
57 : :
58 [ # # ][ # # ]: 0 : for(std::vector<std::string>::iterator file = config.begin(); file != config.end(); ++file) {
[ # # ][ # # ]
[ # # ]
59 [ # # ][ # # ]: 0 : std::ifstream ifs(file->c_str());
[ # # ][ # # ]
60 : :
61 [ # # ][ # # ]: 0 : if(ifs.is_open())
62 [ # # ][ # # ]: 0 : po::store(po::parse_config_file(ifs, description), vm);
[ # # ]
63 : : else
64 [ # # ][ # # ]: 0 : throw std::invalid_argument(*file);
65 : : }
66 : : }
67 : :
68 : 0 : BasicServiceOptions::notify(vm);
69 [ # # ][ # # ]: 0 : wisp_version = (vm.count("wisp-version") > 0);
[ # # ]
70 : 0 : }
71 : :
72 : : public:
73 : : bool wisp_version;
74 : :
75 [ # # ][ # # ]: 0 : virtual ~ServiceMainOptions() { }
76 : : };
77 : :
78 : : __END_NS_SSRC_WISP_UTILITY
79 : :
80 : : #endif
|
Copyright © 2012 Savarese Software Research Corporation. All rights reserved