home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kjs / identifier.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  5.0 KB  |  156 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (C) 2003 Apple Computer, Inc
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public License
  16.  *  along with this library; see the file COPYING.LIB.  If not, write to
  17.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  *  Boston, MA 02110-1301, USA.
  19.  *
  20.  */
  21.  
  22. #ifndef KJS_IDENTIFIER_H
  23. #define KJS_IDENTIFIER_H
  24.  
  25. #include "ustring.h"
  26.  
  27. namespace KJS {
  28.  
  29.   /**
  30.    * Represents an Identifier for a Javascript object.
  31.    */
  32.     class KJS_EXPORT Identifier {
  33.         friend class PropertyMap;
  34.     public:
  35.     /** 
  36.     * Creates an empty identifier
  37.     */
  38.         Identifier() { }
  39.     /**
  40.     * Creates an identifier with the name of the string 
  41.     * @code
  42.     * KJS::Identifier method("someJSMethod");
  43.     * @endcode
  44.     */
  45.         Identifier(const char *s) : _ustring(add(s)) { }
  46.         Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
  47.         explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
  48.  
  49.     /**
  50.     * returns a UString of the identifier
  51.     */
  52.         const UString &ustring() const { return _ustring; }
  53.         DOM::DOMString string() const;
  54.         /**
  55.     * returns a QString of the identifier
  56.     */
  57.     QString qstring() const;
  58.  
  59.     /**
  60.     * returns a UChar pointer to the string of the identifier with a size defined by @ref size().
  61.     */
  62.         const UChar *data() const { return _ustring.data(); }
  63.     /**
  64.     * The size of the UChar string returned.
  65.     */
  66.         int size() const { return _ustring.size(); }
  67.  
  68.     /**
  69.     * Char * of the identifier's string.
  70.     */
  71.         const char *ascii() const { return _ustring.ascii(); }
  72.  
  73.         static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
  74.  
  75.     /**
  76.     * Returns the identfiers state of being unset.
  77.     */
  78.         bool isNull() const { return _ustring.isNull(); }
  79.     /**
  80.     * Returns that the identifiers string is set, but is empty.
  81.     */
  82.         bool isEmpty() const { return _ustring.isEmpty(); }
  83.  
  84.         unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }
  85.         unsigned toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
  86.         unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
  87.  
  88.         double toDouble() const { return _ustring.toDouble(); }
  89.  
  90.     /**
  91.     * Creates an empty Identifier
  92.     */
  93.         static const Identifier &null();
  94.  
  95.         friend bool operator==(const Identifier &, const Identifier &);
  96.         friend bool operator!=(const Identifier &, const Identifier &);
  97.  
  98.         friend bool operator==(const Identifier &, const char *);
  99.  
  100.         static void remove(UString::Rep *);
  101.  
  102.     private:
  103.         UString _ustring;
  104.  
  105.         static bool equal(UString::Rep *, const char *);
  106.         static bool equal(UString::Rep *, const UChar *, int length);
  107.         static bool equal(UString::Rep *, UString::Rep *);
  108.  
  109.         static bool equal(const Identifier &a, const Identifier &b)
  110.             { return a._ustring.rep == b._ustring.rep; }
  111.         static bool equal(const Identifier &a, const char *b)
  112.             { return equal(a._ustring.rep, b); }
  113.  
  114.         static UString::Rep *add(const char *);
  115.         static UString::Rep *add(const UChar *, int length);
  116.         static UString::Rep *add(UString::Rep *);
  117.  
  118.         static void insert(UString::Rep *);
  119.  
  120.         static void rehash(int newTableSize);
  121.         static void expand();
  122.         static void shrink();
  123.  
  124.     // TODO: move into .cpp file
  125.         static UString::Rep **_table;
  126.         static int _tableSize;
  127.         static int _tableSizeMask;
  128.         static int _keyCount;
  129.     };
  130.  
  131.     inline bool operator==(const Identifier &a, const Identifier &b)
  132.         { return Identifier::equal(a, b); }
  133.  
  134.     inline bool operator!=(const Identifier &a, const Identifier &b)
  135.         { return !Identifier::equal(a, b); }
  136.  
  137.     inline bool operator==(const Identifier &a, const char *b)
  138.         { return Identifier::equal(a, b); }
  139.  
  140.     KJS_EXPORT extern const Identifier argumentsPropertyName;
  141.     KJS_EXPORT extern const Identifier calleePropertyName;
  142.     KJS_EXPORT extern const Identifier callerPropertyName;
  143.     KJS_EXPORT extern const Identifier constructorPropertyName;
  144.     KJS_EXPORT extern const Identifier lengthPropertyName;
  145.     KJS_EXPORT extern const Identifier messagePropertyName;
  146.     KJS_EXPORT extern const Identifier namePropertyName;
  147.     KJS_EXPORT extern const Identifier prototypePropertyName;
  148.     KJS_EXPORT extern const Identifier specialPrototypePropertyName;
  149.     KJS_EXPORT extern const Identifier toLocaleStringPropertyName;
  150.     KJS_EXPORT extern const Identifier toStringPropertyName;
  151.     KJS_EXPORT extern const Identifier valueOfPropertyName;
  152.  
  153. }
  154.  
  155. #endif
  156.