Debian Codegraph @

Source/Reasoner/Generator/CStringRefStringHasher.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude 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 (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CStringRefStringHasher.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Generator {
29
30 CStringRefStringHasher::CStringRefStringHasher() {
31 mReferenceOnly = false;
32 }
33
34
35 CStringRefStringHasher::CStringRefStringHasher(const QString& string) {
36 mReferenceOnly = false;
37 mString = string;
38 }
39
40 CStringRefStringHasher::CStringRefStringHasher(const QStringRef& stringRef) {
41 mReferenceOnly = true;
42 mStringRef = stringRef;
43 }
44
45
46 bool CStringRefStringHasher::isReferenceOnly() const {
47 return mReferenceOnly;
48 }
49
50 bool CStringRefStringHasher::isEmpty() const {
51 if (mReferenceOnly) {
52 return mStringRef.isEmpty();
53 } else {
54 return mString.isEmpty();
55 }
56 }
57
58 const QString& CStringRefStringHasher::getString() const {
59 return mString;
60 }
61
62 const QStringRef& CStringRefStringHasher::getStringRef() const {
63 return mStringRef;
64 }
65
66 QStringRef CStringRefStringHasher::toStringRefernce() const {
67 if (mReferenceOnly) {
68 return mStringRef;
69 } else {
70 return mString.leftRef(-1);
71 }
72 }
73
74
75 bool CStringRefStringHasher::operator==(const CStringRefStringHasher& other) const {
76 if (mReferenceOnly && other.mReferenceOnly) {
77 return mStringRef == other.mStringRef;
78 } else if (mReferenceOnly && !other.mReferenceOnly) {
79 return mStringRef == other.mString;
80 } else if (!mReferenceOnly && other.mReferenceOnly) {
81 return other.mStringRef == mString;
82 } else if (!mReferenceOnly && !other.mReferenceOnly) {
83 return mString == other.mString;
84 }
85 return false;
86 }
87
88 }; // end namespace Generator
89
90 }; // end namespace Reasoner
91
92 }; // end namespace Konclude