GElementID.h

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by Raphael Langerhorst                        *
00003  *   raphael-langerhorst@gmx.at                                            *
00004  *                                                                         *
00005  *   Permission is hereby granted, free of charge, to any person obtaining *
00006  *   a copy of this software and associated documentation files (the       *
00007  *   "Software"), to deal in the Software without restriction, including   *
00008  *   without limitation the rights to use, copy, modify, merge, publish,   *
00009  *   distribute, sublicense, and/or sell copies of the Software, and to    *
00010  *   permit persons to whom the Software is furnished to do so, subject to *
00011  *   the following conditions:                                             *
00012  *                                                                         *
00013  *   The above copyright notice and this permission notice shall be        *
00014  *   included in all copies or substantial portions of the Software.       *
00015  *                                                                         *
00016  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
00017  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
00018  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
00019  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
00020  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
00021  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
00022  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
00023  ***************************************************************************/
00024 
00025 #ifndef GELEMENTIDH
00026 #define GELEMENTIDH
00027 
00028 #include <QList>
00029 
00030 class QString;
00031 
00032 namespace GCS
00033 {
00034 
00047 class GIDRange
00048 {
00049   private:
00054     unsigned long LowerBound;
00055 
00060     unsigned long UpperBound;
00061 
00062   public:
00066     GIDRange();
00067 
00071     GIDRange(unsigned long lower_bound, unsigned long upper_bound);
00072     
00077     unsigned long takeID();
00078 
00082     bool isEmpty() const;
00083 
00087     unsigned long count() const;
00088 
00092     void setRange(unsigned long low, unsigned long high);
00093 
00097     unsigned long getLowerBound() const;
00098 
00102     unsigned long getUpperBound() const;
00103 };
00104 
00109 class GIDContainer : public QList<GIDRange*>
00110 {
00111   public:
00112     virtual ~GIDContainer() {}
00113 };
00114 
00125 class GElementID
00126 {  
00127   private:
00128     
00132     static GIDContainer FreeIDs;
00133     
00134   public:
00135 
00140     static GElementID getFreeID();
00141 
00146     static GIDContainer getFreeIDRange(unsigned long amount);
00147 
00151     static void addFreeIDRange(unsigned long lower_bound, unsigned long upper_bound);
00152 
00156     static unsigned long countFreeIDs();
00157     
00158   private:
00159   
00163     unsigned long ID;
00164 
00165   public:
00178     GElementID();
00179     
00180   public:
00181   
00185     GElementID(unsigned long ID);
00186 
00190     GElementID(const GElementID& original);
00191 
00195     unsigned long getID() const;
00196     
00200     QString toString() const;
00201 
00206     bool operator==(const GElementID& id) const;
00207     
00212     bool operator!=(const GElementID& id) const;
00213     
00218     bool operator>(const GElementID& id) const;
00219     
00224     bool operator<(const GElementID& id) const;
00225     
00230     bool operator>=(const GElementID& id) const;
00231     
00236     bool operator<=(const GElementID& id) const;
00237     
00238     //this is a workaround because QValueListNode needs
00239     //a default constructor;
00240     //
00241     //this constructor is declared private in GElementID
00242     //and made only available to this class
00243     //
00244     //note: QValueListNode is used by QValueList
00245     
00246 //     /**
00247 //      * Gives QValueListNode access to the private default
00248 //      * constructor - see GElementID() for details.
00249 //      * 
00250 //      */
00251 //     friend class QValueListNode<GElementID>;
00252 };
00253 
00254 }
00255 
00256 #endif

Generated on Thu Nov 16 07:49:12 2006 for G System by  doxygen 1.4.7