object.h

来自「将konqueror浏览器移植到ARM9 2410中」· C头文件 代码 · 共 641 行 · 第 1/2 页

H
641
字号
/* *  This file is part of the KDE libraries *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org) * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public License *  along with this library; see the file COPYING.LIB.  If not, write to *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, *  Boston, MA 02111-1307, USA. */#ifndef _KJS_OBJECT_H_#define _KJS_OBJECT_H_#include <stdlib.h>#include "ustring.h"/** * @short Main namespace */namespace KJS {  /**   * Types of classes derived from KJSO   */  enum Type { // main types              AbstractType = 1,              UndefinedType,	      NullType,	      BooleanType,	      NumberType,	      StringType,	      ObjectType,	      HostType,	      ReferenceType,              CompletionType,	      // extended types	      FunctionType,	      InternalFunctionType,	      DeclaredFunctionType,	      AnonymousFunctionType,	      ConstructorType,	      ActivationType  };  /**   * Property attributes.   */  enum Attribute { None       = 0,		   ReadOnly   = 1 << 1,		   DontEnum   = 1 << 2,		   DontDelete = 1 << 3,		   Internal   = 1 << 4 };  /**   * Types of classes derived from @ref Object.   */  enum Class { UndefClass,	       ArrayClass,	       StringClass,	       BooleanClass,	       NumberClass,	       ObjectClass,	       DateClass,	       RegExpClass,	       ErrorClass,	       FunctionClass };  /**   * Completion types.   */  enum Compl { Normal, Break, Continue, ReturnValue, Throw };  /**   * Error codes.   */  enum ErrorType { NoError = 0,		   GeneralError,		   EvalError,		   RangeError,		   ReferenceError,		   SyntaxError,		   TypeError,		   URIError };  extern const double NaN;  extern const double Inf;  // forward declarations  class Imp;  class Boolean;  class Number;  class String;  class Object;  struct Property;  class PropList;  class List;  /**   * @short Type information.   */  struct TypeInfo {    /**     * A string denoting the type name. Example: "Number".     */    const char *name;    /**     * One of the @ref KJS::Type enums.     */    Type type;    /**     * Pointer to the type information of the base class.     * NULL if there is none.     */    const TypeInfo *base;    /**     * Additional specifier for your own use.     */    int extra;    /**     * Reserved for future extensions (internal).     */    void *dummy;  };  /**   * @short Main base class for every KJS object.   */  class KJSO {    friend class ElementNode;  public:    /**     * Constructor.     */    KJSO();    /**     * @internal     */    KJSO(Imp *d);    /**     * Copy constructor.     */    KJSO(const KJSO &);    /*     * Assignment operator     */    KJSO& operator=(const KJSO &);    /**     * Destructor.     */    virtual ~KJSO();    /**     * @return True if this object is null, i.e. if there is no data attached     * to this object. Don't confuse this with the Null object.     */    bool isNull() const;    /**     * @return True if this objects is of any other value than Undefined.     */    bool isDefined() const;    /**     * @return the type of the object. One of the @ref KJS::Type enums.     */    Type type() const;    /**     * Check whether object is of a certain type     * @param t type to check for     */    bool isA(Type t) const { return (type() == t); }    /**     * Check whether object is of a certain type. Allows checking of     * host objects, too.     * @param type name (Number, Boolean etc.)     */    bool isA(const char *s) const;    /**     * Use this method when checking for objects. It's safer than checking     * for a single object type with @ref isA().     */    bool isObject() const;    /**     * Examine the inheritance structure of this object.     * @param t Name of the base class.     * @return True if object is of type t or a derived from such a type.     */    bool derivedFrom(const char *s) const;    /**     * @return Conversion to primitive type (Undefined, Boolean, Number     * or String)     * @param preferred Optional hint. Either StringType or NumberType.     */    KJSO toPrimitive(Type preferred = UndefinedType) const; // ECMA 9.1    /**     * @return Conversion to Boolean type.     */    Boolean toBoolean() const; // ECMA 9.2    /**     * @return Conversion to Number type.     */    Number toNumber() const; // ECMA 9.3    /**     * @return Conversion to double. 0.0 if conversion failed.     */    double round() const;    /**     * @return Conversion to Number type containing an integer value.     */    Number toInteger() const; // ECMA 9.4    /**     * @return Conversion to signed integer value.     */    int toInt32() const; // ECMA 9.5    /**     * @return Conversion to unsigned integer value.     */    unsigned int toUInt32() const; // ECMA 9.6    /**     * @return Conversion to unsigned short value.     */    unsigned short toUInt16() const; // ECMA 9.7    /**     * @return Conversion to String type.     */    String toString() const; // ECMA 9.8    /**     * @return Conversion to Object type.     */    Object toObject() const; // ECMA 9.9    // Properties    /**     * Set the internal [[Prototype]] property of this object.     * @param p A prototype object.     */    void setPrototype(const KJSO &p);    /**     * Set the "prototype" property of this object. Different from     * the internal [[Prototype]] property.     * @param p A prototype object.     */    void setPrototypeProperty(const KJSO &p);    /**     * @return The internal [[prototype]] property.     */    KJSO prototype() const;    /**     * The internal [[Get]] method.     * @return The value of property p.     */    KJSO get(const UString &p) const;    /**     * The internal [[HasProperty]] method.     * @param p Property name.     * @param recursive Indicates whether prototypes are searched as well.     * @return Boolean value indicating whether the object already has a     * member with the given name p.     */    bool hasProperty(const UString &p, bool recursive = true) const;    /**     * The internal [[Put]] method. Sets the specified property to the value v.     * @param p Property name.     * @param v Value.     */    void put(const UString &p, const KJSO& v);    /**     * The internal [[CanPut]] method.     * @param p Property name.     * @return A boolean value indicating whether a [[Put]] operation with     * p succeed.     */    bool canPut(const UString &p) const;    /**     * The internal [[Delete]] method. Removes the specified property from     * the object.     * @param p Property name.     * @return True if the property was deleted successfully or didn't exist     * in the first place. False if the DontDelete attribute was set.     */    bool deleteProperty(const UString &p);    /**     * Same as above put() method except the additional attribute. Right now,     * this only works with native types as Host Objects don't reimplement     * this method.     * @param attr One of @ref KJS::Attribute.     */    void put(const UString &p, const KJSO& v, int attr);    /**     * Convenience function for adding a Number property constructed from     * a double value.     */    void put(const UString &p, double d, int attr = None);    /**     * Convenience function for adding a Number property constructed from     * an integer value.     */    void put(const UString &p, int i, int attr = None);    /**     * Convenience function for adding a Number property constructed from     * an unsigned integer value.     */    void put(const UString &p, unsigned int u, int attr = None);    /**     * Reference method.     * @return Reference base if object is a reference. Throws     * a ReferenceError otherwise.     */    KJSO getBase() const;    /**     * Reference method.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?