• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

apt.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef EPT_APT_APT_H
00003 #define EPT_APT_APT_H
00004 
00009 /*
00010  * Copyright (C) 2007,2008  Enrico Zini <enrico@enricozini.org>
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2.1 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00025  */
00026 
00027 #include <wibble/exception.h>
00028 #include <ept/apt/version.h>
00029 #include <ept/core/apt.h>
00030 
00031 #include <iterator>
00032 
00033 namespace ept {
00034 namespace apt {
00035 
00036 class Exception : public wibble::exception::Generic
00037 {
00038 protected:
00039     std::string m_message;
00040 
00041 public:
00042     Exception(const std::string& context) throw ();
00043     ~Exception() throw () {}
00044 
00045     virtual const char* type() const throw () { return "Apt"; }
00046     virtual std::string desc() const throw () { return m_message; }
00047 };
00048 
00049 class Apt;
00050 class AptImplementation;
00051 class RecordIteratorImpl;
00052 using core::PackageState;
00053 
00060 class Apt
00061 {
00062 protected:
00063     AptImplementation* impl;
00064 
00065 public:
00066     // Iterate Packages in the Apt cache
00067     class Iterator : public std::iterator<std::input_iterator_tag, std::string, void, void, void>
00068     {
00069         void* cur;
00070 
00071     protected:
00072         // Construct a valid iterator
00073         Iterator(void* cur) : cur(cur) {}
00074 
00075         // Construct and end iterator
00076         Iterator() : cur(0) {}
00077 
00078     public:
00079         // Copy constructor
00080         Iterator(const Iterator&);
00081         ~Iterator();
00082         std::string operator*();
00083         Iterator& operator++();
00084         Iterator& operator=(const Iterator&);
00085         bool operator==(const Iterator&) const;
00086         bool operator!=(const Iterator&) const;
00087 
00088         // FIXME: Iterator operator++(int); cannot be easily implemented
00089         // because of how Apt's pkgIterator works
00090 
00091         friend class Apt;
00092     };
00093 
00094     // Iterate Package records in the Apt cache
00095     class RecordIterator : public std::iterator<std::input_iterator_tag, std::string, void, void, void>
00096     {
00097         RecordIteratorImpl* impl;
00098         size_t pos;
00099         std::string cur;
00100         size_t cur_pos;
00101 
00102     protected:
00103         // Construct a valid iterator
00104         RecordIterator(RecordIteratorImpl* cur, size_t pos = 0);
00105 
00106         // Construct and end iterator
00107         RecordIterator() : impl(0), pos(0), cur_pos(0) {}
00108 
00109     public:
00110         // Copy constructor
00111         RecordIterator(const RecordIterator& r);
00112 
00113         ~RecordIterator();
00114         std::string operator*();
00115         std::string* operator->();
00116         RecordIterator& operator++();
00117         RecordIterator& operator=(const RecordIterator& r);
00118         bool operator==(const RecordIterator&) const;
00119         bool operator!=(const RecordIterator&) const;
00120 
00121         // FIXME: Iterator operator++(int); cannot be easily implemented
00122         // because of how Apt's pkgIterator works
00123 
00124         friend class Apt;
00125     };
00126 
00127     typedef Iterator iterator;
00128     typedef RecordIterator record_iterator;
00129 
00133     Apt();
00134     ~Apt();
00135 
00136     iterator begin() const;
00137     iterator end() const;
00138 
00139     record_iterator recordBegin() const;
00140     record_iterator recordEnd() const;
00141 
00142 
00144     size_t size() const;
00145 
00150     bool isValid(const std::string& pkg) const;
00151 
00154     std::string validate(const std::string& pkg) const
00155     {
00156         if (isValid(pkg))
00157             return pkg;
00158         return std::string();
00159     }
00160 
00163     Version validate(const Version& ver) const;
00164 
00166     Version installedVersion(const std::string& pkg) const;
00167 
00169     Version candidateVersion(const std::string& pkg) const;
00170 
00175     Version anyVersion(const std::string& pkg) const;
00176 
00178     PackageState state(const std::string& pkg) const;
00179 
00186     //template<typename FILTER, typename OUT>
00187     //void search(const FILTER& filter, OUT& out);
00188 
00190     std::string rawRecord(const std::string& pkg) const;
00191 
00193     std::string rawRecord(const Version& ver) const;
00194 
00196     time_t timestamp();
00197 
00204     void checkCacheUpdates();
00205 
00212     void invalidateTimestamp();
00213 };
00214 
00215 }
00216 }
00217 
00218 // vim:set ts=4 sw=4:
00219 #endif

Generated on Sun Oct 16 2011 01:31:02 for libept by  doxygen 1.7.1