kjs Library API Documentation

scope_chain.h

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (C) 2003 Apple Computer, Inc. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 * Boston, MA 02111-1307, USA. 00019 * 00020 */ 00021 00022 #ifndef KJS_SCOPE_CHAIN_H 00023 #define KJS_SCOPE_CHAIN_H 00024 00025 namespace KJS { 00026 00027 class ObjectImp; 00028 00032 class ScopeChainNode { 00033 public: 00034 ScopeChainNode(ScopeChainNode *n, ObjectImp *o) 00035 : next(n), object(o), refCount(1) { } 00036 00037 ScopeChainNode *next; 00038 ObjectImp *object; 00039 int refCount; 00040 }; 00041 00045 class ScopeChain { 00046 public: 00047 ScopeChain() : _node(0) { } 00048 ~ScopeChain() { deref(); } 00049 00050 ScopeChain(const ScopeChain &c) : _node(c._node) 00051 { if (_node) ++_node->refCount; } 00052 ScopeChain &operator=(const ScopeChain &); 00053 00054 bool isEmpty() const { return !_node; } 00055 ObjectImp *top() const { return _node->object; } 00056 ObjectImp *bottom() const { const ScopeChainNode *n = _node; 00057 while (n->next) n = n->next; 00058 return n->object; } 00059 00060 void clear() { deref(); _node = 0; } 00061 void push(ObjectImp *); 00062 void pop(); 00063 00064 void mark(); 00065 00066 private: 00067 ScopeChainNode *_node; 00068 00069 void deref() { if (_node && --_node->refCount == 0) release(); } 00070 void ref() const; 00071 00072 void release(); 00073 }; 00074 00075 } // namespace KJS 00076 00077 #endif // KJS_SCOPE_CHAIN_H
KDE Logo
This file is part of the documentation for kjs Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:40:47 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003