Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_PROPERTYLIST_H
00020 #define GNASH_PROPERTYLIST_H
00021
00022 #include "Property.h"
00023
00024 #include <set>
00025 #include <map>
00026 #include <string>
00027 #include <cassert>
00028 #include <utility>
00029 #include <boost/cstdint.hpp>
00030 #include <boost/multi_index_container.hpp>
00031 #include <boost/multi_index/ordered_index.hpp>
00032 #include <boost/multi_index/sequenced_index.hpp>
00033 #include <boost/multi_index/key_extractors.hpp>
00034 #include <boost/noncopyable.hpp>
00035
00036
00037 namespace gnash {
00038 class as_object;
00039 class as_environment;
00040 class as_function;
00041 struct ObjectURI;
00042 class as_value;
00043 }
00044
00045 namespace gnash {
00046
00048
00052
00056
00061 class PropertyList : boost::noncopyable
00062 {
00063
00064 public:
00065
00066 typedef std::set<ObjectURI> PropertyTracker;
00067 typedef std::pair<Property, string_table::key> value_type;
00068
00069 struct NameExtractor
00070 {
00071 typedef ObjectURI result_type;
00072 const result_type& operator()(const value_type& r) const {
00073 return r.first.uri();
00074 }
00075 const result_type& operator()(value_type& r) {
00076 return r.first.uri();
00077 }
00078 };
00079
00080 typedef boost::multi_index::member<value_type, value_type::second_type,
00081 &value_type::second> KeyExtractor;
00082
00083 typedef boost::multi_index_container<
00084 value_type,
00085 boost::multi_index::indexed_by<
00086 boost::multi_index::sequenced<>,
00087 boost::multi_index::ordered_unique<NameExtractor>,
00088 boost::multi_index::ordered_non_unique<KeyExtractor>
00089 >
00090 > container;
00091 typedef container::iterator iterator;
00092 typedef container::const_iterator const_iterator;
00093
00095
00099 PropertyList(as_object& obj)
00100 :
00101 _props(),
00102 _owner(obj)
00103 {
00104 }
00105
00107
00111
00116
00121 template <class U, class V>
00122 void visitValues(V& visitor, U cmp = U()) const
00123 {
00124
00125
00126
00127 for (const_iterator it = _props.begin(), ie = _props.end();
00128 it != ie; ++it)
00129 {
00130 if (!cmp(it->first)) continue;
00131 as_value val = it->first.getValue(_owner);
00132 if (!visitor.accept(it->first.uri(), val)) return;
00133 }
00134 }
00135
00137
00145 void enumerateKeys(as_environment& env, PropertyTracker& donelist) const;
00146
00148
00165 bool setValue(const ObjectURI& uri, const as_value& value,
00166 const PropFlags& flagsIfMissing = 0);
00167
00169
00175 Property* getProperty(const ObjectURI& uri) const;
00176
00178
00189 std::pair<bool,bool> delProperty(const ObjectURI& uri);
00190
00192
00194
00205 bool addGetterSetter(const ObjectURI& uri, as_function& getter,
00206 as_function* setter, const as_value& cacheVal,
00207 const PropFlags& flagsIfMissing = 0);
00208
00210
00217 bool addGetterSetter(const ObjectURI& uri, as_c_function_ptr getter,
00218 as_c_function_ptr setter, const PropFlags& flagsIfMissing);
00219
00221
00228 bool addDestructiveGetter(const ObjectURI& uri, as_function& getter,
00229 const PropFlags& flagsIfMissing = 0);
00230
00238
00241 bool addDestructiveGetter(const ObjectURI& uri, as_c_function_ptr getter,
00242 const PropFlags& flagsIfMissing = 0);
00243
00245
00249 void setFlags(const ObjectURI& uri, int setTrue, int setFalse);
00250
00252
00255 void setFlagsAll(int setTrue, int setFalse);
00256
00258 void clear();
00259
00261 size_t size() const {
00262 return _props.size();
00263 }
00264
00266
00269 void dump();
00270
00272
00276 void dump(std::map<std::string, as_value>& to);
00277
00280 void setReachable() const;
00281
00282 private:
00283
00284 container _props;
00285
00286 as_object& _owner;
00287
00288 };
00289
00290
00291 }
00292
00293 #endif // GNASH_PROPERTYLIST_H