Gnash  0.8.11dev
PropertyList.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_PROPERTYLIST_H
20 #define GNASH_PROPERTYLIST_H
21 
22 #include <set>
23 #include <string> // for use within map
24 #include <cassert> // for inlines
25 #include <utility> // for std::pair
26 #include <cstdint>
27 #include <boost/multi_index_container.hpp>
28 #include <boost/multi_index/ordered_index.hpp>
29 #include <boost/multi_index/sequenced_index.hpp>
30 #include <boost/multi_index/key_extractors.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <functional>
33 #include <algorithm>
34 
35 #include "Property.h" // for templated functions
36 #include "dsodefs.h" // for DSOTEXPORT
37 
38 // Forward declaration
39 namespace gnash {
40  class as_object;
41  class as_function;
42  struct ObjectURI;
43  class as_value;
44 }
45 
46 namespace gnash {
47 
50 public:
51 
53  virtual bool accept(const ObjectURI& uri, const as_value& val) = 0;
54  virtual ~PropertyVisitor() {}
55 };
56 
58 class KeyVisitor {
59 public:
60 
62  virtual void operator()(const ObjectURI& uri) = 0;
63  virtual ~KeyVisitor() {}
64 };
65 
66 
68 //
72 //
76 //
81 class PropertyList : boost::noncopyable
82 {
83 public:
84 
85  typedef std::set<ObjectURI, ObjectURI::LessThan> PropertyTracker;
87 
89  struct CreationOrder {};
90 
92  typedef boost::multi_index::sequenced<
93  boost::multi_index::tag<CreationOrder> > SequencedIndex;
94 
95  struct KeyExtractor
96  {
97  typedef const ObjectURI& result_type;
98  result_type operator()(const Property& p) const {
99  return p.uri();
100  }
101  };
102 
104  struct Case {};
105 
107  typedef boost::multi_index::ordered_unique<
108  boost::multi_index::tag<Case>,
109  KeyExtractor,
111 
113  struct NoCase {};
114 
116  typedef boost::multi_index::ordered_non_unique<
117  boost::multi_index::tag<NoCase>,
118  KeyExtractor,
120 
122  typedef boost::multi_index_container<
123  value_type,
124  boost::multi_index::indexed_by<SequencedIndex, CaseIndex, NoCaseIndex>
126 
127  typedef container::iterator iterator;
128  typedef container::const_iterator const_iterator;
129 
131  //
134 
136  //
140  //
145  //
150  template <class U, class V>
151  void visitValues(V& visitor, U cmp = U()) const {
152 
153  for (const auto& prop : _props) {
154 
155  if (!cmp(prop)) continue;
156  as_value val = prop.getValue(_owner);
157  if (!visitor.accept(prop.uri(), val)) return;
158  }
159  }
160 
162  //
170  void visitKeys(KeyVisitor& v, PropertyTracker& donelist) const;
171 
173  //
187  DSOTEXPORT bool setValue(const ObjectURI& uri, const as_value& value,
188  const PropFlags& flagsIfMissing = 0);
189 
191  //
196  DSOTEXPORT Property* getProperty(const ObjectURI& uri) const;
197 
199  //
209  DSOTEXPORT std::pair<bool,bool> delProperty(const ObjectURI& uri);
210 
212  //
214  //
225  bool addGetterSetter(const ObjectURI& uri, as_function& getter,
226  as_function* setter, const as_value& cacheVal,
227  const PropFlags& flagsIfMissing = 0);
228 
230  //
237  bool addGetterSetter(const ObjectURI& uri, as_c_function_ptr getter,
238  as_c_function_ptr setter, const PropFlags& flagsIfMissing);
239 
241  //
248  bool addDestructiveGetter(const ObjectURI& uri, as_function& getter,
249  const PropFlags& flagsIfMissing = 0);
250 
258  // one is created.
261  bool addDestructiveGetter(const ObjectURI& uri, as_c_function_ptr getter,
262  const PropFlags& flagsIfMissing = 0);
263 
265  //
269  DSOTEXPORT void setFlags(const ObjectURI& uri, int setTrue, int setFalse);
270 
272  //
275  void setFlagsAll(int setTrue, int setFalse);
276 
278  void clear();
279 
281  size_t size() const {
282  return _props.size();
283  }
284 
286  //
289  void dump();
290 
292  //
295  void setReachable() const {
296  std::for_each(_props.begin(), _props.end(),
297  std::mem_fn(&Property::setReachable));
298  }
299 
300 private:
301 
302  container _props;
303 
304  as_object& _owner;
305 
306 };
307 
308 
309 } // namespace gnash
310 
311 #endif // GNASH_PROPERTYLIST_H
size_t size() const
Return number of properties in this list.
Definition: PropertyList.h:281
void visitValues(V &visitor, U cmp=U()) const
Visit properties.
Definition: PropertyList.h:151
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
const ObjectURI & result_type
Definition: PropertyList.h:97
virtual ~KeyVisitor()
Definition: PropertyList.h:63
ActionScript value type.
Definition: as_value.h:94
An abstract property.
Definition: Property.h:276
void clear()
Clean up the font library.
Definition: fontlib.cpp:36
virtual ~PropertyVisitor()
Definition: PropertyList.h:54
Definition: PropertyList.h:95
uri
Definition: test.py:12
v
Definition: test.py:11
Flags defining the level of protection of a member.
Definition: PropFlags.h:28
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setReachable() const
Mark this property as being reachable (for the GC)
Definition: Property.h:390
as_value(* as_c_function_ptr)(const fn_call &fn)
Definition: Property.h:34
The base class for all ActionScript objects.
Definition: as_object.h:161
A URI for describing as_objects.
Definition: ObjectURI.h:44
container::const_iterator const_iterator
Definition: PropertyList.h:128
boost::multi_index::ordered_unique< boost::multi_index::tag< Case >, KeyExtractor, ObjectURI::LessThan > CaseIndex
The case-sensitive index.
Definition: PropertyList.h:110
boost::multi_index::sequenced< boost::multi_index::tag< CreationOrder > > SequencedIndex
The sequenced index in creation order.
Definition: PropertyList.h:93
An abstract property visitor.
Definition: PropertyList.h:49
boost::multi_index_container< value_type, boost::multi_index::indexed_by< SequencedIndex, CaseIndex, NoCaseIndex > > container
The container of the Properties.
Definition: PropertyList.h:125
Identifier for the case-insensitive index.
Definition: PropertyList.h:113
Property value_type
Definition: PropertyList.h:86
Definition: GnashKey.h:134
virtual bool accept(const ObjectURI &uri, const as_value &val)=0
This function should return false if no further visits are needed.
boost::multi_index::ordered_non_unique< boost::multi_index::tag< NoCase >, KeyExtractor, ObjectURI::CaseLessThan > NoCaseIndex
The case-insensitive index.
Definition: PropertyList.h:119
Definition: GnashKey.h:133
Definition: ObjectURI.h:129
void setReachable() const
Mark all properties reachable.
Definition: PropertyList.h:295
Identifier for the case-sensitive index.
Definition: PropertyList.h:104
Definition: GnashKey.h:162
std::set< ObjectURI, ObjectURI::LessThan > PropertyTracker
Definition: PropertyList.h:85
Set of properties associated with an ActionScript object.
Definition: PropertyList.h:81
container::iterator iterator
Definition: PropertyList.h:127
#define DSOTEXPORT
Definition: dsodefs.h:63
const ObjectURI & uri() const
The name-namespace pair (ObjectURI) of this Property.
Definition: Property.h:385
An abstract key visitor.
Definition: PropertyList.h:58
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:62
Identifier for the sequenced index.
Definition: PropertyList.h:89
Definition: ObjectURI.h:121
result_type operator()(const Property &p) const
Definition: PropertyList.h:98