Author: dmacvicar Date: Mon Jun 11 15:35:29 2007 New Revision: 5714 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5714&view=rev Log: - 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 Added: trunk/libzypp/zypp/repo/cached/ProductImpl.cc trunk/libzypp/zypp/repo/cached/ProductImpl.h Modified: trunk/libzypp/zypp/CMakeLists.txt trunk/libzypp/zypp/base/String.cc trunk/libzypp/zypp/base/String.h trunk/libzypp/zypp/cache/CacheStore.cpp trunk/libzypp/zypp/cache/CacheStore.h trunk/libzypp/zypp/cache/ResolvableQuery.cc trunk/libzypp/zypp/cache/ResolvableQuery.h trunk/libzypp/zypp/detail/ProductImplIf.cc trunk/libzypp/zypp/detail/ProductImplIf.h trunk/libzypp/zypp/repo/cached/PackageImpl.cc Modified: trunk/libzypp/zypp/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/CMakeLists.txt (original) +++ trunk/libzypp/zypp/CMakeLists.txt Mon Jun 11 15:35:29 2007 @@ -1083,6 +1083,7 @@ 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 @@ repo/cached/PackageImpl.h repo/cached/PatchImpl.h repo/cached/PatternImpl.h + repo/cached/ProductImpl.h ) SET( zypp_repository_data_SRCS Modified: trunk/libzypp/zypp/base/String.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.cc?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.cc (original) +++ trunk/libzypp/zypp/base/String.cc Mon Jun 11 15:35:29 2007 @@ -22,7 +22,12 @@ /////////////////////////////////////////////////////////////////// namespace str { ///////////////////////////////////////////////////////////////// - + template<> + std::string asString( const std::string &t ) + { + return t; + } + /****************************************************************** ** ** FUNCTION NAME : form Modified: trunk/libzypp/zypp/base/String.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.h?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.h (original) +++ trunk/libzypp/zypp/base/String.h Mon Jun 11 15:35:29 2007 @@ -27,6 +27,19 @@ { ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// + /** + * 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 @@ { if ( iter != begin ) res += sep_r; - res += *iter; + res += asString(*iter); } return res; } Modified: trunk/libzypp/zypp/cache/CacheStore.cpp URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.cpp?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.cpp (original) +++ trunk/libzypp/zypp/cache/CacheStore.cpp Mon Jun 11 15:35:29 2007 @@ -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 @@ 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 @@ 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 @@ _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::setstd::string &cont ); -template -void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id, - const std::string &klass, - const std::string &name, - const std::liststd::string &cont ); -template - void CacheStore::appendStringContainerAttribute( const data::RecordId &resolvable_id, - const std::string &klass, - const std::string &name, - const Package::Keywords &cont ); - - - } } Modified: trunk/libzypp/zypp/cache/CacheStore.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.h?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.h (original) +++ trunk/libzypp/zypp/cache/CacheStore.h Mon Jun 11 15:35:29 2007 @@ -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 @@ /** - * 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 Modified: trunk/libzypp/zypp/cache/ResolvableQuery.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/ResolvableQuery.cc?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/ResolvableQuery.cc (original) +++ trunk/libzypp/zypp/cache/ResolvableQuery.cc Mon Jun 11 15:35:29 2007 @@ -114,21 +114,6 @@ 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 @@ 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::setstd::string ResolvableQuery::queryStringContainerAttribute( const data::RecordId &record_id, - const std::string &klass, - const std::string &name ); - -template -std::liststd::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 Modified: trunk/libzypp/zypp/cache/ResolvableQuery.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/ResolvableQuery.h?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/ResolvableQuery.h (original) +++ trunk/libzypp/zypp/cache/ResolvableQuery.h Mon Jun 11 15:35:29 2007 @@ -141,10 +141,17 @@ * \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 ); + } Modified: trunk/libzypp/zypp/detail/ProductImplIf.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/detail/ProductImplIf.cc?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/detail/ProductImplIf.cc (original) +++ trunk/libzypp/zypp/detail/ProductImplIf.cc Mon Jun 11 15:35:29 2007 @@ -24,10 +24,6 @@ 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(); } Modified: trunk/libzypp/zypp/detail/ProductImplIf.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/detail/ProductImplIf.h?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/detail/ProductImplIf.h (original) +++ trunk/libzypp/zypp/detail/ProductImplIf.h Mon Jun 11 15:35:29 2007 @@ -45,9 +45,6 @@ /** 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; Modified: trunk/libzypp/zypp/repo/cached/PackageImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/cached/PackageImpl.cc?rev=5714&r1=5713&r2=5714&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/cached/PackageImpl.cc (original) +++ trunk/libzypp/zypp/repo/cached/PackageImpl.cc Mon Jun 11 15:35:29 2007 @@ -154,7 +154,9 @@ 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 @@ 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::liststd::string PackageImpl::filenames() const Added: trunk/libzypp/zypp/repo/cached/ProductImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/cached/ProductImpl.cc?rev=5714&view=auto ============================================================================== --- trunk/libzypp/zypp/repo/cached/ProductImpl.cc (added) +++ trunk/libzypp/zypp/repo/cached/ProductImpl.cc Mon Jun 11 15:35:29 2007 @@ -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 +/////////////////////////////////////////////////////////////////// + Added: trunk/libzypp/zypp/repo/cached/ProductImpl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/cached/ProductImpl.h?rev=5714&view=auto ============================================================================== --- trunk/libzypp/zypp/repo/cached/ProductImpl.h (added) +++ trunk/libzypp/zypp/repo/cached/ProductImpl.h Mon Jun 11 15:35:29 2007 @@ -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::liststd::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 + -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org