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     
00029     class ScopeChainNode {
00030     public:
00031         ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
00032             : next(n), object(o), refCount(1) { }
00033 
00034         ScopeChainNode *next;
00035         ObjectImp *object;
00036         int refCount;
00037     };
00038 
00039     class ScopeChain {
00040     public:
00041         ScopeChain() : _node(0) { }
00042         ~ScopeChain() { deref(); }
00043 
00044         ScopeChain(const ScopeChain &c) : _node(c._node)
00045             { if (_node) ++_node->refCount; }
00046         ScopeChain &operator=(const ScopeChain &);
00047 
00048         bool isEmpty() const { return !_node; }
00049         ObjectImp *top() const { return _node->object; }
00050         ObjectImp *bottom() const { const ScopeChainNode *n = _node;
00051                     while (n->next) n = n->next;
00052                     return n->object; }
00053 
00054         void clear() { deref(); _node = 0; }
00055         void push(ObjectImp *);
00056         void pop();
00057         
00058         void mark();
00059         
00060     private:
00061         ScopeChainNode *_node;
00062         
00063         void deref() { if (_node && --_node->refCount == 0) release(); }
00064         void ref() const;
00065         
00066         void release();
00067     };
00068 
00069 } // namespace KJS
00070 
00071 #endif // KJS_SCOPE_CHAIN_H
KDE Logo
This file is part of the documentation for kjs Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:34:40 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003