1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2004 Apple Computer, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #ifndef _KJS_PROTECT_H_
25 #define _KJS_PROTECT_H_
28 #include "reference.h"
30 #include "protected_values.h"
34 inline void gcProtect(ValueImp *val)
36 #if TEST_CONSERVATIVE_GC | USE_CONSERVATIVE_GC
37 ProtectedValues::increaseProtectCount(val);
40 inline void gcUnprotect(ValueImp *val)
42 #if TEST_CONSERVATIVE_GC | USE_CONSERVATIVE_GC
43 ProtectedValues::decreaseProtectCount(val);
47 inline void gcProtectNullTolerant(ValueImp *val)
49 if (val) gcProtect(val);
52 inline void gcUnprotectNullTolerant(ValueImp *val)
54 if (val) gcUnprotect(val);
58 class ProtectedValue : public Value {
60 ProtectedValue() : Value() {}
61 ProtectedValue(const Value&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
62 ProtectedValue(const ProtectedValue&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
63 ~ProtectedValue() { gcUnprotectNullTolerant(imp());}
64 ProtectedValue& operator=(const Value &v)
66 ValueImp *old = imp();
68 gcProtectNullTolerant(v.imp());
69 gcUnprotectNullTolerant(old);
72 ProtectedValue& operator=(const ProtectedValue &v)
74 ValueImp *old = imp();
76 gcProtectNullTolerant(v.imp());
77 gcUnprotectNullTolerant(old);
81 explicit ProtectedValue(ValueImp *v);
85 class ProtectedObject : public Object {
87 ProtectedObject() : Object() {}
88 ProtectedObject(const Object &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
89 ProtectedObject(const ProtectedObject &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
90 ~ProtectedObject() { gcUnprotectNullTolerant(imp());}
91 ProtectedObject& operator=(const Object &o)
93 ValueImp *old = imp();
95 gcProtectNullTolerant(o.imp());
96 gcUnprotectNullTolerant(old);
99 ProtectedObject& operator=(const ProtectedObject &o)
101 ValueImp *old = imp();
102 Object::operator=(o);
103 gcProtectNullTolerant(o.imp());
104 gcUnprotectNullTolerant(old);
108 explicit ProtectedObject(ObjectImp *o);
112 class ProtectedReference : public Reference {
114 ProtectedReference(const Reference&r) : Reference(r) { gcProtectNullTolerant(r.base.imp()); };
115 ~ProtectedReference() { gcUnprotectNullTolerant(base.imp());}
116 ProtectedReference& operator=(const Reference &r)
118 ValueImp *old = base.imp();
119 Reference::operator=(r);
120 gcProtectNullTolerant(r.base.imp());
121 gcUnprotectNullTolerant(old);
125 ProtectedReference();
126 ProtectedReference(const Object& b, const Identifier& p);
127 ProtectedReference(const Object& b, unsigned p);
128 ProtectedReference(ObjectImp *b, const Identifier& p);
129 ProtectedReference(ObjectImp *b, unsigned p);
130 ProtectedReference(const Null& b, const Identifier& p);
131 ProtectedReference(const Null& b, unsigned p);