dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uniqueidmanager.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "uniqueidmanager.h"
29 #include "coreconstants.h"
30 
31 using namespace Core;
32 
33 UniqueIDManager *UniqueIDManager::m_instance = nullptr;
34 
36 {
37  m_instance = this;
38  m_uniqueIdentifiers.insert(Constants::C_GLOBAL, Constants::C_GLOBAL_ID);
39 }
40 
42 {
43  m_instance = nullptr;
44 }
45 
46 bool UniqueIDManager::hasUniqueIdentifier(const QString &id) const
47 {
48  return m_uniqueIdentifiers.contains(id);
49 }
50 
51 int UniqueIDManager::uniqueIdentifier(const QString &id)
52 {
53  if (hasUniqueIdentifier(id))
54  return m_uniqueIdentifiers.value(id);
55 
56  int uid = m_uniqueIdentifiers.count() + 1;
57  m_uniqueIdentifiers.insert(id, uid);
58  return uid;
59 }
60 
62 {
63  return m_uniqueIdentifiers.key(uid);
64 }
int uniqueIdentifier(const QString &id)
bool hasUniqueIdentifier(const QString &id) const
const int C_GLOBAL_ID
Definition: coreconstants.h:90
const char *const C_GLOBAL
Definition: coreconstants.h:89
QString stringForUniqueIdentifier(int uid)