Spinning Topp Logo BlackTopp Studios
inc
uidgenerator.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _uidgenerator_h
42 #define _uidgenerator_h
43 
44 #include "datatypes.h"
45 #include "interval.h"
46 
47 namespace Mezzanine
48 {
49  ///////////////////////////////////////////////////////////////////////////////
50  /// @class UIDGenerator
51  /// @brief This class will generate keep track of a pool of unique 32-bit ID's that can be used for distinct object instances.
52  ///////////////////////////////////////
54  {
55  public:
56  /// @brief Convenience type for the ID to be used. Should be some flavor of int.
57  typedef UInt32 IDType;
58  /// @brief Convenience type for Intervals used by this class.
60  /// @brief Basic container type for IDs generated and stored by this class.
61  typedef std::vector<IntervalType> IDContainer;
62  /// @brief Iterator type for IDs generated and stored by this class.
63  typedef IDContainer::iterator IDIterator;
64  /// @brief Const Iterator type for IDs generated and stored by this class.
65  typedef IDContainer::const_iterator ConstIDIterator;
66  protected:
67  /// @internal
68  /// @brief The container storing all IDs generated and in use by this generator.
69  IDContainer FreeIDs;
70  public:
71  /// @brief Class constructor.
72  UIDGenerator();
73  /// @brief Class destructor.
74  ~UIDGenerator();
75 
76  ///////////////////////////////////////////////////////////////////////////////
77  // Utility
78 
79  /// @brief Generates a new ID unique to the pool made by this generator.
80  /// @return Returns a new unique ID, or zero if there was a failure.
81  IDType GenerateID();
82  /// @brief Checks to see if an ID is in use.
83  /// @param ID The ID to check whether or not it is used.
84  /// @return Returns true if the specified ID has already been generated and is in use.
85  Boole IsIDUsed(const IDType ID) const;
86  /// @brief Adds a specific ID to the pool of used IDs.
87  /// @param ID The ID to be reserved.
88  /// @return Returns true if the ID was successfully reserved, false if it is already generated.
89  Boole ReserveID(const IDType ID);
90  /// @brief Frees up an ID so that it can be reused.
91  /// @param ID The ID to be freed up for reuse.
92  /// @return Returns true of the ID was successfully released, false if it was already free.
93  Boole ReleaseID(const IDType ID);
94 
95  /// @brief Sorts the free IDs stored in this generator.
96  void Sort();
97  };//UIDGenerator
98 }//Mezzanine
99 
100 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
All the definitions for datatypes as well as some basic conversion functions are defined here...
Interval< IDType > IntervalType
Convenience type for Intervals used by this class.
Definition: uidgenerator.h:59
IDContainer::const_iterator ConstIDIterator
Const Iterator type for IDs generated and stored by this class.
Definition: uidgenerator.h:65
std::vector< IntervalType > IDContainer
Basic container type for IDs generated and stored by this class.
Definition: uidgenerator.h:61
IDContainer FreeIDs
The container storing all IDs generated and in use by this generator.
Definition: uidgenerator.h:69
This class will generate keep track of a pool of unique 32-bit ID's that can be used for distinct obj...
Definition: uidgenerator.h:53
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
This class will generate keep track of a pool of unique 32-bit ID's that can be used for distinct obj...
Definition: interval.h:55
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
IDContainer::iterator IDIterator
Iterator type for IDs generated and stored by this class.
Definition: uidgenerator.h:63
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
UInt32 IDType
Convenience type for the ID to be used. Should be some flavor of int.
Definition: uidgenerator.h:57