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 <boost/cstdint.hpp>
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 <boost/bind.hpp>
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_iterator it = _props.begin(), ie = _props.end();
154  it != ie; ++it) {
155 
156  if (!cmp(*it)) continue;
157  as_value val = it->getValue(_owner);
158  if (!visitor.accept(it->uri(), val)) return;
159  }
160  }
161 
163  //
171  void visitKeys(KeyVisitor& v, PropertyTracker& donelist) const;
172 
174  //
188  DSOTEXPORT bool setValue(const ObjectURI& uri, const as_value& value,
189  const PropFlags& flagsIfMissing = 0);
190 
192  //
197  DSOTEXPORT Property* getProperty(const ObjectURI& uri) const;
198 
200  //
210  DSOTEXPORT std::pair<bool,bool> delProperty(const ObjectURI& uri);
211 
213  //
215  //
226  bool addGetterSetter(const ObjectURI& uri, as_function& getter,
227  as_function* setter, const as_value& cacheVal,
228  const PropFlags& flagsIfMissing = 0);
229 
231  //
238  bool addGetterSetter(const ObjectURI& uri, as_c_function_ptr getter,
239  as_c_function_ptr setter, const PropFlags& flagsIfMissing);
240 
242  //
249  bool addDestructiveGetter(const ObjectURI& uri, as_function& getter,
250  const PropFlags& flagsIfMissing = 0);
251 
259  // one is created.
262  bool addDestructiveGetter(const ObjectURI& uri, as_c_function_ptr getter,
263  const PropFlags& flagsIfMissing = 0);
264 
266  //
270  DSOTEXPORT void setFlags(const ObjectURI& uri, int setTrue, int setFalse);
271 
273  //
276  void setFlagsAll(int setTrue, int setFalse);
277 
279  void clear();
280 
282  size_t size() const {
283  return _props.size();
284  }
285 
287  //
290  void dump();
291 
293  //
296  void setReachable() const {
297  std::for_each(_props.begin(), _props.end(),
298  boost::mem_fn(&Property::setReachable));
299  }
300 
301 private:
302 
303  container _props;
304 
305  as_object& _owner;
306 
307 };
308 
309 
310 } // namespace gnash
311 
312 #endif // GNASH_PROPERTYLIST_H
DSOTEXPORT PropertyList(as_object &obj)
Construct the PropertyList.
Definition: PropertyList.cpp:75
virtual void operator()(const ObjectURI &uri)=0
This function should return false if no further visits are needed.
DSOTEXPORT bool setValue(const ObjectURI &uri, const as_value &value, const PropFlags &flagsIfMissing=0)
Set the value of a property, creating a new one if it doesn&#39;t exist.
Definition: PropertyList.cpp:94
DSOTEXPORT std::pair< bool, bool > delProperty(const ObjectURI &uri)
Delete a Property, if existing and not protected from deletion.
Definition: PropertyList.cpp:154
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:692
const ObjectURI & result_type
Definition: PropertyList.h:97
DSOTEXPORT Property * getProperty(const ObjectURI &uri) const
Get a property if it exists.
Definition: PropertyList.cpp:139
virtual ~KeyVisitor()
Definition: PropertyList.h:63
ActionScript value type.
Definition: as_value.h:95
as_value(* as_c_function_ptr)(const fn_call &fn)
Definition: Property.h:34
An abstract property.
Definition: Property.h:275
virtual ~PropertyVisitor()
Definition: PropertyList.h:54
DSOTEXPORT void setFlags(const ObjectURI &uri, int setTrue, int setFalse)
Set the flags of a property.
Definition: PropertyList.cpp:118
Definition: PropertyList.h:95
Flags defining the level of protection of a member.
Definition: PropFlags.h:28
The base class for all ActionScript objects.
Definition: as_object.h:161
size_t size() const
Return number of properties in this list.
Definition: PropertyList.h:282
void setFlagsAll(int setTrue, int setFalse)
Set the flags of all properties.
Definition: PropertyList.cpp:129
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
void setReachable() const
Mark this property as being reachable (for the GC)
Definition: Property.h:398
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
tuple v
Definition: test.py:11
void dump()
Dump all members (using log_debug)
Definition: PropertyList.cpp:190
virtual bool accept(const ObjectURI &uri, const as_value &val)=0
This function should return false if no further visits are needed.
void visitKeys(KeyVisitor &v, PropertyTracker &donelist) const
Enumerate all non-hidden properties to the given container.
Definition: PropertyList.cpp:172
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
Identifier for the case-sensitive index.
Definition: PropertyList.h:104
void clear()
Remove all entries in the container.
Definition: PropertyList.cpp:313
void setReachable() const
Mark all properties reachable.
Definition: PropertyList.h:296
bool addDestructiveGetter(const ObjectURI &uri, as_function &getter, const PropFlags &flagsIfMissing=0)
Add a destructive getter property, if not already existant.
Definition: PropertyList.cpp:267
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
const ObjectURI & uri() const
The name-namespace pair (ObjectURI) of this Property.
Definition: Property.h:393
#define DSOTEXPORT
Definition: dsodefs.h:63
result_type operator()(const Property &p) const
Definition: PropertyList.h:98
bool addGetterSetter(const ObjectURI &uri, as_function &getter, as_function *setter, const as_value &cacheVal, const PropFlags &flagsIfMissing=0)
Add a getter/setter property, if not already existing.
Definition: PropertyList.cpp:200
An abstract key visitor.
Definition: PropertyList.h:58
void visitValues(V &visitor, U cmp=U()) const
Visit properties.
Definition: PropertyList.h:151
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