1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 2004 Apple Computer, Inc.
|
---|
5 | *
|
---|
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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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.
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | #ifndef _KJS_PROTECT_H_
|
---|
25 | #define _KJS_PROTECT_H_
|
---|
26 |
|
---|
27 | #include "object.h"
|
---|
28 | #include "reference.h"
|
---|
29 | #include "value.h"
|
---|
30 | #include "protected_values.h"
|
---|
31 |
|
---|
32 | namespace KJS {
|
---|
33 |
|
---|
34 | inline void gcProtect(ValueImp *val)
|
---|
35 | {
|
---|
36 | ProtectedValues::increaseProtectCount(val);
|
---|
37 | }
|
---|
38 | inline void gcUnprotect(ValueImp *val)
|
---|
39 | {
|
---|
40 | ProtectedValues::decreaseProtectCount(val);
|
---|
41 | }
|
---|
42 |
|
---|
43 | inline void gcProtectNullTolerant(ValueImp *val)
|
---|
44 | {
|
---|
45 | if (val) gcProtect(val);
|
---|
46 | }
|
---|
47 |
|
---|
48 | inline void gcUnprotectNullTolerant(ValueImp *val)
|
---|
49 | {
|
---|
50 | if (val) gcUnprotect(val);
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | class ProtectedValue : public Value {
|
---|
55 | public:
|
---|
56 | ProtectedValue() : Value() {}
|
---|
57 | ProtectedValue(const Value&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
|
---|
58 | ProtectedValue(const ProtectedValue&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
|
---|
59 | ~ProtectedValue() { gcUnprotectNullTolerant(imp());}
|
---|
60 | ProtectedValue& operator=(const Value &v)
|
---|
61 | {
|
---|
62 | ValueImp *old = imp();
|
---|
63 | Value::operator=(v);
|
---|
64 | gcProtectNullTolerant(v.imp());
|
---|
65 | gcUnprotectNullTolerant(old);
|
---|
66 | return *this;
|
---|
67 | }
|
---|
68 | ProtectedValue& operator=(const ProtectedValue &v)
|
---|
69 | {
|
---|
70 | ValueImp *old = imp();
|
---|
71 | Value::operator=(v);
|
---|
72 | gcProtectNullTolerant(v.imp());
|
---|
73 | gcUnprotectNullTolerant(old);
|
---|
74 | return *this;
|
---|
75 | }
|
---|
76 | private:
|
---|
77 | explicit ProtectedValue(ValueImp *v);
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 | class ProtectedObject : public Object {
|
---|
82 | public:
|
---|
83 | ProtectedObject() : Object() {}
|
---|
84 | ProtectedObject(const Object &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
|
---|
85 | ProtectedObject(const ProtectedObject &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
|
---|
86 | ~ProtectedObject() { gcUnprotectNullTolerant(imp());}
|
---|
87 | ProtectedObject& operator=(const Object &o)
|
---|
88 | {
|
---|
89 | ValueImp *old = imp();
|
---|
90 | Object::operator=(o);
|
---|
91 | gcProtectNullTolerant(o.imp());
|
---|
92 | gcUnprotectNullTolerant(old);
|
---|
93 | return *this;
|
---|
94 | }
|
---|
95 | ProtectedObject& operator=(const ProtectedObject &o)
|
---|
96 | {
|
---|
97 | ValueImp *old = imp();
|
---|
98 | Object::operator=(o);
|
---|
99 | gcProtectNullTolerant(o.imp());
|
---|
100 | gcUnprotectNullTolerant(old);
|
---|
101 | return *this;
|
---|
102 | }
|
---|
103 | private:
|
---|
104 | explicit ProtectedObject(ObjectImp *o);
|
---|
105 | };
|
---|
106 |
|
---|
107 |
|
---|
108 | class ProtectedReference : public Reference {
|
---|
109 | public:
|
---|
110 | ProtectedReference(const Reference&r) : Reference(r) { gcProtectNullTolerant(r.base.imp()); };
|
---|
111 | ~ProtectedReference() { gcUnprotectNullTolerant(base.imp());}
|
---|
112 | ProtectedReference& operator=(const Reference &r)
|
---|
113 | {
|
---|
114 | ValueImp *old = base.imp();
|
---|
115 | Reference::operator=(r);
|
---|
116 | gcProtectNullTolerant(r.base.imp());
|
---|
117 | gcUnprotectNullTolerant(old);
|
---|
118 | return *this;
|
---|
119 | }
|
---|
120 | private:
|
---|
121 | ProtectedReference();
|
---|
122 | ProtectedReference(const Object& b, const Identifier& p);
|
---|
123 | ProtectedReference(const Object& b, unsigned p);
|
---|
124 | ProtectedReference(ObjectImp *b, const Identifier& p);
|
---|
125 | ProtectedReference(ObjectImp *b, unsigned p);
|
---|
126 | ProtectedReference(const Null& b, const Identifier& p);
|
---|
127 | ProtectedReference(const Null& b, unsigned p);
|
---|
128 | };
|
---|
129 |
|
---|
130 | }
|
---|
131 |
|
---|
132 | #endif
|
---|