- Make the container function use iterators (thanks ma)
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 11 Jun 2007 13:35:29 +0000 (13:35 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 11 Jun 2007 13:35:29 +0000 (13:35 +0000)
  it allows any class that has asString() now, in
  any container that has iterators.
- add product implementation

12 files changed:
zypp/CMakeLists.txt
zypp/base/String.cc
zypp/base/String.h
zypp/cache/CacheStore.cpp
zypp/cache/CacheStore.h
zypp/cache/ResolvableQuery.cc
zypp/cache/ResolvableQuery.h
zypp/detail/ProductImplIf.cc
zypp/detail/ProductImplIf.h
zypp/repo/cached/PackageImpl.cc
zypp/repo/cached/ProductImpl.cc [new file with mode: 0644]
zypp/repo/cached/ProductImpl.h [new file with mode: 0644]

index 47585b5..d165d1d 100644 (file)
@@ -1083,6 +1083,7 @@ SET( zypp_repository_cached_SRCS
   repo/cached/PackageImpl.cc
   repo/cached/PatchImpl.cc
   repo/cached/PatternImpl.cc
+  repo/cached/ProductImpl.cc
 )
 
 SET( zypp_repository_cached_HEADERS
@@ -1090,6 +1091,7 @@ SET( zypp_repository_cached_HEADERS
   repo/cached/PackageImpl.h
   repo/cached/PatchImpl.h
   repo/cached/PatternImpl.h
+  repo/cached/ProductImpl.h
 )
 
 SET( zypp_repository_data_SRCS
index 85dd7d3..e1aaa1f 100644 (file)
@@ -22,7 +22,12 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
   namespace str
   { /////////////////////////////////////////////////////////////////
-
+    template<>
+    std::string asString( const std::string &t )
+    {
+      return t;
+    }
+    
     /******************************************************************
      **
      **      FUNCTION NAME : form
index a9435e0..cc4a24c 100644 (file)
@@ -27,6 +27,19 @@ namespace zypp
   { /////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
+    /**
+     * Global asString() that works with std::string too
+     */
+    template<class _T>
+    std::string asString( const _T &t )
+    {
+      return t.asString();
+    }
+
+    template<>
+    std::string asString( const std::string &t );
+    
+    ///////////////////////////////////////////////////////////////////
     /** Printf style construction of std::string. */
     std::string form( const char * format, ... )
     __attribute__ ((format (printf, 1, 2)));
@@ -261,7 +274,7 @@ namespace zypp
           {
             if ( iter != begin )
               res += sep_r;
-            res += *iter;
+            res += asString(*iter);
           }
         return res;
       }
index 38eb396..9594586 100644 (file)
@@ -7,7 +7,6 @@
 #include "zypp/base/Measure.h"
 #include "zypp/ZYppFactory.h"
 #include "zypp/ZYpp.h"
-#include "zypp/ZConfig.h"
 #include "zypp/Package.h"
 #include "zypp/cache/CacheInitializer.h"
 #include "zypp/cache/CacheStore.h"
@@ -233,8 +232,8 @@ void CacheStore::appendPackageBaseAttributes( const RecordId & pkgid,
   appendStringAttribute( pkgid, "Package", "postin", package->postin );
   appendStringAttribute( pkgid, "Package", "preun", package->preun );
   appendStringAttribute( pkgid, "Package", "postun", package->postun );
-  appendStringContainerAttribute( pkgid, "Package", "keywords", package->keywords );
-  appendStringContainerAttribute( pkgid, "Package", "authors", package->authors );
+  appendStringContainerAttribute( pkgid, "Package", "keywords", package->keywords.begin(), package->keywords.end() );
+  appendStringContainerAttribute( pkgid, "Package", "authors", package->authors.begin(), package->authors.end() );
   appendStringAttribute( pkgid, "Package", "location", package->repositoryLocation.filePath.asString() );
 }
 
@@ -377,7 +376,7 @@ void CacheStore::consumeProduct( const data::RecordId & repository_id,
 
   appendTranslatedStringAttribute( id, "Product", "shortName", product->shortName );
   appendTranslatedStringAttribute( id, "Product", "longName", product->longName );
-  appendStringContainerAttribute( id, "Product", "flags", product->flags );
+  appendStringContainerAttribute( id, "Product", "flags", product->flags.begin(), product->flags.end() );
   appendStringAttribute( id, "Pattern", "releasenotesUrl", product->releasenotesUrl.asString() );
   //! \todo figure out how to store list of Urls. A separate method appendUrlContainerAttribute? Or change it to plain string in ResolvableData.h?
 //  appendStringContainerAttribute( id, "Product", "updateUrls", product->updateUrls );
@@ -1017,38 +1016,6 @@ void CacheStore::appendStringAttribute( const RecordId &resolvable_id,
   _pimpl->append_text_attribute_cmd->executenonquery();
 }
 
-template <class _Container>
-void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id,
-                                                 const std::string &klass,
-                                                 const std::string &name,
-                                                 const _Container &cont )
-{
-  // don't bother with writing if the container is empty
-  if (cont.empty()) return;
-
-  string value = str::join(cont, ZConfig().cacheDBSplitJoinSeparator());
-
-  appendStringAttribute( resolvable_id, klass, name, value );
-}
-
-template
-void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id,
-                                                 const std::string &klass,
-                                                 const std::string &name,
-                                                 const std::set<std::string> &cont );
-template
-void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id,
-                                                 const std::string &klass,
-                                                 const std::string &name,
-                                                 const std::list<std::string> &cont );
-template
- void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id,
-                                                  const std::string &klass,
-                                                  const std::string &name,
-                                                  const Package::Keywords &cont );
-
-    
-    
 }
 }
 
index b392623..09c7f04 100644 (file)
@@ -18,6 +18,7 @@
 #include "zypp/base/PtrTypes.h"
 #include "zypp/Pathname.h"
 #include "zypp/NVRA.h"
+#include "zypp/ZConfig.h"
 #include "zypp/capability/CapabilityImpl.h"
 #include "zypp/capability/Capabilities.h"
 
@@ -474,21 +475,30 @@ namespace zypp
 
 
       /**
-       * Append strings from _Container to a resolvable.
-       * Uses \ref zypp::str::split(_Container, std::string) with
+       * Append strings from _Iterator to a resolvable.
+       *
+       * Uses \ref zypp::str::split(_Iterator,_Iterator, std::string) with
        * \ref ZConfig::cacheDBSplitJoinSeparator() as the second argument
        * (a separator string) of split().
-       * 
+       *
+       * Any container of any class providing asString() can be used.
+       *
        * \param resolvable_id Resovable Id, owner of the attribute
        * \param klass Type class i.e "Package" "lang" "kind"
        * \param name Type name i.e : "summary" "none" "Script"
-       * \param cont The string container.
+       * \param begin begin Iterator to the container
+       * \param end end Iterator to the container
        */
-      template <class _Container>
+      template <class _Iterator>
       void appendStringContainerAttribute( const data::RecordId &resolvable_id,
                                            const std::string &klass,
                                            const std::string &name,
-                                           const _Container &cont );
+                                           _Iterator begin,
+                                           _Iterator end )
+      {
+        std::string value = str::join(begin, end, ZConfig().cacheDBSplitJoinSeparator());
+        appendStringAttribute( resolvable_id, klass, name, value );
+      }
 
        /**
        * Update a known repository checksum and timestamp
index ba06950..a2d9312 100644 (file)
@@ -114,21 +114,6 @@ struct ResolvableQuery::Impl
     return ( queryNumericAttributeInternal( con, record_id, klass, name) != 0 );
   }
       
-  template <class _Container> _Container 
-  queryStringContainerAttribute( const data::RecordId &record_id,
-                                 const std::string &klass,
-                                 const std::string &name )
-  {
-    sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    string all = queryStringAttributeInternal( con, record_id, klass, name);
-    _Container words;
-    
-    //
-    str::split( all, std::inserter(words, words.begin()) );
-    return words;
-  }
-  
-  
   int queryNumericAttribute( const data::RecordId &record_id,
                                  const std::string &klass,
                                  const std::string &name )
@@ -277,29 +262,6 @@ TranslatedText ResolvableQuery::queryTranslatedStringAttribute( const data::Reco
   return _pimpl->queryTranslatedStringAttribute(record_id, klass, name);
 }
 
-template<class _Container>
-_Container ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id,
-                                                           const std::string &klass,
-                                                           const std::string &name )
-{
-  return _pimpl->queryStringContainerAttribute<_Container>(record_id, klass, name);
-}
-
-template
-std::set<std::string> ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id,
-                                                                      const std::string &klass,
-                                                                      const std::string &name );
-
-template
-std::list<std::string> ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id,
-                                                                       const std::string &klass,
-                                                                       const std::string &name );
-
-template
-Package::Keywords ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id,
-                                                                  const std::string &klass,
-                                                                  const std::string &name );
-
 //////////////////////////////////////////////////////////////////////////////
 
 } } // namespace zypp::cache
index 0dfa2c7..9b3bf0d 100644 (file)
@@ -141,10 +141,17 @@ namespace zypp
        * \return the attribute or a empty 
        * \ref _Container if no record is found.
        */
-      template<class _Container>
-      _Container queryStringContainerAttribute( const data::RecordId &record_id,
-                                                const std::string &klass,
-                                                const std::string &name );
+      template<class _OutputIterator>
+      void queryStringContainerAttribute( const data::RecordId &record_id,
+                                    const std::string &klass,
+                                    const std::string &name,
+                                    _OutputIterator result )
+      {
+        
+        std::string all = queryStringAttribute( record_id, klass, name);
+        //FIXME use zypp separator
+        str::split( all, result );
+      }
       
       
       
index cfbc2e1..76ca98a 100644 (file)
@@ -24,10 +24,6 @@ namespace zypp
       std::string ProductImplIf::category() const
       { return std::string(); }
 
-      /** Get the vendor of the product */
-      Label ProductImplIf::vendor() const
-      { return Label(); }
-
       Url ProductImplIf::releaseNotesUrl() const
       { return Url(); }
 
index cb14c27..be90880 100644 (file)
@@ -45,9 +45,6 @@ namespace zypp
       /** Get the category of the product - addon or base*/
       virtual std::string category() const PURE_VIRTUAL;
 
-      /** Get the vendor of the product */
-      virtual Label vendor() const PURE_VIRTUAL;
-
       virtual Url releaseNotesUrl() const PURE_VIRTUAL;
 
       virtual std::list<Url> updateUrls() const PURE_VIRTUAL;
index 54188ce..649fa94 100644 (file)
@@ -154,7 +154,9 @@ PackageGroup PackageImpl::group() const
 
 PackageImpl::Keywords PackageImpl::keywords() const
 {
-  return _repository->resolvableQuery().queryStringContainerAttribute< PackageImpl::Keywords >( _id, "Package", "keywords" );
+  PackageImpl::Keywords keywords;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Package", "keywords", std::inserter(keywords, keywords.begin()) );
+  return keywords;
 }
 
 Changelog PackageImpl::changelog() const
@@ -209,7 +211,9 @@ DiskUsage PackageImpl::diskusage() const
 
 list<string> PackageImpl::authors() const
 {
-  return _repository->resolvableQuery().queryStringContainerAttribute< list<string> >( _id, "Package", "authors" );
+  list<string> authors;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Package", "authors", back_inserter(authors) );
+  return authors;
 }
 
 std::list<std::string> PackageImpl::filenames() const
diff --git a/zypp/repo/cached/ProductImpl.cc b/zypp/repo/cached/ProductImpl.cc
new file mode 100644 (file)
index 0000000..bee8bb3
--- /dev/null
@@ -0,0 +1,177 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#include "zypp/TranslatedText.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/repo/RepositoryImpl.h"
+#include "ProductImpl.h"
+
+
+using namespace std;
+using namespace zypp::detail;
+using namespace::zypp::repo;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp { namespace repo { namespace cached {
+
+///////////////////////////////////////////////////////////////////
+//
+//        CLASS NAME : ProductImpl
+//
+///////////////////////////////////////////////////////////////////
+
+/** Default ctor
+*/
+ProductImpl::ProductImpl (const data::RecordId &id, cached::RepoImpl::Ptr repository_r)
+    : _repository (repository_r),
+      _id(id)
+{}
+
+Repository
+ProductImpl::repository() const
+{
+  return _repository->selfRepository();
+}
+
+///////////////////////////////////////////////////
+// ResObject Attributes
+///////////////////////////////////////////////////
+
+TranslatedText ProductImpl::summary() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "summary" );
+}
+
+TranslatedText ProductImpl::description() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "description" );
+}
+
+TranslatedText ProductImpl::insnotify() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "insnotify" );
+}
+
+TranslatedText ProductImpl::delnotify() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "delnotify" );
+}
+
+TranslatedText ProductImpl::licenseToConfirm() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "licenseToConfirm" );
+}
+
+Vendor ProductImpl::vendor() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "ResObject", "vendor" );
+}
+
+
+ByteCount ProductImpl::size() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "size" );
+}
+
+ByteCount ProductImpl::archivesize() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "archivesize" );
+}
+
+bool ProductImpl::installOnly() const
+{
+  return _repository->resolvableQuery().queryBooleanAttribute( _id, "ResObject", "installOnly" );
+}
+
+Date ProductImpl::buildtime() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "buildtime" );
+}
+
+Date ProductImpl::installtime() const
+{
+  return Date();
+}
+
+//////////////////////////////////////////
+// DEPRECATED
+//////////////////////////////////////////
+
+Source_Ref ProductImpl::source() const
+{
+  return Source_Ref::noSource;
+}
+
+unsigned ProductImpl::sourceMediaNr() const
+{
+  return 1;
+}
+
+//////////////////////////////////////////
+// PRODUCT
+/////////////////////////////////////////
+
+std::string ProductImpl::category() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "Product", "category" );
+}
+
+Url ProductImpl::releaseNotesUrl() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "Product", "releaseNotesUrl" );
+}
+
+std::list<Url> ProductImpl::updateUrls() const
+{
+  std::list<Url> urls;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "updateUrls", back_inserter(urls) );
+  return urls;
+}
+
+std::list<Url> ProductImpl::extraUrls() const
+{
+  std::list<Url> urls;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "extraUrls", back_inserter(urls) );
+  return urls;
+}
+
+std::list<Url> ProductImpl::optionalUrls() const
+{
+  std::list<Url> urls;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "optionalUrls", back_inserter(urls) );
+  return urls;
+}
+
+list<string> ProductImpl::flags() const
+{
+  list<string> flags;
+  _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "flags", back_inserter(flags) );
+  return flags;
+}
+
+TranslatedText ProductImpl::shortName() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "Product", "shortName" );
+}
+
+std::string ProductImpl::distributionName() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "Product", "distributionName" );
+}
+
+Edition ProductImpl::distributionEdition() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "Product", "distributionEdition" );
+}
+
+/////////////////////////////////////////////////////////////////
+} } } // namespace zypp::repo::cached
+///////////////////////////////////////////////////////////////////
+
diff --git a/zypp/repo/cached/ProductImpl.h b/zypp/repo/cached/ProductImpl.h
new file mode 100644 (file)
index 0000000..4ebca07
--- /dev/null
@@ -0,0 +1,71 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef zypp_repo_cached_ProductImpl_H
+#define zypp_repo_cached_ProductImpl_H
+
+#include "zypp/detail/ProductImpl.h"
+#include "zypp/repo/cached/RepoImpl.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+namespace repo
+{ /////////////////////////////////////////////////////////////////
+namespace cached
+{ /////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //        CLASS NAME : ProductImpl
+  //
+  class ProductImpl : public detail::ProductImplIf
+  {
+  public:
+
+    ProductImpl( const data::RecordId &id, repo::cached::RepoImpl::Ptr repository_r );
+    
+    virtual TranslatedText summary() const;
+    virtual TranslatedText description() const;
+    virtual TranslatedText insnotify() const;
+    virtual TranslatedText delnotify() const;
+    virtual TranslatedText licenseToConfirm() const;
+    virtual Vendor vendor() const;
+    virtual ByteCount size() const;
+    virtual ByteCount archivesize() const;
+    virtual bool installOnly() const;
+    virtual Date buildtime() const;
+    virtual Date installtime() const;
+    
+    virtual Source_Ref source() const;
+    virtual unsigned sourceMediaNr() const;
+    
+    // PRODUCT
+    virtual std::string category() const;
+    virtual Url releaseNotesUrl() const;
+    virtual std::list<Url> updateUrls() const;
+    virtual std::list<Url> extraUrls() const ;
+    virtual std::list<Url> optionalUrls() const ;
+    virtual std::list<std::string> flags() const;
+    virtual TranslatedText shortName() const;
+    virtual std::string distributionName() const;
+    virtual Edition distributionEdition() const;   
+    virtual Repository repository() const;
+    
+  protected:
+    repo::cached::RepoImpl::Ptr _repository;
+    data::RecordId _id;
+  };
+  /////////////////////////////////////////////////////////////////
+} // namespace cached
+} // namespace repository
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZMD_BACKEND_DBSOURCE_DBPACKAGEIMPL_H
+