File: datum_datump.cpp

package info (click to toggle)
qlogo 0.92%2Bgit.1.29a5ca2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,556 kB
  • sloc: cpp: 15,101; python: 5,098; sh: 30; makefile: 4
file content (170 lines) | stat: -rw-r--r-- 4,241 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

//===-- qlogo/datum_datumP.cpp - DatumP class implementation -------*-
// C++ -*-===//
//
// This file is part of QLogo.
//
// QLogo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// QLogo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with QLogo.  If not, see <http://www.gnu.org/licenses/>.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the implementation of the DatumP class, which is simply
/// a pointer to a Datum. The DatumP class automatically maintains retain counts
/// to the referred Datum.
///
//===----------------------------------------------------------------------===//

#include "datum.h"
#include <qdebug.h>

Word trueWord("true", false, false);
Word falseWord("false", false, false);


DatumP::DatumP() { d = &notADatum; }

DatumP::DatumP(Datum *other) {
  d = other;
  if (d) {
    d->retain();
  }
}

DatumP::DatumP(const DatumP &other) noexcept {
  d = other.d;
  if (d) {
    d->retain();
  }
}

DatumP::DatumP(bool b) { d = b ? &trueWord : &falseWord; }

void DatumP::destroy() {
  if (d != &notADatum) {
    d->release();
    if (d->shouldDelete()) {
      delete d;
    }
  }
}

DatumP::~DatumP() { destroy(); }

DatumP &DatumP::operator=(const DatumP &other) noexcept {
  if (&other != this) {
    destroy();
    d = other.d;
    if (d) {
      d->retain();
    }
  }
  return *this;
}

DatumP &DatumP::operator=(DatumP *other) noexcept {
  if (other != this) {
    destroy();
    d = other->d;
    d->retain();
  }
  return *this;
}

bool DatumP::operator==(DatumP *other) { return d == other->d; }

bool DatumP::operator==(const DatumP &other) { return d == other.d; }

bool DatumP::operator!=(DatumP *other) { return d != other->d; }

bool DatumP::operator!=(const DatumP &other) { return d != other.d; }

// This is true IFF EQUALP is true
bool DatumP::isEqual(DatumP other, bool ignoreCase) {
  if (d->isa() != other.isa())
    return false;
  if (d == other.d)
    return true;
  return d->isEqual(other, ignoreCase);
}

bool DatumP::isDotEqual(DatumP other) { return (d == other.d); }

bool DatumP::isASTNode() { return d->isa() == Datum::astnodeType; }

bool DatumP::isList() { return d->isa() == Datum::listType; }

bool DatumP::isArray() { return d->isa() == Datum::arrayType; }

bool DatumP::isWord() { return d->isa() == Datum::wordType; }

bool DatumP::isError() { return d->isa() == Datum::errorType; }

Word *DatumP::wordValue() {
  Q_ASSERT(d->isa() == Datum::wordType);
  return (Word *)d;
}

List *DatumP::listValue() {
  if (d->isa() != Datum::listType) {
    qDebug() << "Hello";
  }
  Q_ASSERT(d->isa() == Datum::listType);
  return (List *)d;
}

ListNode *DatumP::listNodeValue() {
  if (d->isa() != Datum::listNodeType) {
    qDebug() << "Hello";
  }
  Q_ASSERT(d->isa() == Datum::listNodeType);
  return (ListNode *)d;
}

Array *DatumP::arrayValue() {
  Q_ASSERT(d->isa() == Datum::arrayType);
  return (Array *)d;
}

Procedure *DatumP::procedureValue() {
  if (d->isa() != Datum::procedureType) {
    qDebug() << "Hello";
  }
  Q_ASSERT(d->isa() == Datum::procedureType);
  return (Procedure *)d;
}

ASTNode *DatumP::astnodeValue() {
  if (d->isa() != Datum::astnodeType) {
    qDebug() << "Error here";
  }
  return (ASTNode *)d;
}

Error *DatumP::errorValue() {
  Q_ASSERT(d->isa() == Datum::errorType);
  return (Error *)d;
}

Datum::DatumType DatumP::isa() { return d->isa(); }

QString DatumP::printValue(bool fullPrintp, int printDepthLimit,
                           int printWidthLimit) {
  return d->printValue(fullPrintp, printDepthLimit, printWidthLimit);
}

QString DatumP::showValue(bool fullPrintp, int printDepthLimit,
                          int printWidthLimit) {
  return d->showValue(fullPrintp, printDepthLimit, printWidthLimit);
}