-fix remaining regressions in background images painting.
[kdelibs.git] / kjs / property_map.h
blob2ae8a056776b0a73982a4f6d53e4b4e5bf10eb63
1 // -*- c-basic-offset: 2 -*-
2 /*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef KJS_PROPERTY_MAP_H_
24 #define KJS_PROPERTY_MAP_H_
26 #include "identifier.h"
27 #include <kxmlcore/OwnArrayPtr.h>
29 namespace KJS {
31 class PropertyNameArray;
32 class JSObject;
33 class JSValue;
35 class SavedProperty;
37 struct PropertyMapHashTable;
39 /**
40 * Saved Properties
42 class SavedProperties {
43 friend class PropertyMap;
44 public:
45 SavedProperties();
46 ~SavedProperties();
48 private:
49 int _count;
50 OwnArrayPtr<SavedProperty> _properties;
53 /**
54 * A hashtable entry for the @ref PropertyMap.
56 struct PropertyMapHashTableEntry
58 PropertyMapHashTableEntry() : key(0) { }
59 UString::Rep *key;
60 JSValue *value;
61 short attributes;
62 short globalGetterSetterFlag;
63 int index;
66 /**
67 * Javascript Property Map.
69 class KJS_EXPORT PropertyMap {
70 public:
71 PropertyMap();
72 ~PropertyMap();
74 void clear();
76 void put(const Identifier &name, JSValue *value, int attributes, bool roCheck = false);
77 void remove(const Identifier &name);
78 JSValue *get(const Identifier &name) const;
79 JSValue *get(const Identifier &name, unsigned &attributes) const;
80 JSValue **getLocation(const Identifier &name);
82 void mark() const;
83 void getEnumerablePropertyNames(PropertyNameArray&) const;
84 void getSparseArrayPropertyNames(PropertyNameArray&) const;
86 void save(SavedProperties &) const;
87 void restore(const SavedProperties &p);
89 bool isEmpty() const;
91 bool hasGetterSetterProperties() const { return (_singleEntry.globalGetterSetterFlag != 0); }
92 void setHasGetterSetterProperties(bool f) { _singleEntry.globalGetterSetterFlag = f; }
94 bool containsGettersOrSetters() const;
95 private:
96 static bool keysMatch(const UString::Rep *, const UString::Rep *);
97 void expand();
98 void rehash();
99 void rehash(int newTableSize);
101 void insert(UString::Rep *, JSValue *value, int attributes, int index);
103 void checkConsistency();
105 typedef PropertyMapHashTableEntry Entry;
106 typedef PropertyMapHashTable Table;
108 Table *_table;
110 Entry _singleEntry;
113 inline PropertyMap::PropertyMap() : _table(0)
115 _singleEntry.globalGetterSetterFlag = 0;
118 } // namespace
120 #endif // _KJS_PROPERTY_MAP_H_