CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/10/26 14:45:28
Modified files:
. : ChangeLog
server : Makefile.am as_object.cpp as_object.h
testsuite/server: Makefile.am
Added files:
server : PropertyList.cpp PropertyList.h
testsuite/server: PropertyListTest.cpp
Log message:
* server/: Makefile.am, as_object.{cpp,h}: use the PropertyList
class
rather then the simple stringi_hash<> (replaces TU things
with standard things, btw)
* server/PropertyList.{cpp,h}, testsuite/server/Makefile.am,
testsuite/server/PropertyListTest.cpp: new class for use
by as objects + associated test.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1398&r2=1.1399
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Makefile.am?cvsroot=gnash&r1=1.76&r2=1.77
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/server/PropertyList.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/server/PropertyList.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/Makefile.am?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/PropertyListTest.cpp?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1398
retrieving revision 1.1399
diff -u -b -r1.1398 -r1.1399
--- ChangeLog 26 Oct 2006 14:24:24 -0000 1.1398
+++ ChangeLog 26 Oct 2006 14:45:28 -0000 1.1399
@@ -1,5 +1,11 @@
2006-10-26 Sandro Santilli <address@hidden>
+ * server/: Makefile.am, as_object.{cpp,h}: use the PropertyList class
+ rather then the simple stringi_hash<> (replaces TU things
+ with standard things, btw)
+ * server/PropertyList.{cpp,h}, testsuite/server/Makefile.am,
+ testsuite/server/PropertyListTest.cpp: new class for use
+ by as objects + associated test.
* server/as_value.h: added output operator.
* server/as_member.h: added is_read_only() method; changed
get_member_flags() to return a reference (+added a const
Index: server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/Makefile.am,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -b -r1.76 -r1.77
--- server/Makefile.am 24 Oct 2006 10:14:35 -0000 1.76
+++ server/Makefile.am 26 Oct 2006 14:45:28 -0000 1.77
@@ -36,7 +36,7 @@
#
#
-# $Id: Makefile.am,v 1.76 2006/10/24 10:14:35 strk Exp $
+# $Id: Makefile.am,v 1.77 2006/10/26 14:45:28 strk Exp $
AUTOMAKE_OPTIONS =
@@ -101,6 +101,7 @@
sprite_instance.cpp \
matrix.cpp \
movie_instance.cpp \
+ PropertyList.cpp \
stream.cpp \
StreamProvider.cpp \
URLAccessManager.cpp \
@@ -142,6 +143,7 @@
movie.h \
movie_interface.h \
movie_root.h \
+ PropertyList.h \
rect.h \
resource.h \
render.h \
Index: server/as_object.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/as_object.cpp 25 Oct 2006 08:59:28 -0000 1.12
+++ server/as_object.cpp 26 Oct 2006 14:45:28 -0000 1.13
@@ -59,51 +59,38 @@
/*protected*/
bool
-as_object::get_member_default(const tu_stringi& name, as_value* val)
+as_object::get_member_default(const tu_stringi& namei, as_value* val)
{
+ assert(val);
+
+ // temp hack, should really update this method's interface instead
+ std::string name = namei.c_str();
+
//log_action(" get member: %s (at %p) for object %p\n", name.c_str(),
(void*)val, (void*)this);
- if (name == "__proto__")
+ if (namei == "__proto__")
{
if ( m_prototype == NULL )
{
- log_msg("as_object %p has no prototype\n", (void*)this);
+ //log_msg("as_object %p has no prototype\n",
(void*)this);
return false;
}
val->set_as_object(m_prototype);
return true;
}
- else
- {
- as_member m;
- if (m_members.get(name, &m) == false)
- {
+ if ( _members.getValue(name, *val) ) return true;
+
//log_action(" not found on first level\n");
if (m_prototype == NULL)
{
//log_action(" no __proto__ (m_prototype)
defined\n");
return false;
}
- else
- {
- //log_action(" checkin in __proto__ (m_prototype)
%p\n", (void*)m_prototype);
- return m_prototype->get_member(name, val);
- }
- } else {
- //log_action(" found on first level\n");
- *val=m.get_member_value();
- return true;
- }
- }
- return true;
-}
-bool
-as_object::get_member(const tu_stringi& name, as_member* member) const
-{
- //printf("GET MEMBER: %s at %p for object %p\n", name.c_str(), member,
this);
- assert(member != NULL);
- return m_members.get(name, member);
+ //log_action(" checkin in __proto__ (m_prototype) %p\n",
(void*)m_prototype);
+ // tmp hack (passing namei), see comment above 'name' declaration
+ // at start of function
+ return m_prototype->get_member(namei, val);
}
void
@@ -130,43 +117,24 @@
return;
}
- stringi_hash<as_member>::const_iterator it = this->m_members.find(name);
-
- if ( it == this->m_members.end() )
+ std::string key = name.c_str();
+ if ( ! _members.setValue(key, val) )
{
- m_members[name] = as_member(val);
- return;
- }
-
- const as_prop_flags flags = (it->second).get_member_flags();
-
- // is the member read-only ?
- if (!flags.get_read_only()) {
- m_members[name] = as_member(val, flags);
+ log_warning("Attempt to set Read-Only property ``%s'' on object
``%p''", key.c_str(), (void*)this);
}
}
bool
-as_object::set_member_flags(const tu_stringi& name, const int flags)
+as_object::set_member_flags(const tu_stringi& name, int setTrue, int setFalse)
{
- as_member member;
- if (this->get_member(name, &member)) {
- as_prop_flags f = member.get_member_flags();
- f.set_flags(flags);
- member.set_member_flags(f);
-
- m_members[name] = member;
-
- return true;
- }
-
- return false;
+ // TODO: accept a std::string directly
+ return _members.setFlags(std::string(name.c_str()), setTrue, setFalse);
}
void
as_object::clear()
{
- m_members.clear();
+ _members.clear();
if (m_prototype)
{
m_prototype->drop_ref();
@@ -189,16 +157,9 @@
void
as_object::dump_members() const
{
- typedef stringi_hash<as_member>::const_iterator members_iterator;
-
- //Vitaly: temporarily commented because of problems with the VC++
compiler
-// log_msg("%d Members of object %p follow",
-// m_members..size(), (void*)this);
- for ( members_iterator it=m_members.begin(), itEnd=m_members.end();
- it != itEnd; ++it )
- {
- log_msg(" %s: %s", it->first.c_str(),
it->second.get_member_value().to_string());
- }
+ log_msg("%d Members of object %p follow",
+ _members.size(), (void*)this);
+ _members.dump();
}
void
@@ -221,22 +182,14 @@
propstr=propstr.substr(next_comma);
}
- stringi_hash<as_member>::iterator it = \
- m_members.find(prop.c_str());
- if ( it != m_members.end() )
- {
- as_member& member = it->second;
- as_prop_flags f = member.get_member_flags();
- f.set_flags(set_true, set_false);
- member.set_member_flags(f);
- }
- else
+ if ( ! _members.setFlags(prop, set_true, set_false) )
{
- log_warning("Unknown object property %s, "
- "can't set propflags on it", prop.c_str());
+ log_warning("Can't set propflags on object "
+ "property %s "
+ "(either not found or protected)",
+ prop.c_str());
}
-
if ( next_comma == std::string::npos )
{
break;
@@ -263,75 +216,28 @@
//
// Take all the members of the object
-
- stringi_hash<as_member>::iterator it = m_members.begin();
- while (it != m_members.end())
- {
- as_member& member = it->second;
- as_prop_flags f = member.get_member_flags();
- f.set_flags(set_true, set_false);
- member.set_member_flags(f);
- ++it;
- }
+ //std::pair<size_t, size_t> result =
+ _members.setFlagsAll(set_true, set_false);
// Are we sure we need to descend to __proto__ ?
// should we recurse then ?
if (m_prototype != NULL)
{
- as_object* prototype = m_prototype;
-
- it = prototype->m_members.begin();
- while (it != prototype->m_members.end())
- {
- as_member& member = it->second;
- as_prop_flags f = member.get_member_flags();
- f.set_flags(set_true, set_false);
- member.set_member_flags(f);
-
- ++it;
- }
+ m_prototype->_members.setFlagsAll(set_true, set_false);
}
}
else
{
- as_object* object_props = props;
-
- stringi_hash<as_member>::iterator it =
object_props->m_members.begin();
- while(it != object_props->m_members.end())
- {
- const tu_stringi key =
(it->second).get_member_value().to_string();
- stringi_hash<as_member>::iterator it2 =
m_members.find(key);
-
- if (it2 != m_members.end())
- {
- as_member& member = it2->second;
-
- as_prop_flags f = member.get_member_flags();
- f.set_flags(set_true, set_false);
- member.set_member_flags(f);
- }
-
- ++it;
- }
+ //std::pair<size_t, size_t> result =
+ _members.setFlagsAll(props->_members, set_true, set_false);
}
}
void
as_object::copyProperties(const as_object& o)
{
- typedef stringi_hash<as_member>::const_iterator members_iterator;
- for (members_iterator it = o.m_members.begin(),
- itEnd = o.m_members.end();
- it != itEnd;
- ++it )
- {
- const tu_stringi name = it->first;
- const as_member member = it->second;
- // TODO: don't call get_member_value, we
- // must copy also 'getset' members ...
- set_member(name, member.get_member_value());
- }
+ _members.import(o._members);
}
void
@@ -344,28 +250,10 @@
// to avoid infinite loops
std::set<const as_object*> visited;
- typedef stringi_hash<as_member>::const_iterator members_iterator;
-
const as_object* obj = this;
while ( obj && visited.insert(obj).second )
{
- for ( members_iterator
- it=obj->m_members.begin(), itEnd=obj->m_members.end();
- it!=itEnd;
- ++it )
- {
- const as_member& member = it->second;
-
- if (! member.get_member_flags().get_dont_enum())
- {
- // shouldn't this be a tu_string instead ?
- // we need to support UTF8 too I guess
- const char* val = it->first.c_str();
-
- env.push(as_value(val));
- }
- }
-
+ obj->_members.enumerateValues(env);
obj = obj->m_prototype;
}
Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- server/as_object.h 25 Oct 2006 19:21:35 -0000 1.13
+++ server/as_object.h 26 Oct 2006 14:45:28 -0000 1.14
@@ -47,7 +47,7 @@
#include <cmath>
#include "container.h"
#include "ref_counted.h" // for inheritance
-#include "as_member.h"
+#include "PropertyList.h"
namespace gnash {
@@ -66,22 +66,8 @@
//class as_object : public resource
class DSOEXPORT as_object : public ref_counted
{
- /// Members of this objects in an hash
- //
- /// TODO: make this private or protected and provide
- /// visitor pattern interface
- ///
- /// TODO: change this to a <boost/ptr_container/ptr_map.hpp>
- /// so we can store as_member by pointer allowing polymorphism
- /// of it (planning to add a getset_as_member) w/out much
- /// overhead and with manager ownerhips. See:
- /// http://www.boost.org/libs/ptr_container/doc/ptr_container.html
- ///
- stringi_hash<as_member> m_members;
-
- /// Get an member pointer by name
- virtual bool get_member(const tu_stringi& name,
- as_member* member) const;
+ /// Properties of this objects
+ PropertyList _members;
public:
@@ -92,12 +78,20 @@
as_object* m_prototype;
/// Construct an ActionScript object with no prototype associated.
- as_object() : m_prototype(NULL) { }
+ as_object()
+ :
+ //_members(*this),
+ m_prototype(NULL)
+ {
+ }
/// \brief
/// Construct an ActionScript object based on the given prototype.
/// Adds a reference to the prototype, if any.
- as_object(as_object* proto) : m_prototype(proto)
+ as_object(as_object* proto)
+ :
+ //_members(*this),
+ m_prototype(proto)
{
if (m_prototype) m_prototype->add_ref();
}
@@ -133,9 +127,20 @@
///
virtual bool get_member(const tu_stringi& name, as_value* val);
+
/// Set member flags (probably used by ASSetPropFlags)
- virtual bool set_member_flags(const tu_stringi& name,
- const int flags);
+ //
+ /// @param setTrue
+ /// the set of flags to set
+ ///
+ /// @param setFalse
+ /// the set of flags to clear
+ ///
+ /// @return true on success, false on failure
+ /// (non-existent or protected member)
+ ///
+ bool set_member_flags(const tu_stringi& name,
+ int setTrue, int setFalse=0);
/// This object is not a movie; no conversion.
virtual movie* to_movie() { return NULL; }
Index: testsuite/server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/server/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- testsuite/server/Makefile.am 16 Oct 2006 18:09:19 -0000 1.9
+++ testsuite/server/Makefile.am 26 Oct 2006 14:45:28 -0000 1.10
@@ -48,6 +48,7 @@
check_PROGRAMS = \
MatrixTest \
+ PropertyListTest \
$(NULL)
CLEANFILES = \
@@ -64,6 +65,12 @@
$(top_builddir)/libbase/libgnashbase.la \
$(NULL)
+PropertyListTest_SOURCES = PropertyListTest.cpp
+PropertyListTest_LDADD = \
+ $(top_builddir)/server/libgnashserver.la \
+ $(top_builddir)/libbase/libgnashbase.la \
+ $(NULL)
+
TEST_DRIVERS = server.exp
check-DEJAGNU: site-update $(check_PROGRAMS)
Index: server/PropertyList.cpp
===================================================================
RCS file: server/PropertyList.cpp
diff -N server/PropertyList.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/PropertyList.cpp 26 Oct 2006 14:45:28 -0000 1.1
@@ -0,0 +1,187 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+//
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "PropertyList.h"
+
+#include "log.h"
+
+#include "as_function.h"
+#include "as_environment.h" // for enumerateValues
+#include "as_value.h" // for enumerateValues
+
+namespace gnash {
+
+//PropertyList::PropertyList(as_object& owner)
+// :
+// _owner(owner)
+//{
+//}
+
+
+bool
+PropertyList::getValue(const std::string& key, as_value& val) const
+{
+ const_iterator found = _props.find( key );
+ if ( found == _props.end() )
+ {
+ return false;
+ }
+
+ val=found->second.get_member_value();
+
+ //log_msg("Property %s found, assigning to return (%s)", key.c_str(),
val.to_string());
+
+ return true;
+}
+
+bool
+PropertyList::setValue(const std::string& key, const as_value& val)
+{
+ iterator found = _props.find( key );
+ if ( found == _props.end() )
+ {
+ // create a new member
+ _props[key] = as_member(val);
+ return true;
+ }
+
+ as_member& member = found->second;
+
+ if ( member.is_read_only() )
+ {
+ log_msg("Property %s is read-only, not setting it",
key.c_str());
+ return false;
+ }
+
+ log_msg("Property %s set to value %s", key.c_str(), val.to_string());
+ member.set_member_value(val);
+ return true;
+}
+
+bool
+PropertyList::setFlags(const std::string& key,
+ int setFlags, int clearFlags)
+{
+ iterator found = _props.find( key );
+ if ( found == _props.end() ) return false;
+
+ as_member& member = found->second;
+
+ as_prop_flags& f = member.get_member_flags();
+ return f.set_flags(setFlags, clearFlags);
+}
+
+std::pair<size_t,size_t>
+PropertyList::setFlagsAll(int setFlags, int clearFlags)
+{
+ size_t success=0;
+ size_t failure=0;
+
+ for ( iterator it=_props.begin(), far=_props.end(); it != far; ++it)
+ {
+ as_member& member = it->second;
+ as_prop_flags& f = member.get_member_flags();
+ if ( f.set_flags(setFlags, clearFlags) ) ++success;
+ else ++failure;
+ }
+
+ return std::make_pair(success,failure);
+}
+
+std::pair<size_t,size_t>
+PropertyList::setFlagsAll(const PropertyList& props,
+ int flagsSet, int flagsClear)
+{
+ size_t success=0;
+ size_t failure=0;
+
+ for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it )
+ {
+ const std::string& name = it->first;
+
+ if ( setFlags(name, flagsSet, flagsClear) ) ++success;
+ else ++failure;
+ }
+
+ return std::make_pair(success,failure);
+
+}
+
+void
+PropertyList::enumerateValues(as_environment& env) const
+{
+ for ( const_iterator i=begin(), ie=end(); i != ie; ++i)
+ {
+ const as_member& member = i->second;
+
+ if ( member.get_member_flags().get_dont_enum() ) continue;
+
+ env.push(as_value(i->first.c_str()));
+ }
+}
+
+void
+PropertyList::dump() const
+{
+ for ( const_iterator it=begin(), itEnd=end(); it != itEnd; ++it )
+ {
+ log_msg(" %s: %s", it->first.c_str(),
+ it->second.get_member_value().to_string());
+ }
+}
+
+void
+PropertyList::import(const PropertyList& o)
+{
+ for (const_iterator it = o.begin(), itEnd = o.end(); it != itEnd; ++it)
+ {
+ const std::string& name = it->first;
+ const as_member& member = it->second;
+
+ // TODO: don't call get_member_value, we
+ // must copy also 'getset' members ...
+ setValue(name, member.get_member_value());
+ }
+}
+
+} // end of gnash namespace
+
Index: server/PropertyList.h
===================================================================
RCS file: server/PropertyList.h
diff -N server/PropertyList.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/PropertyList.h 26 Oct 2006 14:45:28 -0000 1.1
@@ -0,0 +1,275 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+
+#ifndef GNASH_PROPERTYLIST_H
+#define GNASH_PROPERTYLIST_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "as_member.h" // for use within map
+
+#include <map>
+#include <string> // for use within map and for StringNoCaseLessThen
+
+// Forward declaration
+namespace gnash {
+ class as_object;
+ class as_environment;
+ class as_function;
+}
+
+namespace gnash {
+
+/// A case-insensitive string comparator (probably not very performant)
+struct StringNoCaseLessThen {
+ bool operator() (const std::string& a, const std::string& b) const
+ {
+ size_t a_len = a.length();
+ size_t b_len = b.length();
+
+ size_t cmplen = a_len < b_len ? a_len : b_len;
+
+ for (size_t i=0; i<cmplen; ++i)
+ {
+ char cha = toupper(a[i]);
+ char chb = toupper(b[i]);
+
+ if (cha < chb) return true;
+ else if (cha > chb) return false;
+ assert(cha==chb);
+ }
+
+ // strings are equal for whole lenght of a,
+ // a is LessThen b only if 'b' contains more
+ // characters then 'a' (if same number of
+ // chars 'a' is NOT less then 'b')
+
+ if ( a_len < b_len ) return true;
+ return false; // equal or greater
+
+ }
+};
+
+/// Set of properties associated to an ActionScript object.
+//
+class PropertyList
+{
+
+private:
+
+ /// TODO: change this to a <boost/ptr_container/ptr_map.hpp>
+ /// so we can store as_member by pointer allowing polymorphism
+ /// of it (planning to add a getset_as_member) w/out much
+ /// overhead and with manager ownerhips. See:
+ /// http://www.boost.org/libs/ptr_container/doc/ptr_container.html
+ ///
+ typedef std::map<std::string, as_member, StringNoCaseLessThen>
container;
+ typedef container::iterator iterator;
+ typedef container::const_iterator const_iterator;
+ typedef container::reverse_iterator reverse_iterator;
+ typedef container::const_reverse_iterator const_reverse_iterator;
+
+ container _props;
+
+ // this will be used to setup environemnt for
+ // getter-setter properties
+ //as_object& _owner;
+
+ iterator find(const std::string& key) {
+ return _props.find(key);
+ }
+ const_iterator find(const std::string& key) const {
+ return _props.find(key);
+ }
+ iterator end() {
+ return _props.end();
+ }
+ const_iterator end() const {
+ return _props.end();
+ }
+ iterator begin() {
+ return _props.begin();
+ }
+ const_iterator begin() const {
+ return _props.begin();
+ }
+
+public:
+
+ //PropertyList(as_object& owner);
+
+ /// Get the as_value value of a named property
+ //
+ /// @param key
+ /// name of the property. search will be case-insensitive
+ ///
+ /// @param value
+ /// a reference to the as_value to which a found property
+ /// value will be copied (it will be left untouched if
+ /// no property was found)
+ ///
+ /// @return true if the value was successfully retrived, false
+ /// otherwise (and value will be untouched)
+ ///
+ bool getValue(const std::string& key, as_value& value) const;
+
+ /// Set the value of a property, creating a new one if unexistent.
+ //
+ /// @param key
+ /// name of the property. search will be case-insensitive
+ ///
+ /// @param value
+ /// a const reference to the as_value to use for setting
+ /// or creating the property.
+ ///
+ /// @return true if the value was successfully set, false
+ /// otherwise (found a read-only property, most likely).
+ ///
+ bool setValue(const std::string& key, const as_value& value);
+
+ /// \brief
+ /// Add a getter/setter property, if not already existing
+ /// (or should we allow override ?)
+ //
+ /// @param key
+ /// name of the property. search will be case-insensitive
+ ///
+ /// @param getter
+ /// A function to invoke when this property value is requested.
+ /// add_ref will be called on the function.
+ ///
+ /// @param setter
+ /// A function to invoke when setting this property's value.
+ /// add_ref will be called on the function.
+ ///
+ /// @return true if the property was successfully added, false
+ /// otherwise (property already existent?)
+ ///
+ bool addGetterSetter(const std::string& key, as_function& getter,
+ as_function& setter) { assert(0); }
+
+ /// Set the flags of a property.
+ //
+ /// @param key
+ /// name of the property. search will be case-insensitive
+ ///
+ /// @param setTrue
+ /// the set of flags to set
+ ///
+ /// @param setFalse
+ /// the set of flags to clear
+ ///
+ /// @return true if the value was successfully set, false
+ /// otherwise (either not found or protected)
+ ///
+ bool setFlags(const std::string& key, int setTrue, int setFalse);
+
+ /// Set the flags of all properties.
+ //
+ /// @param setTrue
+ /// the set of flags to set
+ ///
+ /// @param setFalse
+ /// the set of flags to clear
+ ///
+ /// @return a pair containing number of successes
+ /// (first) and number of failures (second).
+ /// Failures are due to protected properties,
+ /// on which flags cannot be set.
+ ///
+ std::pair<size_t,size_t> setFlagsAll(int setTrue, int setFalse);
+
+ /// Set the flags of all properties whose name matches
+ /// any key in the given PropertyList object
+ //
+ /// @param props
+ /// the properties to use for finding names
+ ///
+ /// @param setTrue
+ /// the set of flags to set
+ ///
+ /// @param setFalse
+ /// the set of flags to clear
+ ///
+ /// @return a pair containing number of successes
+ /// (first) and number of failures (second).
+ /// Failures are due to either protected properties
+ /// of keys in the props argument not found in
+ /// this properties set.
+ ///
+ std::pair<size_t,size_t> setFlagsAll(
+ const PropertyList& props,
+ int setTrue, int setFalse);
+
+ /// \brief
+ /// Copy all properties from the given PropertyList
+ /// instance.
+ //
+ /// Unexistent properties are created. Existing properties
+ /// are updated with the new value.
+ ///
+ /// @param props
+ /// the properties to copy from
+ ///
+ void import(const PropertyList& props);
+
+ /// \brief
+ /// Enumerate all non-hidden properties pushing
+ /// their value to the given as_environment.
+ void enumerateValues(as_environment& env) const;
+
+ /// Remove all entries in the container
+ void clear()
+ {
+ _props.clear();
+ }
+
+ size_t size() const
+ {
+ return _props.size();
+ }
+
+ /// Dump all members (using log_msg)
+ void dump() const;
+};
+
+
+} // namespace gnash
+
+#endif // GNASH_PROPERTYLIST_H
Index: testsuite/server/PropertyListTest.cpp
===================================================================
RCS file: testsuite/server/PropertyListTest.cpp
diff -N testsuite/server/PropertyListTest.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/server/PropertyListTest.cpp 26 Oct 2006 14:45:28 -0000
1.1
@@ -0,0 +1,95 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+
+#include "PropertyList.h"
+#include "dejagnu.h"
+#include "log.h"
+
+#include "check.h"
+#include <iostream>
+#include <sstream>
+#include <cassert>
+#include <string>
+
+using namespace std;
+using namespace gnash;
+
+int
+main(int /*argc*/, char** /*argv*/)
+{
+
+ dbglogfile.setVerbosity();
+
+ PropertyList props;
+
+ as_value val("value");
+ as_value val2("value2");
+ as_value val3("value3");
+ as_value ret;
+
+ check_equals(props.size(), 0);
+ check ( props.setValue("Var0", val) );
+ check_equals(props.size(), 1);
+
+ check ( props.getValue("Var0", ret) );
+ check_equals ( ret, val );
+
+ // search should be case-insensitive
+ check ( props.getValue("var0", ret) );
+ check_equals ( ret, val );
+
+ // new value overrides existing value
+ check ( props.setValue("Var0", val2) );
+ check_equals(props.size(), 1);
+ check ( props.getValue("Var0", ret) );
+ check_equals ( ret, val2 );
+
+ // case-insensitive setting value overrides existing value
+ check ( props.setValue("var0", val3) );
+ check_equals(props.size(), 1);
+ check ( props.getValue("vAr0", ret) );
+ check_equals ( ret, val3 );
+
+ // Now add some new labels
+ check ( props.setValue("var1", val) );
+ check_equals(props.size(), 2);
+ check ( props.setValue("var2", val) );
+ check_equals(props.size(), 3);
+ check ( props.setValue("var3", val) );
+ check_equals(props.size(), 4);
+
+}
+
_______________________________________________
Gnash-commit mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/gnash-commit