File indexing completed on 2024-10-06 09:37:06

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2013 Bernd Buschinski <b.buschinski@googlemail.com>
0004  *
0005  *  This library is free software; you can redistribute it and/or
0006  *  modify it under the terms of the GNU Lesser General Public
0007  *  License as published by the Free Software Foundation; either
0008  *  version 2 of the License, or (at your option) any later version.
0009  *
0010  *  This library is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  *  Lesser General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU Lesser General Public
0016  *  License along with this library; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef KJS_ARRAYTYPES_H
0021 #define KJS_ARRAYTYPES_H
0022 
0023 #include "kjs_arraybufferview.h"
0024 
0025 namespace KJS
0026 {
0027 
0028 // Declare a TypedArray Class, type == the type, for example int8_t
0029 // and TypeName is a readable name for the Type, for example Int8.
0030 // Use this Macro to declare all typed arrays types.
0031 
0032 #define KJS_TYPEDARRAY_DECLARE(type,TypeName) \
0033     class ArrayBufferViewProto##TypeName; \
0034     class ArrayBufferView##TypeName : public ArrayBufferView<type, ArrayBufferViewProto##TypeName> { \
0035     public: \
0036         explicit ArrayBufferView##TypeName(ExecState* exec, ArrayBuffer* buffer, size_t byteOffset, size_t byteLength); \
0037         virtual ~ArrayBufferView##TypeName() {}; \
0038         \
0039         static const ClassInfo info; \
0040         virtual const ClassInfo* classInfo() const { return &info; } \
0041     }; \
0042     \
0043     class ArrayBufferConstructorImp##TypeName : public ArrayBufferViewConstructorImp<type, ArrayBufferView##TypeName> \
0044     { \
0045     public: \
0046         ArrayBufferConstructorImp##TypeName(ExecState *exec, DOM::DocumentImpl* d) \
0047             : ArrayBufferViewConstructorImp<type, ArrayBufferView##TypeName>(exec, d) \
0048         { } \
0049         using KJS::JSObject::construct; \
0050         virtual JSObject* construct(ExecState *exec, const List &args); \
0051     }; \
0052     \
0053     class ArrayBufferViewProto##TypeName : public ArrayBufferViewProto<type, ArrayBufferView##TypeName> \
0054     { \
0055         friend KJS::JSObject* KJS_CACHEGLOBALOBJECT_NS cacheGlobalObject<ArrayBufferViewProto##TypeName>(KJS::ExecState *exec, const KJS::Identifier &propertyName); \
0056     public: \
0057         virtual const KJS::ClassInfo *classInfo() const { return &info; } \
0058         static const KJS::ClassInfo info; \
0059         static KJS::JSObject *self(KJS::ExecState *exec); \
0060     protected: \
0061         ArrayBufferViewProto##TypeName(KJS::ExecState *exec); \
0062         static KJS::Identifier* s_name; \
0063         static KJS::Identifier* name(); \
0064     };
0065 
0066 KJS_TYPEDARRAY_DECLARE(int8_t, Int8)
0067 KJS_TYPEDARRAY_DECLARE(uint8_t, Uint8)
0068 KJS_TYPEDARRAY_DECLARE(int16_t, Int16)
0069 KJS_TYPEDARRAY_DECLARE(uint16_t, Uint16)
0070 KJS_TYPEDARRAY_DECLARE(int32_t, Int32)
0071 KJS_TYPEDARRAY_DECLARE(uint32_t, Uint32)
0072 
0073 KJS_TYPEDARRAY_DECLARE(float, Float32)
0074 KJS_TYPEDARRAY_DECLARE(double, Float64)
0075 
0076 #undef KJS_TYPEDARRAY_DECLARE
0077 
0078 }
0079 
0080 #endif //KJS_ARRAYTYPES_H