00001 #ifndef _TestOptions_
00002 #define _TestOptions_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/Options.h"
00025 #include "qpid/log/Options.h"
00026 #include "qpid/Url.h"
00027 #include "qpid/log/Logger.h"
00028 #include "qpid/client/Connection.h"
00029 #include "qpid/client/ConnectionSettings.h"
00030
00031 #include <iostream>
00032 #include <exception>
00033
00034 namespace qpid {
00035
00036 struct TestOptions : public qpid::Options
00037 {
00038 TestOptions(const std::string& helpText_=std::string()) :
00039 Options("Test Options"), help(false), helpText(helpText_)
00040 {
00041 addOptions()
00042 ("help", optValue(help), "print this usage statement");
00043 add(con);
00044 }
00045
00047 void parse(int argc, char** argv) {
00048 try {
00049 qpid::Options::parse(argc, argv);
00050 } catch (const std::exception& e) {
00051 std::ostringstream msg;
00052 msg << *this << std::endl << std::endl << e.what() << std::endl;
00053 throw qpid::Options::Exception(msg.str());
00054 }
00055 qpid::log::Logger::instance().configure(con.log, argv[0]);
00056 if (help) {
00057 std::ostringstream msg;
00058 msg << *this << std::endl << std::endl << helpText << std::endl;
00059 throw qpid::Options::Exception(msg.str());
00060 }
00061 }
00062
00064 void open(qpid::client::Connection& connection) {
00065 connection.open(con);
00066 }
00067
00068
00069 bool help;
00070 client::ConnectionSettings con;
00071 std::string helpText;
00072 };
00073
00074 }
00075
00076 #endif