File: types.cpp

package info (click to toggle)
kdelibs 4:2.2.2-13.woody.14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 36,832 kB
  • ctags: 40,077
  • sloc: cpp: 313,284; ansic: 20,558; xml: 11,448; sh: 11,318; makefile: 2,426; perl: 2,084; yacc: 1,663; java: 1,538; lex: 629; python: 300
file content (299 lines) | stat: -rw-r--r-- 5,330 bytes parent folder | download
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
 *  This file is part of the KDE libraries
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 */

#include <stdio.h>

#include "kjs.h"
#include "object.h"
#include "types.h"
#include "internal.h"
#include "operations.h"
#include "nodes.h"

using namespace KJS;

Undefined::Undefined() : KJSO(UndefinedImp::staticUndefined) { }

Undefined::~Undefined() { }

Null::Null() : KJSO(NullImp::staticNull) { }

Null::~Null() { }

Boolean::Boolean(bool b)
  : KJSO(b ? BooleanImp::staticTrue : BooleanImp::staticFalse)
{
}

Boolean::Boolean(BooleanImp *i) : KJSO(i) { }

Boolean::~Boolean() { }

bool Boolean::value() const
{
  assert(rep);
  return ((BooleanImp*)rep)->value();
}

Number::Number(int i)
  : KJSO(new NumberImp(static_cast<double>(i))) { }

Number::Number(unsigned int u)
  : KJSO(new NumberImp(static_cast<double>(u))) { }

Number::Number(double d)
  : KJSO(new NumberImp(d)) { }

Number::Number(long int l)
  : KJSO(new NumberImp(static_cast<double>(l))) { }

Number::Number(long unsigned int l)
  : KJSO(new NumberImp(static_cast<double>(l))) { }

Number::Number(NumberImp *i)
  : KJSO(i) { }

Number::~Number() { }

double Number::value() const
{
  assert(rep);
  return ((NumberImp*)rep)->value();
}

int Number::intValue() const
{
  assert(rep);
  return (int)((NumberImp*)rep)->value();
}

bool Number::isNaN() const
{
  return KJS::isNaN(((NumberImp*)rep)->value());
}

bool Number::isInf() const
{
  return KJS::isInf(((NumberImp*)rep)->value());
}

String::String(const UString &s) : KJSO(new StringImp(UString(s))) { }

String::String(StringImp *i) : KJSO(i) { }

String::~String() { }

UString String::value() const
{
  assert(rep);
  return ((StringImp*)rep)->value();
}

Reference::Reference(const KJSO& b, const UString &p)
  : KJSO(new ReferenceImp(b, p))
{
}

Reference::~Reference()
{
}

Completion::Completion(Imp *d) : KJSO(d) { }

Completion::Completion(Compl c)
  : KJSO(new CompletionImp(c, KJSO(), UString::null))
{
  if (c == Throw)
    KJScriptImp::setException(new UndefinedImp());
}

Completion::Completion(Compl c, const KJSO& v, const UString &t)
  : KJSO(new CompletionImp(c, v, t))
{
  if (c == Throw)
    KJScriptImp::setException(v.imp());
}

Completion::~Completion() { }

Compl Completion::complType() const
{
  assert(rep);
  return ((CompletionImp*)rep)->completion();
}

bool Completion::isValueCompletion() const
{
  assert(rep);
  return !((CompletionImp*)rep)->value().isNull();
}

KJSO Completion::value() const
{
  assert(isA(CompletionType));
  return ((CompletionImp*)rep)->value();
}

UString Completion::target() const
{
  assert(rep);
  return ((CompletionImp*)rep)->target();
}

ListIterator::ListIterator(const List &l)
  : node(l.hook->next)
{
}

List::List()
{
#ifdef KJS_DEBUG_MEM
  count++;
#endif

  static KJSO *null = 0;
  if (!null)
     null = new KJSO();

  hook = new ListNode(*null, 0L, 0L);
  hook->next = hook;
  hook->prev = hook;
}

List::~List()
{
#ifdef KJS_DEBUG_MEM
  count--;
#endif

  clear();
  delete hook;
}

void List::append(const KJSO& obj)
{
  ListNode *n = new ListNode(obj, hook->prev, hook);
  hook->prev->next = n;
  hook->prev = n;
}

void List::prepend(const KJSO& obj)
{
  ListNode *n = new ListNode(obj, hook, hook->next);
  hook->next->prev = n;
  hook->next = n;
}

void List::removeFirst()
{
  erase(hook->next);
}

void List::removeLast()
{
  erase(hook->prev);
}

void List::remove(const KJSO &obj)
{
  if (obj.isNull())
    return;
  ListNode *n = hook->next;
  while (n != hook) {
    if (n->member.imp() == obj.imp()) {
      erase(n);
      return;
    }
    n = n->next;
  }
}

void List::clear()
{
  ListNode *n = hook->next;
  while (n != hook) {
    n = n->next;
    delete n->prev;
  }

  hook->next = hook;
  hook->prev = hook;
}

List *List::copy() const
{
  List *newList = new List();
  ListIterator e = end();
  ListIterator it = begin();

  while(it != e) {
    newList->append(*it);
    ++it;
  }

  return newList;
}

void List::erase(ListNode *n)
{
  if (n != hook) {
    n->next->prev = n->prev;
    n->prev->next = n->next;
    delete n;
  }
}

int List::size() const
{
  int s = 0;
  ListNode *node = hook;
  while ((node = node->next) != hook)
    s++;

  return s;
}

KJSO List::at(int i) const
{
  if (i < 0 || i >= size())
    return Undefined();

  ListIterator it = begin();
  int j = 0;
  while ((j++ < i))
    it++;

  return *it;
}

List *List::emptyList = 0L;

const List *List::empty()
{
  if (!emptyList)
    emptyList = new List;
#ifdef KJS_DEBUG_MEM
  else
    count++;
#endif


  return emptyList;
}