property_map.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2003 Apple Computer, Inc.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef _KJS_PROPERTY_MAP_H_
00024 #define _KJS_PROPERTY_MAP_H_
00025 
00026 #include "identifier.h"
00027 
00028 namespace KJS {
00029 
00030     class Object;
00031     class ReferenceList;
00032     class ValueImp;
00033     
00034     class SavedProperty;
00035     
00036     struct PropertyMapHashTable;
00037     
00041     class SavedProperties {
00042     friend class PropertyMap;
00043     public:
00044         SavedProperties();
00045         ~SavedProperties();
00046         
00047     private:
00048         int _count;
00049         SavedProperty *_properties;
00050         
00051         SavedProperties(const SavedProperties&);
00052         SavedProperties& operator=(const SavedProperties&);
00053     };
00054     
00058     struct PropertyMapHashTableEntry
00059     {
00060         PropertyMapHashTableEntry() : key(0) { }
00061         UString::Rep *key;
00062         ValueImp *value;
00063         int attributes;
00064     };
00069     class KJS_EXPORT PropertyMap {
00070     public:
00071         PropertyMap();
00072         ~PropertyMap();
00073 
00074         void clear();
00075         
00076         void put(const Identifier &name, ValueImp *value, int attributes);
00077         void remove(const Identifier &name);
00078         ValueImp *get(const Identifier &name) const;
00079         ValueImp *get(const Identifier &name, int &attributes) const;
00080 
00081         void mark() const;
00082         void addEnumerablesToReferenceList(ReferenceList &, const Object &) const;
00083     void addSparseArrayPropertiesToReferenceList(ReferenceList &, const Object &) const;
00084 
00085         void save(SavedProperties &) const;
00086         void restore(const SavedProperties &p);
00087 
00088     private:
00089         int hash(const UString::Rep *) const;
00090         static bool keysMatch(const UString::Rep *, const UString::Rep *);
00091         void expand();
00092         
00093         void insert(UString::Rep *, ValueImp *value, int attributes);
00094         
00095         void checkConsistency();
00096         
00097         typedef PropertyMapHashTableEntry Entry;
00098         typedef PropertyMapHashTable Table;
00099 
00100         Table *_table;
00101         
00102         Entry _singleEntry;
00103     };
00104 
00105 } // namespace
00106 
00107 #endif // _KJS_PROPERTY_MAP_H_
KDE Home | KDE Accessibility Home | Description of Access Keys