5 #ifndef EPT_APT_RECORD_H 6 #define EPT_APT_RECORD_H 29 : m_source( &s ), m_idx( 0 )
45 bool parseBool(
bool& def,
const std::string& str)
const 48 if (str ==
"no" || str ==
"false" || str ==
"without" ||
49 str ==
"off" || str ==
"disable")
52 if (str ==
"yes" || str ==
"true" || str ==
"with" ||
53 str ==
"on" || str ==
"enable")
63 template< PropertyId p >
67 template<
typename T >
72 template<
typename T > T parse(
const T &def,
73 const std::string &field )
const;
75 template< PropertyId p >
80 return parse< typename PropertyType< p >::T >( def,
88 template<>
inline std::string Parser::get< ShortDescription >(
89 const std::string& def )
const 92 if (str == std::string())
94 size_t pos = str.find(
"\n");
95 if (pos == std::string::npos)
98 return str.substr(0, pos);
101 template<>
inline std::string Parser::get< LongDescription >(
102 const std::string& def )
const 105 if (str == std::string())
107 size_t pos = str.find(
"\n");
108 if (pos == std::string::npos)
113 for (++pos; pos < str.size() && isspace(str[pos]); ++pos)
115 return str.substr(pos);
120 const std::string& def,
const std::string& str)
const 122 if (str == std::string())
127 template<>
inline int Parser::parse< int >(
128 const int& def,
const std::string& str)
const 132 return (
size_t)strtoul(str.c_str(), NULL, 10);
145 typedef vector< pkgCache::VerFile * >
VfList;
149 if ( m_vflist.size() > 0 )
152 m_vflist.reserve(m_db.
cache().HeaderP->PackageCount + 1);
155 for (pkgCache::PkgIterator pi = m_db.
cache().PkgBegin(); !pi.end(); ++pi)
157 if (pi->VersionList == 0)
160 for( pkgCache::VerIterator vi = pi.VersionList(); !vi.end(); ++vi ) {
163 pkgCache::VerFileIterator vfi = vi.FileList();
164 for ( ; !vfi.end(); ++vfi )
165 if ((vfi.File()->Flags & pkgCache::Flag::NotSource) == 0)
169 m_vflist.push_back( vfi );
189 const pkgCache::VerFile* b)
191 if (a == 0 && b == 0)
198 if (a->File == b->File)
199 return a->Offset < b->Offset;
200 return a->File < b->File;
205 lastFile = pkgCache::PkgFileIterator();
209 if ( vfi.Cache() == 0 || vfi.end() )
212 if ((lastFile.Cache() == 0)
213 || vfi->File + m_db.
cache().PkgFileP != lastFile)
215 lastFile = pkgCache::PkgFileIterator(
216 m_db.
cache(), vfi->File + m_db.
cache().PkgFileP);
217 if (!lastFile.IsOk())
218 throw wibble::exception::System(
219 std::string(
"Reading the" 220 " data record for a package from file ")
221 + lastFile.FileName() );
224 if (!file.Open(lastFile.FileName(), FileFd::ReadOnly))
225 throw wibble::exception::System( std::string(
"Opening file ")
226 + lastFile.FileName() );
232 size_t slack = vfi->Offset - lastOffset;
236 if ( !file.Seek( vfi->Offset ) )
237 throw wibble::exception::System(
238 std::string(
"Cannot seek to package record in file ")
239 + lastFile.FileName() );
242 char buffer[vfi->Size + slack + 1];
243 if (!file.Read(buffer, vfi->Size + slack))
244 throw wibble::exception::System(
245 std::string(
"Cannot read package " 246 "record in file ") + lastFile.FileName() );
248 buffer[vfi->Size + slack] =
'\0';
251 lastOffset = vfi->Offset + vfi->Size;
253 return string(buffer+slack);
258 t._id = getInternal< Name >( i ) +
"_" + getInternal< Version >( i );
262 template< PropertyId p >
264 Parser rec( getRecord( i ) );
265 return rec.
get< p >();
269 template<>
inline std::string Source::getInternal< Record >(
Internal i ) {
271 return getRecord( i );
Parser(const std::string &str)
Definition: record.h:61
record::InternalList InternalList
Definition: record.h:37
Setup::Token Token
Definition: source.h:15
vector< pkgCache::VerFile * > VfList
Definition: record.h:145
const char * fields[]
Definition: record.cpp:8
Definition: core/apt.h:389
bool parseBool(bool &def, const std::string &str) const
Definition: record.h:45
bool empty() const
Definition: record.h:279
-*- C++ -*- (c) 2006, 2007 Petr Rockai me@mornfall.net
Definition: apt.cc:43
std::string getRecord(Internal vfi)
Definition: record.h:208
int T
Definition: record.h:41
pkgCache::PkgFileIterator lastFile
Definition: record.h:140
ept::Token Token
Definition: record.h:34
VfList m_vflist
Definition: record.h:146
Definition: core/apt.h:387
pkgCache::VerIterator lookupVersion(Token t)
Definition: core/apt.h:256
size_t m_idx
Definition: record.h:16
pkgCache::VerFileIterator Internal
Definition: core/apt.h:393
Definition: core/apt.h:395
int T
Definition: record.h:40
static bool localityCompare(const pkgCache::VerFile *a, const pkgCache::VerFile *b)
Definition: record.h:188
Internal lookupToken(Token t)
Definition: record.h:183
Definition: core/apt.h:112
Access the fields of a package record contained inside a std::string.
Definition: core/apt/recordparser.h:40
Definition: core/apt.h:388
static pkgCache::VerFileIterator lookupVersionFile(pkgCache::VerIterator vi)
Definition: core/apt.h:268
VfList & vfList()
Definition: record.h:148
InternalList listInternal()
Definition: record.h:179
size_t lastOffset
Definition: record.h:142
record::PropertyId PropertyId
Definition: record.h:36
std::string Parser::parse< std::string >(const std::string &def, const std::string &str) const
Definition: record.h:119
static T def
Definition: record.h:69
PropertyType< p >::T get(const typename PropertyType< p >::T &def=Default< typename PropertyType< p >::T >::def) const
Definition: record.h:76
void invalidate()
Definition: record.h:203
PropertyId
Definition: core/apt.h:387
bool localityCompare(const pkgCache::VerFile *a, const pkgCache::VerFile *b)
Definition: apt.cc:147
record::Internal Internal
Definition: record.h:35
std::string T
Definition: core/apt.h:396
InternalList(Source &s)
Definition: record.h:28
pkgCache & cache()
Definition: core/apt.h:113
PropertyType< p >::T getInternal(Internal i)
Definition: record.h:263
Parser()
Definition: record.h:60
InternalList tail() const
Definition: record.h:22
Source(AptDatabase &db)
Definition: record.h:177
void invalidate()
Definition: source.h:31
AptDatabase & m_db
Definition: record.h:137
FileFd file
Definition: record.h:141
Source * m_source
Definition: record.h:15
Token getToken(Internal i)
Definition: record.h:256