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