ResolvableQuery.h

Go to the documentation of this file.
00001 
00002 #ifndef ZYPP_CACHE_RESOLVABLE_QUERY_H
00003 #define ZYPP_CACHE_RESOLVABLE_QUERY_H
00004 
00005 #include <set>
00006 #include <list>
00007 #include <vector>
00008 #include "zypp/base/Function.h"
00009 #include "zypp/Pathname.h"
00010 #include "zypp/data/ResolvableData.h"
00011 #include "zypp/data/RecordId.h"
00012 #include "zypp/cache/Attribute.h"
00013 #include "zypp/ZConfig.h"
00014 
00022 #define queryOnMediaLocation(RESQUERY,ID,OMLATTRPREFIX,OML)                                              \
00023 do {                                                                                                     \
00024   OML.setLocation( RESQUERY.queryStringAttribute( ID, OMLATTRPREFIX##Filename() ),                       \
00025                    RESQUERY.queryNumericAttribute( ID, OMLATTRPREFIX##MediaNr() ) );                     \
00026   OML.setChecksum( CheckSum( RESQUERY.queryStringAttribute( ID, OMLATTRPREFIX##ChecksumType() ),         \
00027                              RESQUERY.queryStringAttribute( ID, OMLATTRPREFIX##Checksum() ) ) );         \
00028   OML.setDownloadSize( RESQUERY.queryNumericAttribute( ID, OMLATTRPREFIX##DownloadSize() ) );            \
00029   OML.setOpenChecksum( CheckSum( RESQUERY.queryStringAttribute( ID, OMLATTRPREFIX##OpenChecksumType() ), \
00030                                  RESQUERY.queryStringAttribute( ID, OMLATTRPREFIX##OpenChecksum() ) ) ); \
00031   OML.setOpenSize( RESQUERY.queryNumericAttribute( ID, OMLATTRPREFIX##OpenSize() ) );                    \
00032 } while(false)
00033 
00034 
00036 namespace zypp
00037 { 
00038 
00039   namespace cache
00040   { 
00041 
00042    // match flag definitions for iterate*() functions
00043 
00044    const int MATCH_EXACT =      0x00;           // match 'string' exactly
00045    const int MATCH_LEADING =    0x01;           // match 'string*'
00046    const int MATCH_TRAILING =   0x02;           // match '*string'
00047    const int MATCH_SUBSTRING =  (MATCH_LEADING|MATCH_TRAILING);
00048    const int MATCH_REGEXP =     0x04;           // match e.g. 's?t*r??ing*' (only ? and * are allowed)
00049    const int MATCH_NAME =       0x08;           // match string in resolvable name, this is the default
00050    const int MATCH_SUMMARY =    0x10;           // match string in resolvable summary
00051    const int MATCH_DESCRIPTION= 0x20;           // match string in resolvable description
00052 
00053 
00054    const int MATCH_WILDCARDS = (MATCH_SUBSTRING|MATCH_REGEXP);
00055    const int MATCH_FIELDS = (MATCH_NAME|MATCH_SUMMARY|MATCH_DESCRIPTION);
00056 
00062       typedef function<bool( const data::RecordId &,
00063                              data::ResObject_Ptr )> ProcessResolvable;
00064 
00069     struct ResolvableQuery
00070     {
00071     public:
00077       ResolvableQuery( const Pathname &dbdir );
00078 
00079       ~ResolvableQuery();
00080 
00086       void query( const data::RecordId &record_id,
00087                   ProcessResolvable fnc  );
00088 
00094       void query( const std::string &text,
00095                   ProcessResolvable fnc  );
00096 
00106       int queryNumericAttribute( const data::RecordId &record_id,
00107                                  const std::string &klass,
00108                                  const std::string &name,
00109                                  int default_value = 0 );
00111       int queryNumericAttribute( const data::RecordId &record_id,
00112                                  const Attribute& attr,
00113                                  int default_value = 0 )
00114       { return queryNumericAttribute( record_id, attr.klass, attr.name, default_value ); }
00115 
00116 
00127       bool queryBooleanAttribute( const data::RecordId &record_id,
00128                                   const std::string &klass,
00129                                   const std::string &name,
00130                                   bool default_value = false );
00132       bool queryBooleanAttribute( const data::RecordId &record_id,
00133                                   const Attribute& attr,
00134                                   bool default_value = false )
00135       { return queryBooleanAttribute( record_id, attr.klass, attr.name, default_value ); }
00136 
00137 
00148       std::string queryStringAttribute( const data::RecordId &record_id,
00149                                         const std::string &klass,
00150                                         const std::string &name,
00151                                         const std::string &default_value = std::string() );
00153       std::string queryStringAttribute( const data::RecordId &record_id,
00154                                         const Attribute& attr,
00155                                         const std::string &default_value = std::string() )
00156       { return queryStringAttribute( record_id, attr.klass, attr.name, default_value ); }
00157 
00170       std::string queryStringAttributeTranslation( const data::RecordId &record_id,
00171                                                    const Locale &locale,
00172                                                    const std::string &klass,
00173                                                    const std::string &name,
00174                                                    const std::string &default_value = std::string() );
00176       std::string queryStringAttributeTranslation( const data::RecordId &record_id,
00177                                                    const Locale &locale,
00178                                                    const Attribute& attr,
00179                                                    const std::string &default_value = std::string() )
00180       { return queryStringAttributeTranslation( record_id, locale, attr.klass, attr.name, default_value ); }
00181 
00193       TranslatedText queryTranslatedStringAttribute( const data::RecordId &record_id,
00194                                                      const std::string &klass,
00195                                                      const std::string &name,
00196                                                      const TranslatedText &default_value = TranslatedText() );
00198       TranslatedText queryTranslatedStringAttribute( const data::RecordId &record_id,
00199                                                      const Attribute& attr,
00200                                                      const TranslatedText &default_value = TranslatedText() )
00201       { return queryTranslatedStringAttribute( record_id, attr.klass, attr.name, default_value ); }
00202 
00214       template<class _OutputIterator>
00215       void queryStringContainerAttribute( const data::RecordId &record_id,
00216                                     const std::string &klass,
00217                                     const std::string &name,
00218                                     _OutputIterator result )
00219       {
00220 
00221         std::string all = queryStringAttribute( record_id, klass, name);
00222         //FIXME use zypp separator
00223         str::split( all, result, ZConfig::instance().cacheDBSplitJoinSeparator() );
00224       }
00226       template<class _OutputIterator>
00227       void queryStringContainerAttribute( const data::RecordId &record_id,
00228                                           const Attribute& attr,
00229                                           _OutputIterator result )
00230       { queryStringContainerAttribute( record_id, attr.klass, attr.name, result ); }
00231 
00232 
00233 
00237       void queryDiskUsage( const data::RecordId &record_id,
00238                            DiskUsage &du );
00239 
00243       std::string queryRepositoryAlias( const data::RecordId &repo_id );
00244 
00248       data::RecordId queryRepositoryId( const std::string &repo_alias );
00249 
00260       void iterateResolvablesByKindsAndStringsAndRepos( const std::vector<zypp::Resolvable::Kind> & kinds,
00261                   const std::vector<std::string> &names, int flags, const std::vector<std::string> &repos, ProcessResolvable fnc );
00262 
00263     private:
00265       class Impl;
00267       RW_pointer<Impl> _pimpl;
00268     };
00269   } //NS cache
00270 } //NS zypp
00271 
00272 #endif

Generated on Tue Sep 25 19:23:00 2007 for libzypp by  doxygen 1.5.3