From: Michael Andres Date: Wed, 19 Dec 2012 08:58:37 +0000 (+0100) Subject: Add pointer to command specific options. X-Git-Tag: 1.8.7~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b67b6eebc10e2cd4b05dd2d116202f2866728a60;p=platform%2Fupstream%2Fzypper.git Add pointer to command specific options. --- diff --git a/src/Zypper.cc b/src/Zypper.cc index eb13bf9..fc80b4c 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -57,9 +57,8 @@ #include "output/OutNormal.h" #include "output/OutXML.h" -using namespace std; +using boost::format; using namespace zypp; -using namespace boost; ZYpp::Ptr God = NULL; parsed_opts copts; // command options @@ -602,7 +601,7 @@ void Zypper::processGlobalOptions() if ((it = gopts.find("opt")) != gopts.end()) { cout << "Opt arg: "; std::copy (it->second.begin(), it->second.end(), - ostream_iterator (cout, ", ")); + std::ostream_iterator (cout, ", ")); cout << endl; } @@ -2516,7 +2515,7 @@ void Zypper::processCommandOptions() if (optind < argc()) { - ostringstream s; + std::ostringstream s; s << _("Non-option program arguments: "); while (optind < argc()) { @@ -3074,7 +3073,7 @@ void Zypper::doCommand() if (command() == ZypperCommand::REMOVE_REPO) { // must store repository before remove to ensure correct match number - set repo_to_remove; + std::set repo_to_remove; for_(it, _arguments.begin(), _arguments.end()) { RepoInfo repo; @@ -3097,7 +3096,7 @@ void Zypper::doCommand() } else { - set to_remove; + std::set to_remove; for_(it, _arguments.begin(), _arguments.end()) { repo::RepoInfoBase_Ptr s; @@ -4303,7 +4302,7 @@ copts.end()) { out().error(_("Required argument missing.")); ERR << "Required argument missing." << endl; - ostringstream s; + std::ostringstream s; s << _("Usage") << ':' << endl; s << _command_help; out().info(s.str()); diff --git a/src/Zypper.h b/src/Zypper.h index 7c0be46..830aa91 100644 --- a/src/Zypper.h +++ b/src/Zypper.h @@ -26,10 +26,24 @@ #include "utils/getopt.h" #include "output/Out.h" +// As a matter of fact namespaces std, boost and zypp have overlapping +// symbols (e.g. shared_ptr). We default to the ones used in namespace zypp. +// Symbols from other namespaces should be used explicitly (std::set, boost::format) +// and not by using the whole namespace. +using namespace zypp; + +// Convenience +using std::cout; +using std::cerr; +using std::endl; + /** directory for storing manually installed (zypper install foo.rpm) RPM files */ #define ZYPPER_RPM_CACHE_DIR "/var/cache/zypper/RPMS" +/** Base class for command specific option classes. */ +struct Options { virtual ~Options() {} }; + /** * Structure for holding global options. * @@ -245,6 +259,27 @@ private: int _sh_argc; char **_sh_argv; + + /** Command specific options (see also _copts). */ + shared_ptr _commandOptions; + + /** Convenience to return properly casted _commandOptions. */ + template + shared_ptr<_Opt> commandOptionsAs() const + { return dynamic_pointer_cast<_Opt>( _commandOptions ); } + + /** Convenience to return command options for \c _Op, either casted from _commandOptions or newly created. */ + template + shared_ptr<_Opt> assertCommandOptions() + { + shared_ptr<_Opt> myopt( commandOptionsAs<_Opt>() ); + if ( ! myopt ) + { + myopt.reset( new _Opt() ); + _commandOptions = myopt; + } + return myopt; + } }; void print_main_help(const Zypper & zypper);