From 3ddb7c9261ffed0361a241602871b66524773885 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 11 Jun 2007 13:35:29 +0000 Subject: [PATCH] - Make the container function use iterators (thanks ma) it allows any class that has asString() now, in any container that has iterators. - add product implementation --- zypp/CMakeLists.txt | 2 + zypp/base/String.cc | 7 +- zypp/base/String.h | 15 +++- zypp/cache/CacheStore.cpp | 39 +-------- zypp/cache/CacheStore.h | 22 +++-- zypp/cache/ResolvableQuery.cc | 38 --------- zypp/cache/ResolvableQuery.h | 15 +++- zypp/detail/ProductImplIf.cc | 4 - zypp/detail/ProductImplIf.h | 3 - zypp/repo/cached/PackageImpl.cc | 8 +- zypp/repo/cached/ProductImpl.cc | 177 ++++++++++++++++++++++++++++++++++++++++ zypp/repo/cached/ProductImpl.h | 71 ++++++++++++++++ 12 files changed, 306 insertions(+), 95 deletions(-) create mode 100644 zypp/repo/cached/ProductImpl.cc create mode 100644 zypp/repo/cached/ProductImpl.h diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index 47585b5..d165d1d 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -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 diff --git a/zypp/base/String.cc b/zypp/base/String.cc index 85dd7d3..e1aaa1f 100644 --- a/zypp/base/String.cc +++ b/zypp/base/String.cc @@ -22,7 +22,12 @@ namespace zypp /////////////////////////////////////////////////////////////////// namespace str { ///////////////////////////////////////////////////////////////// - + template<> + std::string asString( const std::string &t ) + { + return t; + } + /****************************************************************** ** ** FUNCTION NAME : form diff --git a/zypp/base/String.h b/zypp/base/String.h index a9435e0..cc4a24c 100644 --- a/zypp/base/String.h +++ b/zypp/base/String.h @@ -27,6 +27,19 @@ namespace zypp { ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// + /** + * Global asString() that works with std::string too + */ + template + 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; } diff --git a/zypp/cache/CacheStore.cpp b/zypp/cache/CacheStore.cpp index 38eb396..9594586 100644 --- a/zypp/cache/CacheStore.cpp +++ b/zypp/cache/CacheStore.cpp @@ -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 -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 &cont ); -template -void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id, - const std::string &klass, - const std::string &name, - const std::list &cont ); -template - void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id, - const std::string &klass, - const std::string &name, - const Package::Keywords &cont ); - - - } } diff --git a/zypp/cache/CacheStore.h b/zypp/cache/CacheStore.h index b392623..09c7f04 100644 --- a/zypp/cache/CacheStore.h +++ b/zypp/cache/CacheStore.h @@ -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 + template 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 diff --git a/zypp/cache/ResolvableQuery.cc b/zypp/cache/ResolvableQuery.cc index ba06950..a2d9312 100644 --- a/zypp/cache/ResolvableQuery.cc +++ b/zypp/cache/ResolvableQuery.cc @@ -114,21 +114,6 @@ struct ResolvableQuery::Impl return ( queryNumericAttributeInternal( con, record_id, klass, name) != 0 ); } - template _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 -_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 ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id, - const std::string &klass, - const std::string &name ); - -template -std::list 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 diff --git a/zypp/cache/ResolvableQuery.h b/zypp/cache/ResolvableQuery.h index 0dfa2c7..9b3bf0d 100644 --- a/zypp/cache/ResolvableQuery.h +++ b/zypp/cache/ResolvableQuery.h @@ -141,10 +141,17 @@ namespace zypp * \return the attribute or a empty * \ref _Container if no record is found. */ - template - _Container queryStringContainerAttribute( const data::RecordId &record_id, - const std::string &klass, - const std::string &name ); + template + 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 ); + } diff --git a/zypp/detail/ProductImplIf.cc b/zypp/detail/ProductImplIf.cc index cfbc2e1..76ca98a 100644 --- a/zypp/detail/ProductImplIf.cc +++ b/zypp/detail/ProductImplIf.cc @@ -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(); } diff --git a/zypp/detail/ProductImplIf.h b/zypp/detail/ProductImplIf.h index cb14c27..be90880 100644 --- a/zypp/detail/ProductImplIf.h +++ b/zypp/detail/ProductImplIf.h @@ -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 updateUrls() const PURE_VIRTUAL; diff --git a/zypp/repo/cached/PackageImpl.cc b/zypp/repo/cached/PackageImpl.cc index 54188ce..649fa94 100644 --- a/zypp/repo/cached/PackageImpl.cc +++ b/zypp/repo/cached/PackageImpl.cc @@ -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 PackageImpl::authors() const { - return _repository->resolvableQuery().queryStringContainerAttribute< list >( _id, "Package", "authors" ); + list authors; + _repository->resolvableQuery().queryStringContainerAttribute( _id, "Package", "authors", back_inserter(authors) ); + return authors; } std::list PackageImpl::filenames() const diff --git a/zypp/repo/cached/ProductImpl.cc b/zypp/repo/cached/ProductImpl.cc new file mode 100644 index 0000000..bee8bb3 --- /dev/null +++ b/zypp/repo/cached/ProductImpl.cc @@ -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 ProductImpl::updateUrls() const +{ + std::list urls; + _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "updateUrls", back_inserter(urls) ); + return urls; +} + +std::list ProductImpl::extraUrls() const +{ + std::list urls; + _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "extraUrls", back_inserter(urls) ); + return urls; +} + +std::list ProductImpl::optionalUrls() const +{ + std::list urls; + _repository->resolvableQuery().queryStringContainerAttribute( _id, "Product", "optionalUrls", back_inserter(urls) ); + return urls; +} + +list ProductImpl::flags() const +{ + list 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 index 0000000..4ebca07 --- /dev/null +++ b/zypp/repo/cached/ProductImpl.h @@ -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 updateUrls() const; + virtual std::list extraUrls() const ; + virtual std::list optionalUrls() const ; + virtual std::list 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 + -- 2.7.4