/opt/workspace/qpid/tags/M2/Final/cpp/lib/common/CommonOptions.h

00001 #ifndef QPID_COMMONOPTIONS_H
00002 #define QPID_COMMONOPTIONS_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  *
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include <boost/program_options.hpp>
00026 #include <boost/format.hpp>
00027 
00028 namespace qpid { 
00029 
00031 namespace program_options {
00032 
00033 using namespace boost::program_options;
00034 
00036 template <class T>
00037 class OptionValue : public typed_value<T> {
00038   public:
00039     OptionValue(T& value, const std::string& arg)
00040         : typed_value<T>(&value), argName(arg) {}
00041     std::string name() const { return argName; }
00042   private:
00043     std::string argName;
00044 };
00045 
00056 template<class T>
00057 value_semantic* optValue(T& value, const char* arg) {
00058     std::string val(boost::lexical_cast<std::string>(value));
00059     std::string argName(
00060         val.empty() ? std::string(arg) :
00061         (boost::format("%s (=%s) ") % arg % val).str());
00062     return new OptionValue<T>(value, argName);
00063 }
00064 
00069 struct EnvMapper {
00070     EnvMapper(const options_description& o) : opts(o) {}
00071     std::string operator()(const std::string& env);
00072     const options_description& opts;
00073 };
00074 
00078 inline value_semantic* optValue(bool& value) { return bool_switch(&value); }
00079 
00080 } // namespace program_options
00081 
00082 namespace po=program_options;   // Convenience alias.
00083 
00087 struct CommonOptions {
00088     static const int DEFAULT_PORT;
00089 
00090     CommonOptions();
00091 
00092     bool trace;
00093     int port;
00094 
00096     void addTo(po::options_description&);
00097 };
00098 
00099 } // namespace qpid
00100 
00101 #endif  

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1