Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
Options.h
Go to the documentation of this file.
1 #ifndef QPID_COMMONOPTIONS_H
2 #define QPID_COMMONOPTIONS_H
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "qpid/Exception.h"
26 
27 // Disable warnings triggered by boost.
28 #ifdef _MSC_VER
29 # pragma warning(push)
30 # pragma warning(disable : 4251 4275)
31 #endif
32 
33 #include <boost/program_options.hpp>
34 #include <boost/format.hpp>
35 
36 #ifdef _MSC_VER
37 # pragma warning(pop)
38 #endif
39 
40 #include <sstream>
41 #include <iterator>
42 #include <algorithm>
43 #include <string>
45 
46 namespace qpid {
47 namespace po=boost::program_options;
48 
49 
50 
52 QPID_COMMON_EXTERN std::string prettyArg(const std::string&, const std::string&);
53 
55 template <class T>
56 class OptionValue : public po::typed_value<T> {
57  public:
58  OptionValue(T& value, const std::string& arg)
59  : po::typed_value<T>(&value), argName(arg) {}
60  std::string name() const { return argName; }
61 
62  private:
63  std::string argName;
64 };
65 
66 
73 template<class T>
74 po::value_semantic* optValue(T& value, const char* name) {
75  std::string valstr(boost::lexical_cast<std::string>(value));
76  return new OptionValue<T>(value, prettyArg(name, valstr));
77 }
78 
82 template <class T>
83 po::value_semantic* optValue(std::vector<T>& value, const char* name) {
84  std::ostringstream os;
85  std::copy(value.begin(), value.end(), std::ostream_iterator<T>(os, " "));
86  std::string val=os.str();
87  if (!val.empty())
88  val.erase(val.end()-1); // Remove trailing " "
89  return (new OptionValue<std::vector<T> >(value, prettyArg(name, val)));
90 }
91 
93 inline po::value_semantic* optValue(bool& value) { return po::bool_switch(&value); }
94 
135 struct Options : public po::options_description {
136 
137  struct Exception : public qpid::Exception {
138  Exception(const std::string& msg) : qpid::Exception(msg) {}
139  };
140 
141  QPID_COMMON_EXTERN Options(const std::string& name=std::string());
142 
148  QPID_COMMON_EXTERN void parse(int argc, char const* const* argv,
149  const std::string& configfile=std::string(),
150  bool allowUnknown = false);
151 
155  QPID_COMMON_EXTERN bool findArg(int argc, char const* const* argv,
156  const std::string& theArg);
157 
158  boost::program_options::options_description_easy_init addOptions() {
159  return add_options();
160  }
161 };
162 
163 
164 
168 struct CommonOptions : public Options {
169  QPID_COMMON_EXTERN CommonOptions(const std::string& name=std::string(),
170  const std::string& configfile=std::string(),
171  const std::string& clientConfigFile=std::string());
172  bool help;
173  bool version;
174  std::string config;
175  std::string clientConfig;
176 };
177 
178 
179 
180 
181 } // namespace qpid
182 
183 #endif

Qpid C++ API Reference
Generated on Tue Jul 2 2013 for Qpid C++ Client API by doxygen 1.8.3.1