idMan.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef IDMAN_H
00020 #define IDMAN_H
00021 
00022 class IDataSource;
00023 class ODataSource;
00024 
00025 #include <vector>
00026 
00027 //
00028 // idMan. Used to allocate and keep track of unused ids.
00029 // Supposed to be used by Kernel and World for pID and ObjId
00030 //
00031 // The idMan itself uses a nifty linked list that is also an array.
00032 // As such it has the advantages of both. Adds and removals are fast,
00033 // As is checking to see if an ID is used.
00034 //
00035 // idMan works as a LILO (last in last out) for id recycling. So an id that has
00036 // been cleared will not be used until all other currently unused ids have been
00037 // allocated.
00038 //
00039 
00040 class idMan
00041 {
00042         uint16          begin;                  
00043         uint16          end;                    
00044         uint16          max_end;                
00045         uint16          startcount;             
00046 
00047         uint16          usedcount;              
00048 
00049         std::vector<uint16> ids;        
00050         uint16          first;                  
00051         uint16          last;                   
00052 public:
00056         idMan(uint16 begin, uint16 max_end, uint16 startcount=0);
00057         ~idMan();
00058 
00060         void            clearAll();
00061 
00064         uint16          getNewID();
00065 
00069         bool            reserveID(uint16 id);
00070 
00072         void            clearID(uint16 id);
00073 
00075         bool            isIDUsed(uint16 id)
00076                 { return id >= begin && id <= end && ids[id] == 0 && id != last; }
00077 
00078         void save(ODataSource* ods);
00079         bool load(IDataSource* ids, uint32 version);
00080 
00081 private:
00084         void expand();
00085 };
00086 
00087 #endif //IDMAN_H

Generated on Fri Jul 27 22:27:19 2007 for pentagram by  doxygen 1.4.7