• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
value.h
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
5 * Copyright (C) 2003 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef _KJS_VALUE_H_
25#define _KJS_VALUE_H_
26
27#include <stdlib.h> // Needed for size_t
28
29#include "ustring.h"
30#include "simple_number.h"
31
32// Primitive data types
33
34namespace KJS {
35
36 class Value;
37 class ValueImp;
38 class ValueImpPrivate;
39 class Undefined;
40 class UndefinedImp;
41 class Null;
42 class NullImp;
43 class Boolean;
44 class BooleanImp;
45 class String;
46 class StringImp;
47 class Number;
48 class NumberImp;
49 class Object;
50 class ObjectImp;
51 class Reference;
52 class List;
53 class ListImp;
54 class Completion;
55 class ExecState;
56
60 enum Type {
61 UnspecifiedType = 0,
62 UndefinedType = 1,
63 NullType = 2,
64 BooleanType = 3,
65 StringType = 4,
66 NumberType = 5,
67 ObjectType = 6
68 };
69
78 class KJS_EXPORT ValueImp {
79 friend class Collector;
80 friend class Value;
81 friend class ContextImp;
82 public:
83 ValueImp();
84 virtual ~ValueImp();
85
86 ValueImp* ref() { if (!SimpleNumber::is(this)) refcount++; return this; }
87 bool deref() { if (SimpleNumber::is(this)) return false; else return (!--refcount); }
88
89 virtual void mark();
90 bool marked() const;
91 void* operator new(size_t);
92 void operator delete(void*);
93
99 void setGcAllowed();
100
101 // Will crash if called on a simple number.
102 void setGcAllowedFast() { _flags |= VI_GCALLOWED; }
103
104 int toInteger(ExecState *exec) const;
105 int toInt32(ExecState *exec) const;
106 unsigned int toUInt32(ExecState *exec) const;
107 unsigned short toUInt16(ExecState *exec) const;
108
109 // Dispatch wrappers that handle the special small number case
110
111 Type dispatchType() const;
112 Value dispatchToPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const;
113 bool dispatchToBoolean(ExecState *exec) const;
114 double dispatchToNumber(ExecState *exec) const;
115 UString dispatchToString(ExecState *exec) const;
116 bool dispatchToUInt32(unsigned&) const;
117 Object dispatchToObject(ExecState *exec) const;
118
119 unsigned short int refcount;
120
121 bool isDestroyed() const { return _flags & VI_DESTRUCTED; }
122
123 private:
124 unsigned short int _flags;
125
126 virtual Type type() const = 0;
127
128 // The conversion operations
129
130 virtual Value toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0;
131 virtual bool toBoolean(ExecState *exec) const = 0;
132 virtual double toNumber(ExecState *exec) const = 0;
133 // TODO: no need for the following 4 int conversions to be virtual
134 virtual UString toString(ExecState *exec) const = 0;
135 virtual Object toObject(ExecState *exec) const = 0;
136 virtual bool toUInt32(unsigned&) const;
137
138 enum {
139 VI_MARKED = 1,
140 VI_GCALLOWED = 2,
141 VI_CREATED = 4,
142 VI_DESTRUCTED = 8 // nice word we have here :)
143 }; // VI means VALUEIMPL
144
145 ValueImpPrivate *_vd;
146
147 // Give a compile time error if we try to copy one of these.
148 ValueImp(const ValueImp&);
149 ValueImp& operator=(const ValueImp&);
150 };
151
167 class KJS_EXPORT Value {
168 public:
169 Value() : rep(0) { }
170 explicit Value(ValueImp *v);
171 Value(const Value &v);
172 ~Value();
173
174 Value& operator=(const Value &v);
181 bool isValid() const { return rep != 0; }
186 bool isNull() const { return rep == 0; }
187 ValueImp *imp() const { return rep; }
188
195 Type type() const { return rep->dispatchType(); }
196
203 bool isA(Type t) const { return rep->dispatchType() == t; }
204
209 Value toPrimitive(ExecState *exec,
210 Type preferredType = UnspecifiedType) const
211 { return rep->dispatchToPrimitive(exec, preferredType); }
212
216 bool toBoolean(ExecState *exec) const { return rep->dispatchToBoolean(exec); }
217
221 double toNumber(ExecState *exec) const { return rep->dispatchToNumber(exec); }
222
226 int toInteger(ExecState *exec) const { return rep->toInteger(exec); }
227
231 int toInt32(ExecState *exec) const { return rep->toInt32(exec); }
232
236 unsigned int toUInt32(ExecState *exec) const { return rep->toUInt32(exec); }
237
241 unsigned short toUInt16(ExecState *exec) const { return rep->toUInt16(exec); }
242
246 UString toString(ExecState *exec) const { return rep->dispatchToString(exec); }
247
251 Object toObject(ExecState *exec) const;
252
256 bool toUInt32(unsigned& i) const { return rep->dispatchToUInt32(i); }
257
258 protected:
259 ValueImp *rep;
260 };
261
262 // Primitive types
263
269 class KJS_EXPORT Undefined : public Value {
270 public:
271 Undefined();
272
282 static Undefined dynamicCast(const Value &v);
283 private:
284 friend class UndefinedImp;
285 explicit Undefined(UndefinedImp *v);
286
287 };
288
294 class KJS_EXPORT Null : public Value {
295 public:
296 Null();
297
307 static Null dynamicCast(const Value &v);
308 private:
309 friend class NullImp;
310 explicit Null(NullImp *v);
311 };
312
316 class KJS_EXPORT Boolean : public Value {
317 public:
318 Boolean(bool b = false);
319
329 static Boolean dynamicCast(const Value &v);
330
331 bool value() const;
332 private:
333 friend class BooleanImp;
334 explicit Boolean(BooleanImp *v);
335 };
336
340 class KJS_EXPORT String : public Value {
341 public:
342 String(const UString &s = "");
343
353 static String dynamicCast(const Value &v);
354
355 UString value() const;
356 private:
357 friend class StringImp;
358 explicit String(StringImp *v);
359 };
360
361 extern const double NaN;
362 extern const double Inf;
363
367 class KJS_EXPORT Number : public Value {
368 friend class ValueImp;
369 public:
370 Number(int i);
371 Number(unsigned int u);
372 Number(double d = 0.0);
373 Number(long int l);
374 Number(long unsigned int l);
375
376 double value() const;
377 int intValue() const;
378
379 bool isNaN() const;
380 bool isInf() const;
381
391 static Number dynamicCast(const Value &v);
392 private:
393 friend class NumberImp;
394 explicit Number(NumberImp *v);
395 };
396
397} // namespace
398
399#endif // _KJS_VALUE_H_
KJS::Boolean
Represents an primitive Boolean value.
Definition: value.h:316
KJS::Collector
Garbage collector.
Definition: collector.h:37
KJS::ContextImp
Execution context.
Definition: context.h:34
KJS::ExecState
Represents the current state of script execution.
Definition: interpreter.h:438
KJS::Null
Represents an primitive Null value.
Definition: value.h:294
KJS::Number
Represents an primitive Number value.
Definition: value.h:367
KJS::Object
Represents an Object.
Definition: object.h:81
KJS::String
Represents an primitive String value.
Definition: value.h:340
KJS::UString
Unicode string class.
Definition: ustring.h:189
KJS::Undefined
Represents an primitive Undefined value.
Definition: value.h:269
KJS::ValueImp
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Definition: value.h:78
KJS::Value
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents.
Definition: value.h:167
KJS::Value::toString
UString toString(ExecState *exec) const
Performs the ToString type conversion operation on this value (ECMA 9.8)
Definition: value.h:246
KJS::Value::isA
bool isA(Type t) const
Checks whether or not the value is of a particular tpye.
Definition: value.h:203
KJS::Value::toUInt32
bool toUInt32(unsigned &i) const
Checks if we can do a lossless conversion to UInt32.
Definition: value.h:256
KJS::Value::toInteger
int toInteger(ExecState *exec) const
Performs the ToInteger type conversion operation on this value (ECMA 9.4)
Definition: value.h:226
KJS::Value::toUInt32
unsigned int toUInt32(ExecState *exec) const
Performs the ToUInt32 type conversion operation on this value (ECMA 9.6)
Definition: value.h:236
KJS::Value::toInt32
int toInt32(ExecState *exec) const
Performs the ToInt32 type conversion operation on this value (ECMA 9.5)
Definition: value.h:231
KJS::Value::isNull
bool isNull() const
Definition: value.h:186
KJS::Value::toPrimitive
Value toPrimitive(ExecState *exec, Type preferredType=UnspecifiedType) const
Performs the ToPrimitive type conversion operation on this value (ECMA 9.1)
Definition: value.h:209
KJS::Value::toBoolean
bool toBoolean(ExecState *exec) const
Performs the ToBoolean type conversion operation on this value (ECMA 9.2)
Definition: value.h:216
KJS::Value::isValid
bool isValid() const
Returns whether or not this is a valid value.
Definition: value.h:181
KJS::Value::type
Type type() const
Returns the type of value.
Definition: value.h:195
KJS::Value::toUInt16
unsigned short toUInt16(ExecState *exec) const
Performs the ToUInt16 type conversion operation on this value (ECMA 9.7)
Definition: value.h:241
KJS::Value::toNumber
double toNumber(ExecState *exec) const
Performs the ToNumber type conversion operation on this value (ECMA 9.3)
Definition: value.h:221

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.9.4
This website is maintained by Timothy Pearson.