kjs Library: scope_chain.cpp Source File (kjs Library)

| # kjs Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# scope_chain.cpp

    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 #include "scope_chain.h"
    00023
    00024 #include "object.h"
    00025
    00026 #include <assert.h>
    00027
    00028 namespace KJS {
    00029
    00030 inline void ScopeChain::ref() const
    00031 {
    00032     for (ScopeChainNode *n = _node; n; n = n->next) {
    00033         if (n->refCount++ != 0)
    00034             break;
    00035     }
    00036 }
    00037
    00038 ScopeChain &ScopeChain::operator=(const ScopeChain &c)
    00039 {
    00040     c.ref();
    00041     deref();
    00042     _node = c._node;
    00043     return *this;
    00044 }
    00045
    00046 void ScopeChain::push(ObjectImp *o)
    00047 {
    00048     assert(o);
    00049     _node = new ScopeChainNode(_node, o);
    00050 }
    00051
    00052 void ScopeChain::pop()
    00053 {
    00054     ScopeChainNode *oldNode = _node;
    00055     assert(oldNode);
    00056     ScopeChainNode *newNode = oldNode->next;
    00057     _node = newNode;
    00058
    00059     if (--oldNode->refCount != 0) {
    00060         if (newNode)
    00061             ++newNode->refCount;
    00062     } else {
    00063         delete oldNode;
    00064     }
    00065 }
    00066
    00067 void ScopeChain::release()
    00068 {
    00069     // This function is only called by deref(),
    00070     // Deref ensures these conditions are true.
    00071     assert(_node && _node->refCount == 0);
    00072     ScopeChainNode *n = _node;
    00073     do {
    00074         ScopeChainNode *next = n->next;
    00075         delete n;
    00076         n = next;
    00077     } while (n && --n->refCount == 0);
    00078 }
    00079
    00080 void ScopeChain::mark()
    00081 {
    00082     for (ScopeChainNode *n = _node; n; n = n->next) {
    00083         ObjectImp *o = n->object;
    00084         if (!o->marked())
    00085             o->mark();
    00086     }
    00087 }
    00088
    00089 } // namespace KJS

This file is part of the documentation for kjs Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:07 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003