gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9677: Make as_value::to_element ret


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9677: Make as_value::to_element return by auto_ptr, have as_value by Element
Date: Thu, 04 Sep 2008 12:50:29 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9677
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Thu 2008-09-04 12:50:29 +0200
message:
  Make as_value::to_element return by auto_ptr, have as_value by Element
  constructor take a const ref. Minor const correctness and headers
  streamline in libamf.
modified:
  libamf/element.cpp
  libamf/element.h
  libamf/sol.cpp
  libamf/sol.h
  libcore/as_value.cpp
  libcore/as_value.h
  testsuite/libcore.all/AsValueTest.cpp
    ------------------------------------------------------------
    revno: 9676.1.1
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Thu 2008-09-04 12:48:29 +0200
    message:
      Make as_value::to_element return by auto_ptr, have as_value by Element
      constructor take a const ref. Minor const correctness and headers
      streamline in libamf.
    modified:
      libamf/element.cpp
      libamf/element.h
      libamf/sol.cpp
      libamf/sol.h
      libcore/as_value.cpp
      libcore/as_value.h
      testsuite/libcore.all/AsValueTest.cpp
=== modified file 'libamf/element.cpp'
--- a/libamf/element.cpp        2008-09-03 21:46:17 +0000
+++ b/libamf/element.cpp        2008-09-04 10:48:29 +0000
@@ -276,7 +276,7 @@
 }
 
 Network::byte_t *
-Element::getData()
+Element::getData() const
 {
 //    GNASH_REPORT_FUNCTION;
     if (_buffer) {

=== modified file 'libamf/element.h'
--- a/libamf/element.h  2008-09-02 09:34:35 +0000
+++ b/libamf/element.h  2008-09-04 10:48:29 +0000
@@ -174,12 +174,12 @@
     
     Element *operator[](size_t x);
 
-    gnash::Network::byte_t *getData();
+    gnash::Network::byte_t *getData() const;
     size_t getLength() const;
     Buffer *getBuffer() { return _buffer; };
     
     // These are all accessors for the various output formats
-    amf0_type_e getType() { return _type; };
+    amf0_type_e getType() const { return _type; };
     void setType(amf0_type_e x) { _type = x; };
 //    void setData(Buffer *buf) { _buffer = buf; };
 
@@ -197,12 +197,12 @@
 
     // Manipulate the children Elements of an object
     Element *findProperty(const std::string &name);
-    Element *getProperty(size_t x) { return _properties[x]; };
+    Element *getProperty(size_t x) const { return _properties[x]; };
     
     void addProperty(Element &el) { _properties.push_back(&el); };
     void addProperty(Element *el) { _properties.push_back(el); };
     Element *popProperty()        { return _properties.front(); };
-    size_t propertySize()         { return _properties.size(); };
+    size_t propertySize() const   { return _properties.size(); };
     amf::Buffer *encode();
     std::vector<Element *> getProperties() { return _properties; };
     void dump() const { dump(std::cerr); }

=== modified file 'libamf/sol.cpp'
--- a/libamf/sol.cpp    2008-08-13 19:26:51 +0000
+++ b/libamf/sol.cpp    2008-09-04 10:48:29 +0000
@@ -30,6 +30,7 @@
 #include <cassert>
 
 #include "network.h"
+#include "element.h"
 #include "amf.h"
 #include "buffer.h"
 #include "sol.h"

=== modified file 'libamf/sol.h'
--- a/libamf/sol.h      2008-05-16 02:46:11 +0000
+++ b/libamf/sol.h      2008-09-04 10:48:29 +0000
@@ -28,9 +28,14 @@
 
 #include "dsodefs.h" //DSOEXPORT
 #include "network.h"
-#include "element.h"
+//#include "element.h"
 #include "amf.h"
 
+// Forward declarations
+namespace amf {
+       class Element;
+}
+
 // It comprises of a magic number, followed by the file length, a
 // filetype, which appears to always be "TCSO", and what appears to be
 // a marker at the end of the header block.
@@ -48,7 +53,7 @@
 public:
     SOL();
     ~SOL();
-    size_t size() { return _amfobjs.size(); };
+    size_t size() const { return _amfobjs.size(); };
     
     // extract the header
     bool extractHeader(const std::vector<gnash::Network::byte_t> &data);

=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp      2008-09-04 00:35:31 +0000
+++ b/libcore/as_value.cpp      2008-09-04 10:48:29 +0000
@@ -59,7 +59,6 @@
 // Define this macto to make AMF parsing verbose
 //#define GNASH_DEBUG_AMF_PARSING
 
-using namespace amf;
 using namespace std;
 
 namespace {
@@ -98,10 +97,10 @@
 // This class is used to iterate through all the properties of an AS object,
 // so we can change them to children of an AMF0 element.
 class PropsSerializer {
-    Element& _obj;
+    amf::Element& _obj;
     string_table& _st;
 public:
-    PropsSerializer(Element& el, VM& vm)
+    PropsSerializer(amf::Element& el, VM& vm)
         : _obj(el),
          _st(vm.getStringTable())
        {};
@@ -109,8 +108,8 @@
     void operator() (string_table::key key, const as_value& val) const
         {
             //GNASH_REPORT_FUNCTION;
-            AMF amf;
-            Element *el = 0;
+            amf::AMF amf;
+            amf::Element *el = 0;
            
             const string& name = _st.string_table::value(key);
            
@@ -674,12 +673,12 @@
     /* NOTREACHED */
 }
 
-amf::Element *
+std::auto_ptr<amf::Element>
 as_value::to_element() const
 {
     VM& vm = VM::get();
     int swfVersion = vm.getSWFVersion();
-    Element *el = new Element;
+    std::auto_ptr<amf::Element> el ( new amf::Element );
     boost::intrusive_ptr<as_object> ptr = to_object();
 
     switch (m_type) {
@@ -701,9 +700,11 @@
       }
       case AS_FUNCTION:
          log_unimpl("Converting an AS function to an element is not 
supported");
+          // TODO: what kind of Element will be left with ? Should we throw an 
exception ?
          break;
       case MOVIECLIP:
          log_unimpl("Converting a Movie Clip to an element is not supported");
+          // TODO: what kind of Element will be left with ? Should we throw an 
exception ?
          break;
       default:
          break;
@@ -1748,100 +1749,100 @@
 }
 
 /// Instantiate this value from an AMF element 
-as_value::as_value(Element *el)
+as_value::as_value(const amf::Element& el)
 {
     VM& vm = VM::get();
     int swfVersion = vm.getSWFVersion();
     string_table& st = vm.getStringTable();
     
-    switch (el->getType()) {
-      case Element::NULL_AMF0:
+    switch (el.getType()) {
+      case amf::Element::NULL_AMF0:
       {
          m_type = NULLTYPE;
          break;
       }
-      case Element::UNDEFINED_AMF0:
+      case amf::Element::UNDEFINED_AMF0:
       {
          m_type = UNDEFINED;
          break;
       }
-      case Element::MOVIECLIP_AMF0:
+      case amf::Element::MOVIECLIP_AMF0:
       {
          m_type = MOVIECLIP;
-         _value = el->getData();
+         _value = el.getData();
          break;
       }
-      case Element::NUMBER_AMF0:
+      case amf::Element::NUMBER_AMF0:
       {
          m_type = NUMBER;
-         _value = el->to_number();
+         _value = el.to_number();
          break;
       }
-      case Element::BOOLEAN_AMF0:
+      case amf::Element::BOOLEAN_AMF0:
       {
          m_type = BOOLEAN;
-         bool flag = el->to_bool();
+         bool flag = el.to_bool();
          _value = flag ;
          break;
       }
-      case Element::STRING_AMF0:
+      case amf::Element::STRING_AMF0:
       {
          m_type = STRING;
-         std::string str = el->to_string();
+         std::string str = el.to_string();
          _value = str;
          break;
       }
-      case Element::OBJECT_AMF0:
-      case Element::REFERENCE_AMF0:
-      case Element::ECMA_ARRAY_AMF0:
-      case Element::OBJECT_END_AMF0:
-      case Element::STRICT_ARRAY_AMF0:
+      case amf::Element::OBJECT_AMF0:
+      case amf::Element::REFERENCE_AMF0:
+      case amf::Element::ECMA_ARRAY_AMF0:
+      case amf::Element::OBJECT_END_AMF0:
+      case amf::Element::STRICT_ARRAY_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->getProperty(i);
+         if (el.propertySize()) {
+             for (size_t i=0; i < el.propertySize(); i++) {
+                 const amf::Element *prop = el.getProperty(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(prop->getName()), 
as_value(*prop));
                  }
              }
          }
          _value = obj;
       }
       break;
-      case Element::DATE_AMF0:
+      case amf::Element::DATE_AMF0:
       {
          if (swfVersion > 5) {
              m_type = STRING;
          }
          break;
       }
-      case Element::LONG_STRING_AMF0:
+      case amf::Element::LONG_STRING_AMF0:
       {
          m_type = STRING;
-         std::string str = el->to_string();
+         std::string str = el.to_string();
          _value = str;
          break;
       }
-      case Element::UNSUPPORTED_AMF0:
+      case amf::Element::UNSUPPORTED_AMF0:
          log_unimpl("Unsupported data type is not supported yet");
          break;
-      case Element::RECORD_SET_AMF0:
+      case amf::Element::RECORD_SET_AMF0:
          log_unimpl("Record Set data type is not supported yet");
          break;
-      case Element::XML_OBJECT_AMF0:
+      case amf::Element::XML_OBJECT_AMF0:
          log_unimpl("XML data type is not supported yet");
          break;
-      case Element::TYPED_OBJECT_AMF0:
+      case amf::Element::TYPED_OBJECT_AMF0:
          log_unimpl("Typed Object data type is not supported yet");
          break;
-      case Element::AMF3_DATA:
+      case amf::Element::AMF3_DATA:
          log_unimpl("AMF3 data type is not supported yet");
          break;
-      case Element::NOTYPE:
+      case amf::Element::NOTYPE:
          throw ParserException("No type set for amf0 element");
          break;
       default:
@@ -1850,12 +1851,6 @@
     }
 }
 
-as_value &
-as_value::operator=(amf::Element *el)
-{
-//    as_value(el);
-}
-
 as_value&
 as_value::newAdd(const as_value& op2)
 {
@@ -2023,7 +2018,7 @@
                                return false;
                        }
                        dub = *(reinterpret_cast<double*>(b)); b += 8;
-                       swapBytes(&dub, 8);
+                       amf::swapBytes(&dub, 8);
 #ifdef GNASH_DEBUG_AMF_PARSING
                        log_debug("amf0 read double: %e", dub);
 #endif

=== modified file 'libcore/as_value.h'
--- a/libcore/as_value.h        2008-09-04 09:14:34 +0000
+++ b/libcore/as_value.h        2008-09-04 10:48:29 +0000
@@ -169,8 +169,7 @@
        as_value(asNamespace &);
 
        /// Construct a value from an AMF element
-       as_value(amf::Element *el);
-       as_value &operator=(amf::Element *el);
+       as_value(const amf::Element& el);
        
        /// Construct a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value
        //
@@ -309,12 +308,7 @@
        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;
+       std::auto_ptr<amf::Element> to_element() const;
 
        /// Conversion to 32bit integer
        //

=== modified file 'testsuite/libcore.all/AsValueTest.cpp'
--- a/testsuite/libcore.all/AsValueTest.cpp     2008-09-04 00:35:31 +0000
+++ b/testsuite/libcore.all/AsValueTest.cpp     2008-09-04 10:48:29 +0000
@@ -123,7 +123,7 @@
     
     Element el1;
     el1.makeNumber(1.234);
-    as_value as1(&el1);
+    as_value as1(el1);
     if (as1.to_number() == el1.to_number()) {
         runtest.pass("as_value(Element &number)");
     } else {
@@ -235,7 +235,7 @@
         }
     }
 
-    Element *el1 = as1.to_element();
+    std::auto_ptr<Element> el1 = as1.to_element();
     Element *fooel = el1->getProperty(0);
     Element *barel = el1->getProperty(1);
     if ((el1->getType() == Element::OBJECT_AMF0)


reply via email to

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