Gnash  0.8.10
Array_as.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program 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
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_ARRAY_H
00020 #define GNASH_ARRAY_H
00021 
00022 #include "as_object.h" 
00023 
00024 // Forward declarations
00025 namespace gnash {
00026         class as_value;
00027 }
00028 
00029 namespace gnash {
00030 
00032 //
00035 //
00039 size_t arrayLength(as_object& array);
00040 
00042 //
00045 //
00048 ObjectURI arrayKey(VM& vm, size_t i);
00049 
00051 //
00054 class IsStrictArray : public PropertyVisitor
00055 {
00056 public:
00057     IsStrictArray(VM& st) : _strict(true), _st(st) {}
00058     virtual bool accept(const ObjectURI& uri, const as_value& val);
00059 
00060     bool strict() const {
00061         return _strict;
00062     }
00063 private:
00064     bool _strict;
00065     VM& _st;
00066 };
00067 
00068 
00070 //
00074 void checkArrayLength(as_object& array, const ObjectURI& uri,
00075         const as_value& val);
00076 
00077 template<typename T>
00078 void foreachArray(as_object& array, T& pred)
00079 {
00080     size_t size = arrayLength(array);
00081     if (!size) return;
00082 
00083     VM& vm = getVM(array);
00084 
00085     for (size_t i = 0; i < static_cast<size_t>(size); ++i) {
00086         pred(getOwnProperty(array, arrayKey(vm, i)));
00087     }
00088 }
00089 
00091 void array_class_init(as_object& global, const ObjectURI& uri);
00092 
00093 void registerArrayNative(as_object& global);
00094 
00095 }
00096 
00097 #endif