5 #ifndef EPT_APT_RECORD_H
6 #define EPT_APT_RECORD_H
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,
86 template<
typename T > T Parser::Default< T >::def = T();
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;
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)
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() )
215 lastFile = pkgCache::PkgFileIterator(
218 throw wibble::exception::System(
219 std::string(
"Reading the"
220 " data record for a package from file ")
225 throw wibble::exception::System( std::string(
"Opening file ")
236 if ( !
file.Seek( vfi->Offset ) )
237 throw wibble::exception::System(
238 std::string(
"Cannot seek to package record in file ")
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';
253 return string(buffer+slack);
258 t._id = getInternal< Name >( i ) +
"_" + getInternal< Version >( i );
262 template< PropertyId p >
265 return rec.
get< p >();
269 template<>
inline std::string Source::getInternal< Record >(
Internal i ) {
271 return getRecord( i );