Code_TYMPAN  4.4.0
Industrial site acoustic simulation
idgen.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2014> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef TY_IDGEN
17 #define TY_IDGEN
18 
19 #include <string>
20 #include <quuid.h>
21 
22 namespace tympan
23 {
24 class UuidAdapter;
25 } // namespace tympan
26 
27 class OGenID
28 {
29  friend size_t qHash(const OGenID& uid);
30 
31 private:
32  QUuid quid;
33  friend class tympan::UuidAdapter;
34 
35 public:
36  OGenID();
37  OGenID(const OGenID& other);
38  OGenID(const QString& id);
39  OGenID& operator=(const OGenID& other);
40 
41  ~OGenID();
42 
43  void GenUniqueID();
44  bool isNull() const;
45 
46  const QString toString() const;
47  void FromString(const char* strUuid);
48  void FromString(const QString& strUuid);
49 
50  bool operator==(const OGenID& orig) const;
51  bool operator!=(const OGenID& orig) const;
52  bool operator<(const OGenID& other) const;
53 };
54 
55 inline OGenID::OGenID() {}
56 inline OGenID::~OGenID() {}
57 
58 inline OGenID::OGenID(const OGenID& other) : quid(other.quid) {}
59 
60 inline OGenID::OGenID(const QString& id) : quid(id) {}
61 
62 inline OGenID& OGenID::operator=(const OGenID& other)
63 {
64  quid = other.quid;
65  return *this;
66 }
67 
68 inline void OGenID::GenUniqueID()
69 {
70  quid = QUuid::createUuid();
71 }
72 
73 inline bool OGenID::isNull() const
74 {
75  return quid.isNull();
76 }
77 
78 inline const QString OGenID::toString() const
79 {
80  return quid.toString();
81 }
82 
83 inline void OGenID::FromString(const char* strUuid)
84 {
85  quid = QUuid(QString(strUuid));
86 }
87 
88 inline void OGenID::FromString(const QString& strUuid)
89 {
90  quid = QUuid(strUuid);
91 }
92 
93 inline bool OGenID::operator==(const OGenID& orig) const
94 {
95  return quid == orig.quid;
96 }
97 
98 inline bool OGenID::operator!=(const OGenID& orig) const
99 {
100  return quid != orig.quid;
101 }
102 
103 inline bool OGenID::operator<(const OGenID& other) const
104 {
105  return quid < other.quid;
106 }
107 
113 inline size_t qHash(QUuid& uuid)
114 {
115  return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^
116  ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^
117  ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]);
118 }
119 
120 inline size_t qHash(const OGenID& uid)
121 {
122  return qHash(uid.quid);
123 }
124 
125 #endif // TY_IDGEN
int id
Definition: idgen.h:28
void FromString(const char *strUuid)
Definition: idgen.h:83
bool isNull() const
Definition: idgen.h:73
bool operator!=(const OGenID &orig) const
Definition: idgen.h:98
~OGenID()
Definition: idgen.h:56
OGenID()
Definition: idgen.h:55
QUuid quid
Definition: idgen.h:32
friend size_t qHash(const OGenID &uid)
Definition: idgen.h:120
bool operator==(const OGenID &orig) const
Definition: idgen.h:93
void GenUniqueID()
Definition: idgen.h:68
friend class tympan::UuidAdapter
Definition: idgen.h:33
const QString toString() const
Definition: idgen.h:78
bool operator<(const OGenID &other) const
Definition: idgen.h:103
OGenID & operator=(const OGenID &other)
Definition: idgen.h:62
size_t qHash(QUuid &uuid)
Returns a hash of the QUuid For old version of Qt, imported from http://qt.gitorious....
Definition: idgen.h:113