gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9617: Initial support for converting


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9617: Initial support for converting as_values and amf::Elements.
Date: Wed, 03 Sep 2008 14:29:55 -0600
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9617
committer: address@hidden
branch nick: rtmp
timestamp: Wed 2008-09-03 14:29:55 -0600
message:
  Initial support for converting as_values and amf::Elements.
modified:
  libcore/as_value.cpp
  libcore/as_value.h
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp      2008-08-18 23:53:04 +0000
+++ b/libcore/as_value.cpp      2008-09-03 20:29:55 +0000
@@ -32,6 +32,9 @@
 #include "action.h" // for call_method0
 #include "utility.h" // for typeName() and utility::isFinite
 #include "namedStrings.h"
+#include "element.h"
+#include "GnashException.h"
+#include "array.h"
 
 #include <cmath> // std::fmod
 #include <boost/algorithm/string/case_conv.hpp>
@@ -50,8 +53,11 @@
 // Define this macro to make soft references activity verbose
 //#define GNASH_DEBUG_SOFT_REFERENCES
 
+using namespace amf;
+
 namespace {
 
+
 struct invalidHexDigit {};
 boost::uint8_t parseHex(char c)
 {
@@ -620,6 +626,34 @@
     /* NOTREACHED */
 }
 
+amf::Element *
+as_value::to_element() const
+{
+    Element *el = new Element;
+    switch (m_type) {
+      case  STRING:
+         el->makeString(getStr());
+         break;
+      case NUMBER:
+         el->makeNumber(getNum());
+         break;
+      case BOOLEAN:
+         el->makeBoolean(getBool());
+         break;
+      case OBJECT:
+         el->makeObject();
+         break;
+      case AS_FUNCTION:
+         break;
+      case MOVIECLIP:
+         break;
+      default:
+         break;
+    }
+
+    return el;
+}
+
 // This returns an as_value as an integer. It is
 // probably used for most implicit conversions to 
 // int, for instance in the String class.
@@ -1652,6 +1686,114 @@
 {
 }
 
+/// Instantiate this value from an AMF element 
+as_value::as_value(Element &el)
+{
+    VM& vm = VM::get();
+    int swfVersion = vm.getSWFVersion();
+    string_table& st = vm.getStringTable();
+    
+    switch (el.getType()) {
+      case Element::NULL_AMF0:
+      {
+         m_type = NULLTYPE;
+         break;
+      }
+      case Element::UNDEFINED_AMF0:
+      {
+         m_type = UNDEFINED;
+         break;
+      }
+      case Element::MOVIECLIP_AMF0:
+      {
+         m_type = MOVIECLIP;
+         _value = el.getData();
+         break;
+      }
+      case Element::NUMBER_AMF0:
+      {
+         m_type = NUMBER;
+         _value = el.to_number();
+         break;
+      }
+      case Element::BOOLEAN_AMF0:
+      {
+         m_type = BOOLEAN;
+         bool flag = el.to_bool();
+         _value = flag ;
+         break;
+      }
+      case Element::STRING_AMF0:
+      {
+         m_type = STRING;
+         std::string str = el.to_string();
+         _value = str;
+         break;
+      }
+      case Element::OBJECT_AMF0:
+      {
+         m_type = OBJECT;
+         boost::intrusive_ptr<as_object> obj(new as_object()); 
+         if (el.propertySize()) {
+             for (size_t i=0; i < el.propertySize(); i++) {
+                 Element *prop = el[i];
+                 if (prop == 0) {
+                     break;
+                 } else {
+//                   obj->set_member(st.string_table::find(prop->getName()), 
as_value(prop));
+                     obj->set_member(st.string_table::find("foo"), 
as_value("bar"));
+                     obj->set_member(st.string_table::find("bar"), 
as_value(1.234));
+                 }
+             }
+         }
+         _value = obj;
+         break;
+      }
+      case Element::REFERENCE_AMF0:
+      case Element::ECMA_ARRAY_AMF0:
+      case Element::OBJECT_END_AMF0:
+      case Element::STRICT_ARRAY_AMF0:
+      {
+         m_type = OBJECT;
+         _value = el.getData();
+         break;
+      }
+      case Element::DATE_AMF0:
+      {
+         if (swfVersion > 5) {
+             m_type = STRING;
+         }
+         break;
+      }
+      case Element::LONG_STRING_AMF0:
+      {
+         m_type = STRING;
+         std::string str = el.to_string();
+         _value = str;
+         break;
+      }
+      case Element::UNSUPPORTED_AMF0:
+      case Element::RECORD_SET_AMF0:
+      case Element::XML_OBJECT_AMF0:
+      case Element::TYPED_OBJECT_AMF0:
+         break;
+      case Element::AMF3_DATA:
+      case Element::NOTYPE:
+         throw ParserException("No type set for amf0 element");
+         break;
+      default:
+         throw ParserException("Unsupported value type");
+         break;
+    }
+}
+
+as_value &
+as_value::operator=(amf::Element &)
+{
+
+    return *this;
+}
+
 as_value&
 as_value::newAdd(const as_value& op2)
 {

=== modified file 'libcore/as_value.h'
--- a/libcore/as_value.h        2008-08-18 23:53:04 +0000
+++ b/libcore/as_value.h        2008-09-03 20:29:55 +0000
@@ -26,6 +26,7 @@
 #include "dsodefs.h"
 #include "smart_ptr.h"
 #include "CharacterProxy.h"
+#include "element.h"
 
 #include <cmath>
 #include <limits>
@@ -161,6 +162,10 @@
        /// Chad: Document this
        as_value(asNamespace &);
 
+       /// Construct a value from an AMF element
+       as_value(amf::Element &);
+       as_value &operator=(amf::Element &);
+       
        /// Construct a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value
        //
        /// See as_object::to_movie and as_object::to_function
@@ -278,6 +283,14 @@
        ///
        double  to_number() const;
 
+       /// Get an AMF element representation for this value
+       //
+       /// @param env
+       ///     The environment to use for running the valueOf() method
+       ///     for object values. If NULL, valueOf() won't be run.
+       ///
+       amf::Element *to_element() const;
+
        /// Conversion to 32bit integer
        //
        /// Use this conversion whenever an int is needed.
@@ -568,8 +581,6 @@
        // Equivalent of ActionSubtract
        as_value& subtract(const as_value& o);
 
-
-
        /// Set any object value as reachable (for the GC)
        //
        /// Object values are values stored by pointer (objects and functions)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]