# kjs Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# types.cpp

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Lesser General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Lesser General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Lesser General Public License
    00018  *  along with this library; see the file COPYING.LIB.  If not, write to
    00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  *  Boston, MA 02111-1307, USA.
    00021  *
    00022  *  $Id: types.cpp,v 1.28 2002/09/22 15:23:57 porten Exp $
    00023  */
    00024
    00025 #include "value.h"
    00026 #include "object.h"
    00027 #include "types.h"
    00028 #include "interpreter.h"
    00029
    00030 #include <assert.h>
    00031 #include <math.h>
    00032 #include <stdio.h>
    00033
    00034 #include "internal.h"
    00035 #include "collector.h"
    00036 #include "operations.h"
    00037 #include "error_object.h"
    00038 #include "nodes.h"
    00039
    00040 using namespace KJS;
    00041
    00042 // ------------------------------ Reference ------------------------------------
    00043
    00044 Reference::Reference(const Object& b, const UString& p)
    00045   : Value(new ReferenceImp(b,p))
    00046 {
    00047 }
    00048
    00049 Reference::Reference(const Null& b, const UString& p)
    00050   : Value(new ReferenceImp(b,p))
    00051 {
    00052 }
    00053
    00054 Reference::Reference(ReferenceImp *v) : Value(v)
    00055 {
    00056 }
    00057
    00058 Reference::Reference(const Reference &v) : Value(v)
    00059 {
    00060 }
    00061
    00062 Reference::Reference(const Value& v) : Value(v)
    00063 {
    00064 }
    00065
    00066 Reference::~Reference()
    00067 {
    00068 }
    00069
    00070 Reference& Reference::operator=(const Reference &v)
    00071 {
    00072   Value::operator=(v);
    00073   return *this;
    00074 }
    00075
    00076 Reference Reference::dynamicCast(const Value &v)
    00077 {
    00078   if (v.isNull() || v.type() != ReferenceType)
    00079     return 0;
    00080
    00081   return static_cast<ReferenceImp*>(v.imp());
    00082 }
    00083
    00084 // ------------------------------ ListIterator ---------------------------------
    00085
    00086 //d  dont add   ListIterator();
    00087
    00088 ListIterator::ListIterator(ListNode *n) : node(n)
    00089 {
    00090 }
    00091
    00092 ListIterator::ListIterator(const List &l)
    00093   : node(static_cast<ListImp*>(l.imp())->hook->next)
    00094 {
    00095 }
    00096
    00097 ListIterator& ListIterator::operator=(const ListIterator &iterator)
    00098 {
    00099   node=iterator.node;
    00100   return *this;
    00101 }
    00102
    00103 ListIterator::ListIterator(const ListIterator &i) : node(i.node)
    00104 {
    00105 }
    00106
    00107 ListIterator::~ListIterator()
    00108 {
    00109 }
    00110
    00111 ValueImp* ListIterator::operator->() const
    00112 {
    00113   return node->member;
    00114 }
    00115
    00116     //    operator Value* () const { return node->member; }
    00117 Value ListIterator::operator*() const
    00118 {
    00119   return Value(node->member);
    00120 }
    00121
    00122     //    operator Value*() const { return node->member; }
    00123 Value ListIterator::operator++()
    00124 {
    00125   node = node->next;
    00126   return Value(node->member);
    00127 }
    00128
    00129 Value ListIterator::operator++(int)
    00130 {
    00131   const ListNode *n = node;
    00132   ++*this;
    00133   return Value(n->member);
    00134 }
    00135
    00136 Value ListIterator::operator--()
    00137 {
    00138   node = node->prev;
    00139   return Value(node->member);
    00140 }
    00141
    00142 Value ListIterator::operator--(int)
    00143 {
    00144   const ListNode *n = node;
    00145   --*this;
    00146   return Value(n->member);
    00147 }
    00148
    00149 bool ListIterator::operator==(const ListIterator &it) const
    00150 {
    00151   return (node==it.node);
    00152 }
    00153
    00154 bool ListIterator::operator!=(const ListIterator &it) const
    00155 {
    00156   return (node!=it.node);
    00157 }
    00158
    00159 // ------------------------------ List -----------------------------------------
    00160
    00161 List::List()
    00162   : Value(new ListImp())
    00163 {
    00164   //fprintf(stderr,"List::List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount);
    00165 }
    00166
    00167 List::List(ListImp *v) : Value(v)
    00168 {
    00169   //fprintf(stderr,"List::List(imp) this=%p imp=%p refcount=%d\n",this,v,v?v->refcount:0);
    00170 }
    00171
    00172 List::List(const List &v) : Value(v)
    00173 {
    00174   //fprintf(stderr,"List::List(List) this=%p imp=%p refcount=%d\n",this,rep,rep?rep->refcount:0);
    00175 }
    00176
    00177 List::~List()
    00178 {
    00179   //fprintf(stderr,"List::~List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount-1);
    00180 }
    00181
    00182 List& List::operator=(const List &v)
    00183 {
    00184   //fprintf(stderr,"List::operator=() this=%p\n",this);
    00185   Value::operator=(v);
    00186   return *this;
    00187 }
    00188
    00189 List List::dynamicCast(const Value &v)
    00190 {
    00191   if (v.isNull() || v.type() != ListType)
    00192     return 0;
    00193
    00194   return static_cast<ListImp*>(v.imp());
    00195 }
    00196
    00197 void List::append(const Value& val)
    00198 {
    00199   static_cast<ListImp*>(rep)->append(val);
    00200 }
    00201
    00202 void List::prepend(const Value& val)
    00203 {
    00204   static_cast<ListImp*>(rep)->prepend(val);
    00205 }
    00206
    00207 void List::appendList(const List& lst)
    00208 {
    00209   static_cast<ListImp*>(rep)->appendList(lst);
    00210 }
    00211
    00212 void List::prependList(const List& lst)
    00213 {
    00214   static_cast<ListImp*>(rep)->prependList(lst);
    00215 }
    00216
    00217 void List::removeFirst()
    00218 {
    00219   static_cast<ListImp*>(rep)->removeFirst();
    00220 }
    00221
    00222 void List::removeLast()
    00223 {
    00224   static_cast<ListImp*>(rep)->removeLast();
    00225 }
    00226
    00227 void List::remove(const Value &val)
    00228 {
    00229   static_cast<ListImp*>(rep)->remove(val);
    00230 }
    00231
    00232 void List::clear()
    00233 {
    00234   static_cast<ListImp*>(rep)->clear();
    00235 }
    00236
    00237 List List::copy() const
    00238 {
    00239   return static_cast<ListImp*>(rep)->copy();
    00240 }
    00241
    00242 ListIterator List::begin() const
    00243 {
    00244   return static_cast<ListImp*>(rep)->begin();
    00245 }
    00246
    00247 ListIterator List::end() const
    00248 {
    00249   return static_cast<ListImp*>(rep)->end();
    00250 }
    00251
    00252 bool List::isEmpty() const
    00253 {
    00254   return static_cast<ListImp*>(rep)->isEmpty();
    00255 }
    00256
    00257 int List::size() const
    00258 {
    00259   return static_cast<ListImp*>(rep)->size();
    00260 }
    00261
    00262 Value List::at(int i) const
    00263 {
    00264   return static_cast<ListImp*>(rep)->at(i);
    00265 }
    00266
    00267 Value List::operator[](int i) const
    00268 {
    00269   return static_cast<ListImp*>(rep)->at(i);
    00270 }
    00271
    00272 const List List::empty()
    00273 {
    00274   return ListImp::empty();
    00275 }
    00276
    00277 #ifdef KJS_DEBUG_MEM
    00278 void List::globalClear()
    00279 {
    00280   delete ListImp::emptyList;
    00281   ListImp::emptyList = 0L;
    00282 }
    00283 #endif
    00284
    00285
    00286 // ------------------------------ Completion -----------------------------------
    00287
    00288 Completion::Completion(ComplType c, const Value& v, const UString &t)
    00289   : Value(new CompletionImp(c,v,t))
    00290 {
    00291 }
    00292
    00293 Completion::Completion(CompletionImp *v) : Value(v)
    00294 {
    00295 }
    00296
    00297 Completion::Completion(const Completion &v) : Value(v)
    00298 {
    00299 }
    00300
    00301 Completion::~Completion()
    00302 {
    00303 }
    00304
    00305 Completion& Completion::operator=(const Completion &v)
    00306 {
    00307   Value::operator=(v);
    00308   return *this;
    00309 }
    00310
    00311 Completion Completion::dynamicCast(const Value &v)
    00312 {
    00313   if (v.isNull() || v.type() != CompletionType)
    00314     return 0;
    00315
    00316   return static_cast<CompletionImp*>(v.imp());
    00317 }
    00318
    00319 ComplType Completion::complType() const
    00320 {
    00321   return static_cast<CompletionImp*>(rep)->complType();
    00322 }
    00323
    00324 Value Completion::value() const
    00325 {
    00326   return static_cast<CompletionImp*>(rep)->value();
    00327 }
    00328
    00329 UString Completion::target() const
    00330 {
    00331   return static_cast<CompletionImp*>(rep)->target();
    00332 }
    00333
    00334 bool Completion::isValueCompletion() const
    00335 {
    00336   return !value().isNull();
    00337 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:36 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001