1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #include "U2Type.h"
23 
24 namespace U2 {
25 
26 //////////////////////////////////////////////////////////////////////////
27 /// U2Entity implementation
28 //////////////////////////////////////////////////////////////////////////
29 
U2Entity(const U2DataId & id)30 U2Entity::U2Entity(const U2DataId &id)
31     : id(id) {
32 }
33 
U2Entity(const U2Entity & other)34 U2Entity::U2Entity(const U2Entity &other)
35     : id(other.id) {
36 }
37 
~U2Entity()38 U2Entity::~U2Entity() {
39 }
40 
hasValidId() const41 bool U2Entity::hasValidId() const {
42     return !id.isEmpty();
43 }
44 
operator =(const U2Entity & other)45 U2Entity U2Entity::operator=(const U2Entity &other) {
46     id = other.id;
47     return *this;
48 }
49 
operator ==(const U2Entity & other) const50 bool U2Entity::operator==(const U2Entity &other) const {
51     return id == other.id;
52 }
53 
operator !=(const U2Entity & other) const54 bool U2Entity::operator!=(const U2Entity &other) const {
55     return id != other.id;
56 }
57 
operator <(const U2Entity & other) const58 bool U2Entity::operator<(const U2Entity &other) const {
59     return id < other.id;
60 }
61 
62 //////////////////////////////////////////////////////////////////////////
63 /// U2DbiRef implementation
64 //////////////////////////////////////////////////////////////////////////
65 
U2DbiRef(const U2DbiFactoryId & dbiFactoryId,const U2DbiId & dbiId)66 U2DbiRef::U2DbiRef(const U2DbiFactoryId &dbiFactoryId, const U2DbiId &dbiId)
67     : dbiFactoryId(dbiFactoryId), dbiId(dbiId) {
68 }
69 
isValid() const70 bool U2DbiRef::isValid() const {
71     return !dbiFactoryId.isEmpty() && !dbiId.isEmpty();
72 }
73 
operator !=(const U2DbiRef & r2) const74 bool U2DbiRef::operator!=(const U2DbiRef &r2) const {
75     return !(operator==(r2));
76 }
77 
operator ==(const U2DbiRef & r2) const78 bool U2DbiRef::operator==(const U2DbiRef &r2) const {
79     return dbiFactoryId == r2.dbiFactoryId && dbiId == r2.dbiId;
80 }
81 
operator <(const U2DbiRef & r2) const82 bool U2DbiRef::operator<(const U2DbiRef &r2) const {
83     return dbiFactoryId + dbiId < r2.dbiFactoryId + r2.dbiId;
84 }
85 
operator <<(QDataStream & out,const U2DbiRef & dbiRef)86 QDataStream &operator<<(QDataStream &out, const U2DbiRef &dbiRef) {
87     out << dbiRef.dbiFactoryId << dbiRef.dbiId;
88     return out;
89 }
90 
operator >>(QDataStream & in,U2DbiRef & dbiRef)91 QDataStream &operator>>(QDataStream &in, U2DbiRef &dbiRef) {
92     in >> dbiRef.dbiFactoryId;
93     in >> dbiRef.dbiId;
94     return in;
95 }
96 
97 //////////////////////////////////////////////////////////////////////////
98 /// U2EntityRef implementation
99 //////////////////////////////////////////////////////////////////////////
100 
U2EntityRef()101 U2EntityRef::U2EntityRef()
102     : version(0) {
103 }
104 
U2EntityRef(const U2DbiRef & dbiRef,const U2DataId & entityId)105 U2EntityRef::U2EntityRef(const U2DbiRef &dbiRef, const U2DataId &entityId)
106     : dbiRef(dbiRef), entityId(entityId), version(0) {
107 }
108 
isValid() const109 bool U2EntityRef::isValid() const {
110     return dbiRef.isValid() && !entityId.isEmpty();
111 }
112 
operator ==(const U2EntityRef & other) const113 bool U2EntityRef::operator==(const U2EntityRef &other) const {
114     return (entityId == other.entityId) && (version == other.version) && (dbiRef == other.dbiRef);
115 }
116 
operator !=(const U2EntityRef & other) const117 bool U2EntityRef::operator!=(const U2EntityRef &other) const {
118     return !(operator==(other));
119 }
120 
operator <(const U2EntityRef & other) const121 bool U2EntityRef::operator<(const U2EntityRef &other) const {
122     if (dbiRef.dbiFactoryId != other.dbiRef.dbiFactoryId) {
123         return dbiRef.dbiFactoryId < other.dbiRef.dbiFactoryId;
124     } else if (dbiRef.dbiId != other.dbiRef.dbiId) {
125         return dbiRef.dbiId < other.dbiRef.dbiId;
126     } else if (version != other.version) {
127         return version < other.version;
128     } else if (entityId != other.entityId) {
129         return entityId < other.entityId;
130     }
131     return false;
132 }
133 
134 namespace {
135 
registerMetaInfo()136 bool registerMetaInfo() {
137     qRegisterMetaType<U2DbiRef>("U2::U2DbiRef");
138     qRegisterMetaTypeStreamOperators<U2DbiRef>("U2::U2DbiRef");
139     return true;
140 }
141 
registerDataId()142 bool registerDataId() {
143     qRegisterMetaType<U2DataId>("U2DataId");
144     return true;
145 }
146 
147 class Registrator {
148     static const bool u2DataIdRegistered;
149 };
150 
151 const bool Registrator::u2DataIdRegistered = registerDataId();
152 
153 }  // namespace
154 
155 bool U2DbiRef::metaInfoRegistered = registerMetaInfo();
156 
157 }  // namespace U2
158