branch.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  *  this is part of Spm
00004  *
00005  *  Copyright (c) 2005-2007 Guillaume Chevallereau
00006  *
00007  *  This program is free software. You can redistribute it and/or modify it 
00008  *  under the terms of the GNU General Public License as published by the 
00009  *  Free Software Foundation. Either version 2 of the license or (at your 
00010  *  option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be usefull but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
00015  *  more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along 
00018  *  with this program; if not, write to the Free Software Foundation, Inc., 
00019  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00020  */
00021 #ifndef __BRANCH_H__ 
00022 #define __BRANCH_H__
00023 #include <string>
00024 #include <map>
00025 #include <list>
00026 #include "coreException.h"
00027 #include <util/utilException.h>
00028 #include <plugin/installerInterface.h>
00029 #include <algorithm>
00030 #include <boost/thread.hpp>
00031 #include <boost/filesystem/path.hpp>
00032 #include <util/object.h>
00033 
00034 namespace Spm
00035 {
00036   namespace Core
00037   {
00041     const std::string BRANCH_NODE_ELEMENTS = "elementList";
00042     const std::string BRANCH_NODE_ELEMENT = "element";
00043     const std::string BRANCH_ATTRIBUTE_BRANCH = "branch";
00044     const std::string BRANCH_ATTRIBUTE_ELEMENT = "element";
00045     const std::string BRANCH_LIST_FILES = "branchFile";
00050     class Element;
00051 
00057     class Branch : public Util::Object
00058     {
00059       friend class PackageSystem;
00060       friend class Element;
00061       friend class Store;
00062       
00063     private:
00064       std::string major;
00065       std::string minor;
00066       std::string actualVersion;
00067       boost::filesystem::path __prefix;
00068       std::string cflags;
00069 
00070       std::string branchURL;
00071       std::string owner;
00072       mutable unsigned long size;
00073       std::map <std::string,
00074                 std::string> extraInformation;
00075       mutable std::list<boost::filesystem::path> __files;
00076       std::list<Branch *> elements;
00077       Element * element;
00078 
00079       void loadFileList () const;
00080       void loadFileList ();
00081       bool removeFiles ();
00082       bool uninstall () const;
00083     public:
00084       static std::string getBranchName (const std::string major,
00085                                         const std::string minor,
00086                                         const std::string micro);
00087       Branch ()
00088       { 
00089         element = NULL;
00090       }
00091 
00092       Branch(const Branch &)
00093       {
00094       }
00095 
00099       Branch (Element * aElement)
00100         throw (Util::NullPointerException);
00101 
00106       Branch (const std::string & aVersion,
00107               Element * aElement)
00108         throw (Util::NullPointerException,
00109                BadNameException);
00110 
00117       Branch (const std::string & aMajor, 
00118               const std::string & aMinor, 
00119               const std::string & extraVersion,
00120               Element * aElement);
00121 
00122       ~Branch ();
00123 
00127       void setActual (const std::string & actual);
00131       void setMinor (const std::string & aMinor);
00132 
00136       void setMajor (const std::string & aMajor);
00137       
00141       std::string getName ();
00142 
00146       const std::string getMajor ();
00147 
00151       const std::string getMinor ();
00152 
00156       const std::string getActualVersion ();
00157 
00158       const std::string getMajor () const;
00159       const std::string getMinor () const;
00160       const std::string getActualVersion () const;
00161 
00165       std::string getName () const;
00166       
00170       void setPrefix (const boost::filesystem::path & prefix);
00171       
00175       void setFlags (const std::string & flags);
00176 
00180       const boost::filesystem::path & getPrefix ();
00181       const boost::filesystem::path & getPrefix () const;
00182       
00186       const std::string & getFlags ();
00187       const std::string & getFlags () const;
00188 
00192       void setUrl (const std::string & url);
00193 
00197       const std::string & getUrl ();
00198       const std::string & getUrl () const;
00199 
00203       const std::map<std::string,
00204                      std::string> & getExtraInformations ();
00205       const std::map<std::string,
00206                      std::string> & getExtraInformations () const;
00207 
00212       const std::string & getExtraInformation (const std::string & key)
00213         throw (UnknownKeyException);
00214       const std::string & getExtraInformation (const std::string & key) const
00215         throw (UnknownKeyException);
00216 
00221       void addExtraInformation(const std::string & key,
00222                                const std::string & val)
00223         throw (AlreadyExistingKeyException);
00227       void removeExtraInformation (const std::string & key)
00228         throw (UnknownKeyException);
00232       void setExtraInformation (const std::map<std::string,
00233                                 std::string> & extra);
00238       void setExtraInformation (const std::string & key,
00239                                 const std::string & val)
00240         throw (UnknownKeyException);
00244       const std::string & getOwner ();
00245 
00249       const std::string & getOwner () const;
00250       
00254       void setOwner (const std::string & aUser);
00255 
00261       bool queryForFile (const boost::filesystem::path & file) const;
00262 
00266       void setFiles (const std::list<boost::filesystem::path> & branchFiles);
00267 
00271       const std::list<boost::filesystem::path> & getFiles ();
00272 
00276       void setSize (unsigned long size);
00277 
00281       const unsigned long & getSize ();
00282       const unsigned long & getSize () const;
00283 
00288       void addElement (const Branch * branchOfElement);
00289 
00294       void delElement (const std::string & elementName);
00295 
00299       const std::list<Branch *> & getElements ();
00300       const std::list<Branch *> & getElements () const;
00301 
00307       const Branch * getElement (const std::string & elementName)
00308         throw (UnknownElementException);
00309       
00313       const Element * getElement ();
00314 
00318       const Element * getElement () const;
00319 
00320       bool operator< (const Branch & b) const;
00321 
00322       bool operator< (const std::string & branchVersion);
00323       bool operator== (const std::string & branchVersion);
00324       bool operator== (const Branch & otherBranch) const;
00325     };
00326 
00330     typedef struct equalBranchOfElement : public std::binary_function<Branch *, std::string, bool>
00331     {
00332       bool operator() (Branch * branch,
00333                        const std::string & elementName) const;
00334     };
00335 
00336     typedef struct fileIsInBranch : public std::binary_function<boost::filesystem::path, boost::filesystem::path, bool>
00337     {
00338       bool operator() (const boost::filesystem::path & file,
00339                        const boost::filesystem::path & searchedFile) const;
00340     };
00344   }
00345 }
00346 #endif

Generated on Wed Jul 4 15:27:21 2007 for libSpm by  doxygen 1.4.6