PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
id_generator.h
Go to the documentation of this file.
1 /*
2  * handlegen.h
3  *
4  * Class that generates unique numbers in a thread safe manner.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 2013 Vox Lucida
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef PTLIB_ID_GENERATOR_H
28 #define PTLIB_ID_GENERATOR_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <set>
35 #include <ptlib/mutex.h>
36 
37 
38 
44 {
45 public:
46  typedef unsigned int Handle;
47  static const Handle Invalid; // Always zero
48 
49 private:
50  Handle m_nextId;
51  std::set<Handle> m_inUse;
52  PCriticalSection * m_mutex;
53 
54 public:
55  PIdGenerator();
56  ~PIdGenerator();
57 
58  Handle Create();
59  void Release(Handle id);
60  bool IsValid(Handle id) const;
61 };
62 
63 
64 #endif // PTLIB_ID_GENERATOR_H
65 
66 
67 // End Of File ///////////////////////////////////////////////////////////////
Handle Create()
void Release(Handle id)
This class implements critical section mutexes using the most efficient mechanism available on the ho...
Definition: mutex.h:270
unsigned int Handle
Definition: id_generator.h:46
This class generates unique numerical &quot;handles&quot;.
Definition: id_generator.h:43
bool IsValid(Handle id) const
static const Handle Invalid
Definition: id_generator.h:47