Add pointer to command specific options.
authorMichael Andres <ma@suse.de>
Wed, 19 Dec 2012 08:58:37 +0000 (09:58 +0100)
committerMichael Andres <ma@suse.de>
Wed, 19 Dec 2012 08:58:37 +0000 (09:58 +0100)
src/Zypper.cc
src/Zypper.h

index eb13bf9..fc80b4c 100644 (file)
@@ -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<string> (cout, ", "));
+               std::ostream_iterator<string> (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<RepoInfo,RepoInfoAliasComparator> repo_to_remove;
+      std::set<RepoInfo,RepoInfoAliasComparator> repo_to_remove;
       for_(it, _arguments.begin(), _arguments.end())
       {
         RepoInfo repo;
@@ -3097,7 +3096,7 @@ void Zypper::doCommand()
     }
     else
     {
-      set<repo::RepoInfoBase_Ptr, ServiceAliasComparator> to_remove;
+      std::set<repo::RepoInfoBase_Ptr, ServiceAliasComparator> 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());
index 7c0be46..830aa91 100644 (file)
 #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<Options>  _commandOptions;
+
+  /** Convenience to return properly casted _commandOptions. */
+  template<class _Opt>
+  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<class _Opt>
+  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);