Mailinglist Archive: zypp-devel (68 mails)

< Previous Next >
[zypp-devel] Interim helper class to collect global options and settings
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Wed, 16 May 2007 21:54:12 +0200
  • Message-id: <20070516195412.GA2020@xxxxxxx>

I added class ZConfig:


+#include "zypp/ZConfig.h"
+
+  /** Interim helper class to collect global options and settings.
+   * Use it to avoid hardcoded values and calls to getZypp() just
+   * to retrieve some value like architecture, languages or tmppath.
+  */
+  class ZConfig
+  {
+    public:
+      /** The system architecture. */
+      Arch systemArchitecture() const;
+  };

Not very impressive by now.

- Add methods here instead of hardcoding values (e.g. CacheStore default 
  db location, db filename).

- Add methods for values that are required at multiple locations. There's 
  no need to create a ZYpp object just to ask for a tmpPath.

We'll see how it evolves. 




Example: 
Old parser code:

 #include "zypp/ZYppFactory.h"

 static void replace_variables( std::string &text )
 {
  string::size_type pos = text.find("%a");
  if (pos != string::npos)
  {
    Arch sysarch( getZYpp()->architecture() );
    text.replace( pos, 2, sysarch.asString() );
  }
 }


would become:

 #include "zypp/ZConfig.h"

 static void replace_variables( std::string &text )
 {
  string::size_type pos = text.find("%a");
  if (pos != string::npos)
  {
    text.replace( pos, 2, ZConfig().systemArchitecture().asString() );
  }
 }



If you spot code that calls getZYpp() just to retrieve some setting change 
it to ZConfig. 



-- 

cu,
    Michael Andres

+------------------------------------------------------------------+
Key fingerprint = 2DFA 5D73 18B1 E7EF A862  27AC 3FB8 9E3A 27C6 B0E4
+------------------------------------------------------------------+
Michael Andres             YaST Development            ma@xxxxxxxxxx
SUSE LINUX Products GmbH, GF:  Markus Rex,  HRB 16746 (AG Nuernberg)
Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0
+------------------------------------------------------------------+

-- 
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages