kjs Library API Documentation

identifier.h

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 #ifndef KJS_IDENTIFIER_H
00023 #define KJS_IDENTIFIER_H
00024 
00025 #include "ustring.h"
00026 
00027 namespace KJS {
00028 
00029     class Identifier {
00030         friend class PropertyMap;
00031     public:
00032         Identifier() { }
00033         Identifier(const char *s) : _ustring(add(s)) { }
00034         Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
00035         explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
00036 
00037         const UString &ustring() const { return _ustring; }
00038         DOM::DOMString string() const;
00039         QString qstring() const;
00040 
00041         const UChar *data() const { return _ustring.data(); }
00042         int size() const { return _ustring.size(); }
00043 
00044         const char *ascii() const { return _ustring.ascii(); }
00045 
00046         static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
00047 
00048         bool isNull() const { return _ustring.isNull(); }
00049         bool isEmpty() const { return _ustring.isEmpty(); }
00050 
00051         unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }
00052         unsigned toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
00053         unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
00054 
00055         double toDouble() const { return _ustring.toDouble(); }
00056 
00057         static const Identifier &null();
00058 
00059         friend bool operator==(const Identifier &, const Identifier &);
00060         friend bool operator!=(const Identifier &, const Identifier &);
00061 
00062         friend bool operator==(const Identifier &, const char *);
00063 
00064         static void remove(UString::Rep *);
00065 
00066     private:
00067         UString _ustring;
00068 
00069         static bool equal(UString::Rep *, const char *);
00070         static bool equal(UString::Rep *, const UChar *, int length);
00071         static bool equal(UString::Rep *, UString::Rep *);
00072 
00073         static bool equal(const Identifier &a, const Identifier &b)
00074             { return a._ustring.rep == b._ustring.rep; }
00075         static bool equal(const Identifier &a, const char *b)
00076             { return equal(a._ustring.rep, b); }
00077 
00078         static UString::Rep *add(const char *);
00079         static UString::Rep *add(const UChar *, int length);
00080         static UString::Rep *add(UString::Rep *);
00081 
00082         static void insert(UString::Rep *);
00083 
00084         static void rehash(int newTableSize);
00085         static void expand();
00086         static void shrink();
00087 
00088     // TODO: move into .cpp file
00089         static UString::Rep **_table;
00090         static int _tableSize;
00091         static int _tableSizeMask;
00092         static int _keyCount;
00093     };
00094 
00095     inline bool operator==(const Identifier &a, const Identifier &b)
00096         { return Identifier::equal(a, b); }
00097 
00098     inline bool operator!=(const Identifier &a, const Identifier &b)
00099         { return !Identifier::equal(a, b); }
00100 
00101     inline bool operator==(const Identifier &a, const char *b)
00102         { return Identifier::equal(a, b); }
00103 
00104     extern const Identifier argumentsPropertyName;
00105     extern const Identifier calleePropertyName;
00106     extern const Identifier constructorPropertyName;
00107     extern const Identifier lengthPropertyName;
00108     extern const Identifier messagePropertyName;
00109     extern const Identifier namePropertyName;
00110     extern const Identifier prototypePropertyName;
00111     extern const Identifier specialPrototypePropertyName;
00112     extern const Identifier toLocaleStringPropertyName;
00113     extern const Identifier toStringPropertyName;
00114     extern const Identifier valueOfPropertyName;
00115 
00116 }
00117 
00118 #endif
KDE Logo
This file is part of the documentation for kjs Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:43:30 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003