• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

PropertyList.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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 "Property.h" // for templated functions
00023 
00024 #include <set> 
00025 #include <map> 
00026 #include <string> // for use within map 
00027 #include <cassert> // for inlines
00028 #include <utility> // for std::pair
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 // Forward declaration
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         // The template keyword is not required by the Standard here, but the
00125         // OpenBSD compiler needs it. Use of the template keyword where it is
00126         // not necessary is not an error.
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     //                          one is created.
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 } // namespace gnash
00292 
00293 #endif // GNASH_PROPERTYLIST_H

Generated on Thu Sep 30 2010 14:35:01 for Gnash by  doxygen 1.7.1