Gnash 0.8.9
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 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_PROPERTYLIST_H 00020 #define GNASH_PROPERTYLIST_H 00021 00022 #include <set> 00023 #include <map> 00024 #include <vector> 00025 #include <string> // for use within map 00026 #include <cassert> // for inlines 00027 #include <utility> // for std::pair 00028 #include <boost/cstdint.hpp> 00029 #include <boost/multi_index_container.hpp> 00030 #include <boost/multi_index/ordered_index.hpp> 00031 #include <boost/multi_index/sequenced_index.hpp> 00032 #include <boost/multi_index/key_extractors.hpp> 00033 #include <boost/noncopyable.hpp> 00034 #include <boost/bind.hpp> 00035 #include <algorithm> 00036 00037 #include "Property.h" // for templated functions 00038 00039 // Forward declaration 00040 namespace gnash { 00041 class as_object; 00042 class as_environment; 00043 class as_function; 00044 struct ObjectURI; 00045 class as_value; 00046 } 00047 00048 namespace gnash { 00049 00051 class PropertyVisitor { 00052 public: 00053 00055 virtual bool accept(const ObjectURI& uri, const as_value& val) = 0; 00056 virtual ~PropertyVisitor() {} 00057 }; 00058 00060 class KeyVisitor { 00061 public: 00062 00064 virtual void operator()(const ObjectURI& uri) = 0; 00065 virtual ~KeyVisitor() {} 00066 }; 00067 00068 00070 // 00074 // 00078 // 00083 class PropertyList : boost::noncopyable 00084 { 00085 public: 00086 00087 typedef std::set<ObjectURI, ObjectURI::LessThan> PropertyTracker; 00088 typedef Property value_type; 00089 00091 struct CreationOrder {}; 00092 00094 typedef boost::multi_index::sequenced< 00095 boost::multi_index::tag<CreationOrder> > SequencedIndex; 00096 00097 struct KeyExtractor 00098 { 00099 typedef const ObjectURI& result_type; 00100 result_type operator()(const Property& p) const { 00101 return p.uri(); 00102 } 00103 }; 00104 00106 struct Case {}; 00107 00109 typedef boost::multi_index::ordered_unique< 00110 boost::multi_index::tag<Case>, 00111 KeyExtractor, 00112 ObjectURI::LessThan> CaseIndex; 00113 00115 struct NoCase {}; 00116 00118 typedef boost::multi_index::ordered_non_unique< 00119 boost::multi_index::tag<NoCase>, 00120 KeyExtractor, 00121 ObjectURI::CaseLessThan> NoCaseIndex; 00122 00124 typedef boost::multi_index_container< 00125 value_type, 00126 boost::multi_index::indexed_by<SequencedIndex, CaseIndex, NoCaseIndex> 00127 > container; 00128 00129 typedef container::iterator iterator; 00130 typedef container::const_iterator const_iterator; 00131 00133 // 00135 PropertyList(as_object& obj); 00136 00138 // 00142 // 00147 // 00152 template <class U, class V> 00153 void visitValues(V& visitor, U cmp = U()) const { 00154 00155 for (const_iterator it = _props.begin(), ie = _props.end(); 00156 it != ie; ++it) { 00157 00158 if (!cmp(*it)) continue; 00159 as_value val = it->getValue(_owner); 00160 if (!visitor.accept(it->uri(), val)) return; 00161 } 00162 } 00163 00165 // 00173 void visitKeys(KeyVisitor& v, PropertyTracker& donelist) const; 00174 00176 // 00190 bool setValue(const ObjectURI& uri, const as_value& value, 00191 const PropFlags& flagsIfMissing = 0); 00192 00194 // 00199 Property* getProperty(const ObjectURI& uri) const; 00200 00202 // 00212 std::pair<bool,bool> delProperty(const ObjectURI& uri); 00213 00215 // 00217 // 00228 bool addGetterSetter(const ObjectURI& uri, as_function& getter, 00229 as_function* setter, const as_value& cacheVal, 00230 const PropFlags& flagsIfMissing = 0); 00231 00233 // 00240 bool addGetterSetter(const ObjectURI& uri, as_c_function_ptr getter, 00241 as_c_function_ptr setter, const PropFlags& flagsIfMissing); 00242 00244 // 00251 bool addDestructiveGetter(const ObjectURI& uri, as_function& getter, 00252 const PropFlags& flagsIfMissing = 0); 00253 00261 // one is created. 00264 bool addDestructiveGetter(const ObjectURI& uri, as_c_function_ptr getter, 00265 const PropFlags& flagsIfMissing = 0); 00266 00268 // 00272 void setFlags(const ObjectURI& uri, int setTrue, int setFalse); 00273 00275 // 00278 void setFlagsAll(int setTrue, int setFalse); 00279 00281 void clear(); 00282 00284 size_t size() const { 00285 return _props.size(); 00286 } 00287 00289 // 00292 void dump(); 00293 00295 // 00298 void setReachable() const { 00299 std::for_each(_props.begin(), _props.end(), 00300 boost::mem_fn(&Property::setReachable)); 00301 } 00302 00303 private: 00304 00305 container _props; 00306 00307 as_object& _owner; 00308 00309 }; 00310 00311 00312 } // namespace gnash 00313 00314 #endif // GNASH_PROPERTYLIST_H