/* * Copyright (c) 2001, Robert Collins. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * A copy of the GNU General Public License can be found at * http://www.gnu.org/ * * Written by Robert Collins * */ #ifndef SETUP_PACKAGE_DB_H #define SETUP_PACKAGE_DB_H /* required to parse this file */ #include #include #include "String++.h" class packagemeta; class io_stream; class PackageSpecification; typedef enum { PackageDB_Install, PackageDB_Download } PackageDBActions; class packagedb; typedef std::vector ::iterator PackageDBConnectedIterator; /*TODO: add mutexs */ /*TODO: add sanity. Beware, Here Be C++ Dragons: This class is a hidden singleton. It's a singleton, but you create and delete transient objects of the class, none of which have any member data, but solely serve as shortcuts to access one static set of shared data through an irrelevant this-pointer. Not only that, but it's a hidden singleton that is constructed the first time you access it, and constructed differently based on implicit global state. Not only that, but it has some static state of its own that also controls how it gets constructed, but that could then be changed afterward without invalidating the cached data, silently changing its semantic interpretation. To use this class, you must first set the packagedb::task member and the cygfile:// (install dir) root path. You must only then construct a packagedb, and must remember not to change the task or root path any later in the execution sequence. */ class packagedb { public: packagedb (); /* 0 on success */ int flush (); packagemeta * findBinary (PackageSpecification const &) const; packagemeta * findSource (PackageSpecification const &) const; PackageDBConnectedIterator connectedBegin(); PackageDBConnectedIterator connectedEnd(); void fillMissingCategory(); void markUnVisited(); void setExistence(); /* all seen binary packages */ static std::vector < packagemeta *> packages; /* all seen source packages */ static std::vector sourcePackages; /* all seen categories */ typedef std::map , casecompare_lt_op > categoriesType; static categoriesType categories; static PackageDBActions task; private: static int installeddbread; /* do we have to reread this */ friend class ConnectedLoopFinder; static std::vector dependencyOrderedPackages; }; #endif /* SETUP_PACKAGE_DB_H */