1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
//=======================================================================
// pkgset.cc
//-----------------------------------------------------------------------
// This file is part of the package paco
// Copyright (C) 2004-2009 David Rosal
// For more information visit http://paco.sourceforge.net
//=======================================================================
#include "config.h"
#include "gconfig.h"
#include "pkg.h"
#include "pkgset.h"
#include "util.h"
using namespace Gpaco;
PkgSet::PkgSet()
:
mSizeInst(0)
{
try {
Glib::Dir dir(GConfig::logdir());
for (Glib::Dir::iterator d = dir.begin(); d != dir.end(); ++d) {
try {
*this += new Pkg(*d);
}
catch (Paco::X& x) {
errorDialog(NULL, x.what(), true);
}
catch (...) { }
}
}
catch (Glib::Error& x) {
errorDialog(NULL, x.what(), true);
}
}
PkgSet::~PkgSet()
{
for (iterator p = begin(); p != end(); ++p) {
g_assert(*p != NULL);
if (*p) {
delete *p;
*p = NULL;
}
}
}
bool PkgSet::hasPkg(std::string const& pkgName)
{
for (iterator p = begin(); p != end(); ++p) {
if ((*p)->name() == pkgName)
return true;
}
return false;
}
PkgSet& PkgSet::operator+=(Pkg* pkg)
{
g_assert(pkg != NULL);
push_back(pkg);
mSizeInst += pkg->sizeInst();
return *this;
}
PkgSet& PkgSet::operator-=(Pkg* pkg)
{
g_assert(pkg != NULL);
iterator i = std::remove(begin(), end(), pkg);
if (i != end()) {
mSizeInst -= pkg->sizeInst();
delete pkg;
pkg = NULL;
erase(i, end());
}
return *this;
}
|