gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10762: Various improvements to cons


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10762: Various improvements to const correctness, function signatures and
Date: Thu, 02 Apr 2009 10:50:53 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10762
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2009-04-02 10:50:53 +0200
message:
  Various improvements to const correctness, function signatures and 
  code reuse.
modified:
  libcore/TextField.cpp
  libcore/TextField.h
  libcore/asobj/Mouse_as.cpp
  libcore/asobj/System_as.cpp
  libcore/movie_root.h
  libcore/swf/TextRecord.cpp
    ------------------------------------------------------------
    revno: 10758.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-04-02 09:42:17 +0200
    message:
      Const correct.
    modified:
      libcore/swf/TextRecord.cpp
    ------------------------------------------------------------
    revno: 10758.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-04-02 09:42:23 +0200
    message:
      More const correction.
    modified:
      libcore/TextField.cpp
      libcore/TextField.h
    ------------------------------------------------------------
    revno: 10758.1.7
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-04-02 10:16:17 +0200
    message:
      Make the second argument to the interface call() function optional, as 
it's
      often not used. Clean up System object.
    modified:
      libcore/asobj/System_as.cpp
      libcore/movie_root.h
    ------------------------------------------------------------
    revno: 10758.1.8
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-04-02 10:18:16 +0200
    message:
      Do the same for Mouse object.
    modified:
      libcore/asobj/Mouse_as.cpp
=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2009-03-17 12:01:42 +0000
+++ b/libcore/TextField.cpp     2009-04-02 07:42:23 +0000
@@ -292,15 +292,15 @@
 
     registerTextVariable();
 
-    bool drawBorder = getDrawBorder();
-    bool drawBackground = getDrawBackground();
+    const bool drawBorder = getDrawBorder();
+    const bool drawBackground = getDrawBackground();
 
-    SWFMatrix wmat = getWorldMatrix();
+    const SWFMatrix& wmat = getWorldMatrix();
 
     if ((drawBorder || drawBackground) && !_bounds.is_null())
     {
 
-        point coords[4];
+        std::vector<point> coords(4);
 
         boost::int32_t xmin = _bounds.get_x_min();
         boost::int32_t xmax = _bounds.get_x_max();
@@ -326,7 +326,7 @@
     log_debug("rendering a Pol composed by corners %s", _bounds);
 #endif
 
-        render::draw_poly( &coords[0], 4, backgroundColor, 
+        render::draw_poly(&coords.front(), 4, backgroundColor, 
                 borderColor, wmat, true);
         
     }
@@ -359,12 +359,12 @@
     
     ranges.add(m_old_invalidated_ranges);
 
-    SWFMatrix wm = getWorldMatrix();
+    const SWFMatrix& wm = getWorldMatrix();
 
     rect bounds = getBounds();
     bounds.expand_to_rect(m_text_bounding_box); 
     wm.transform(bounds);
-    ranges.add( bounds.getRange() );            
+    ranges.add(bounds.getRange());            
 }
 
 void
@@ -1685,10 +1685,9 @@
 
     // If using a device font (PP compatibility), do not take parent cxform
     // into account.
-    if (!getEmbedFonts()) {
-        return cxform();
-    }
-    else return character::get_world_cxform();
+    if (!getEmbedFonts()) return cxform();
+
+    return character::get_world_cxform();
 }
 
 void

=== modified file 'libcore/TextField.h'
--- a/libcore/TextField.h       2009-02-26 18:48:57 +0000
+++ b/libcore/TextField.h       2009-04-02 07:42:23 +0000
@@ -607,7 +607,7 @@
        VariableRef parseTextVariableRef(const std::string& variableName) const;
        
        // Text fields need to handle cxform specially 
-       cxform  get_world_cxform() const;
+       virtual cxform get_world_cxform() const;
 
        /// The flag keeping status of TextVariable registration
        //

=== modified file 'libcore/asobj/Mouse_as.cpp'
--- a/libcore/asobj/Mouse_as.cpp        2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/Mouse_as.cpp        2009-04-02 08:18:16 +0000
@@ -92,11 +92,9 @@
 {
     boost::intrusive_ptr<as_object> obj = ensureType<as_object>(fn.this_ptr);
 
-    int success = 0;
-
     movie_root& m = obj->getVM().getRoot();
 
-    success = (m.callInterface("Mouse.hide", "") == "true") ? 1 : 0;
+    const int success = (m.callInterface("Mouse.hide") == "true") ? 1 : 0;
 
     // returns 1 if mouse was visible before call.
     return as_value(success);
@@ -110,11 +108,9 @@
 {
     boost::intrusive_ptr<as_object> obj=ensureType<as_object>(fn.this_ptr);
 
-    int success = 0;
-
     movie_root& m = obj->getVM().getRoot();
 
-    success = (m.callInterface("Mouse.show", "") == "true") ? 1 : 0;
+    const int success = (m.callInterface("Mouse.show") == "true") ? 1 : 0;
 
     // returns 1 if Mouse was visible before call.
     return as_value(success);

=== modified file 'libcore/asobj/System_as.cpp'
--- a/libcore/asobj/System_as.cpp       2009-02-25 22:33:03 +0000
+++ b/libcore/asobj/System_as.cpp       2009-04-02 08:16:17 +0000
@@ -27,25 +27,44 @@
 #include "VM.h" // for getPlayerVersion() 
 #include "Object.h" // for getObjectInterface
 
-inline std::string
-trueFalse(bool x)
-{
-    return x ? "t" : "f";
-}
-
 namespace gnash {
 
-static const std::string& systemLanguage(as_object& proto);
-
-static as_value system_security_allowdomain(const fn_call& fn);
-static as_value system_security_allowinsecuredomain(const fn_call& fn);
-static as_value system_security_loadpolicyfile(const fn_call& fn);
-static as_value system_setclipboard(const fn_call& fn);
-static as_value system_showsettings(const fn_call& fn);
-static as_value system_exactsettings(const fn_call& fn);
-static as_value system_usecodepage(const fn_call& fn);
-
-void registerSystemNative(as_object& global)
+// Forward declarations.
+namespace {
+
+    inline std::string trueFalse(bool x) { return x ? "t" : "f"; }
+
+    template<typename T> inline void convertValue(const std::string& in,
+            T& val);
+
+    const std::string& systemLanguage(as_object& proto);
+
+    as_value system_security_allowdomain(const fn_call& fn);
+    as_value system_security_allowinsecuredomain(const fn_call& fn);
+    as_value system_security_loadpolicyfile(const fn_call& fn);
+    as_value system_setclipboard(const fn_call& fn);
+    as_value system_showsettings(const fn_call& fn);
+    as_value system_exactsettings(const fn_call& fn);
+    as_value system_usecodepage(const fn_call& fn);
+    as_object* getSystemSecurityInterface(as_object& o);
+    as_object* getSystemCapabilitiesInterface(as_object& o);
+    void attachSystemInterface(as_object& proto);
+}
+
+
+void
+system_class_init(as_object& global)
+{
+       // _global.System is NOT a class, but a simple object, see System.as
+
+       boost::intrusive_ptr<as_object> obj = new 
as_object(getObjectInterface());
+       attachSystemInterface(*obj);
+       global.init_member("System", obj.get());
+}
+
+
+void
+registerSystemNative(as_object& global)
 {
     VM& vm = global.getVM();
     
@@ -63,7 +82,9 @@
     // System.Product.download 2201, 3    
 }
 
-static as_object*
+namespace {
+
+as_object*
 getSystemSecurityInterface(as_object& o)
 {
     VM& vm = o.getVM();
@@ -75,14 +96,16 @@
                proto->init_member("allowDomain", vm.getNative(12, 0));
 
                // TODO: only available when SWF >= 7 
-               proto->init_member("allowInsecureDomain", new 
builtin_function(system_security_allowinsecuredomain));
+               proto->init_member("allowInsecureDomain",
+                new builtin_function(system_security_allowinsecuredomain));
 
-               proto->init_member("loadPolicyFile", new 
builtin_function(system_security_loadpolicyfile));
+               proto->init_member("loadPolicyFile",
+                new builtin_function(system_security_loadpolicyfile));
        }
        return proto.get();
 }
 
-static as_object*
+as_object*
 getSystemCapabilitiesInterface(as_object& o)
 {
        RcInitFile& rcfile = RcInitFile::getDefaultInstance();
@@ -120,44 +143,34 @@
     // Display information (needs active GUI)
     //
 
+    const movie_root& m = vm.getRoot();
+
+    int screenResolutionX;
+    convertValue(m.callInterface("System.capabilities.screenResolutionX"),
+            screenResolutionX);
+    int screenResolutionY;
+    convertValue(m.callInterface("System.capabilities.screenResolutionY"),
+            screenResolutionY);
+    int screenDPI;
+    convertValue(m.callInterface("System.capabilities.screenDPI"), screenDPI);
+        
     // Documented to be a number, but is in fact a string.
-    std::string pixelAspectRatio;
+    const std::string pixelAspectRatio = 
+        m.callInterface("System.capabilities.pixelAspectRatio");
 
     // "StandAlone", "External", "PlugIn", "ActiveX" (get from GUI)
-    std::string playerType;
-    
-    std::string screenColor;
-    
-    int screenDPI = 0;
-
-    int screenResolutionX = 0;
-    int screenResolutionY = 0;
-
-    std::istringstream ss;
-
-    const movie_root& m = vm.getRoot();
-
-    ss.str(m.callInterface("System.capabilities.screenResolutionX", ""));
-    ss >> screenResolutionX;
-        
-    ss.clear();
-    ss.str(m.callInterface("System.capabilities.screenResolutionY", ""));
-    ss >> screenResolutionY;
-
-    ss.clear();
-    ss.str(m.callInterface("System.capabilities.screenDPI", ""));
-    ss >> screenDPI;
-        
-    pixelAspectRatio = m.callInterface("System.capabilities.pixelAspectRatio", 
"");
-    playerType = m.callInterface("System.capabilities.playerType", "");
-    screenColor = m.callInterface("System.capabilities.screenColor", "");
+    const std::string playerType =
+        m.callInterface("System.capabilities.playerType");
+
+    const std::string screenColor =
+        m.callInterface("System.capabilities.screenColor");
 
     //
     // Media
     //
         
     // Is audio available?
-    const bool hasAudio = (vm.getRoot().runInfo().soundHandler() != NULL);
+    const bool hasAudio = (vm.getRoot().runInfo().soundHandler());
 
     // FIXME: these need to be implemented properly. They are mostly
     // self-explanatory.
@@ -272,22 +285,38 @@
        return proto.get();
 }
 
-static void
+/// Convert a string to the type passed in, making sure the target variable
+/// is initialized.
+template<typename T>
+inline void
+convertValue(const std::string& in, T& val)
+{
+    val = T();
+    std::istringstream is(in);
+    is >> val;
+} 
+
+void
 attachSystemInterface(as_object& proto)
 {
        VM& vm = proto.getVM();
-    const int version = vm.getSWFVersion();
 
        proto.init_member("security", getSystemSecurityInterface(proto));
        proto.init_member("capabilities", 
getSystemCapabilitiesInterface(proto));
-       proto.init_member("setClipboard", new 
builtin_function(system_setclipboard));
+       proto.init_member("setClipboard", 
+            new builtin_function(system_setclipboard));
        proto.init_member("showSettings", vm.getNative(2107, 0));
 
-       proto.init_property("useCodepage", &system_usecodepage, 
&system_usecodepage);
-
-    if (version < 6) return;
-
-    proto.init_property("exactSettings", &system_exactsettings, 
&system_exactsettings);
+       proto.init_property("useCodepage", &system_usecodepage,
+            &system_usecodepage);
+
+    const int flags = as_prop_flags::dontDelete
+                    | as_prop_flags::dontEnum
+                    | as_prop_flags::readOnly
+                    | as_prop_flags::onlySWF6Up;
+
+    proto.init_property("exactSettings", &system_exactsettings,
+            &system_exactsettings, flags);
 
 }
 
@@ -339,7 +368,8 @@
 as_value
 system_exactsettings(const fn_call& fn)
 {
-       static boost::intrusive_ptr<as_object> obj = 
ensureType<as_object>(fn.this_ptr);
+       static boost::intrusive_ptr<as_object> obj =
+        ensureType<as_object>(fn.this_ptr);
 
     // Getter
     if (fn.nargs == 0)
@@ -363,7 +393,8 @@
 as_value
 system_usecodepage(const fn_call& fn)
 {
-       static boost::intrusive_ptr<as_object> obj = 
ensureType<as_object>(fn.this_ptr);
+       boost::intrusive_ptr<as_object> obj = 
+        ensureType<as_object>(fn.this_ptr);
 
     // Getter
     if (fn.nargs == 0)
@@ -381,23 +412,14 @@
 }
 
 
-void
-system_class_init(as_object& global)
-{
-       // _global.System is NOT a class, but a simple object, see System.as
-
-       static boost::intrusive_ptr<as_object> obj = new 
as_object(getObjectInterface());
-       attachSystemInterface(*obj);
-       global.init_member("System", obj.get());
-}
-
 
 const std::string&
 systemLanguage(as_object& proto)
 {
        // Two-letter language code ('en', 'de') corresponding to ISO 639-1
        // Chinese can be either zh-CN or zh-TW. English used to have a 
-       // country (GB, US) qualifier, but that was dropped in version 7 of the 
player.
+       // country (GB, US) qualifier, but that was dropped in version 7 of
+    // the player.
        // This method relies on getting a POSIX-style language code of the form
        // "zh_TW.utf8", "zh_CN" or "it" from the VM.
        // It is obviously very easy to extend support to all language codes, 
but
@@ -441,4 +463,5 @@
 
 }
 
-} // end of gnash namespace
+} // anonymous namespace
+} // gnash namespace

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2009-03-14 15:20:39 +0000
+++ b/libcore/movie_root.h      2009-04-02 08:16:17 +0000
@@ -734,7 +734,8 @@
             const std::string& arg) const;
 
     /// Abstract base class for hosting app handler
-    class AbstractIfaceCallback {
+    class AbstractIfaceCallback
+    {
     public:
 
         /// Get Gui-related information for the core.
@@ -743,7 +744,7 @@
         /// Mouse.hide, System.capabilities etc. The return can be
         /// various types, so it is passed as a string.
         virtual std::string call(const std::string& cmd,
-                const std::string& arg) = 0;
+                const std::string& arg = std::string()) = 0;
 
         /// Ask the hosting application for a yes / no answer to
         /// a question.

=== modified file 'libcore/swf/TextRecord.cpp'
--- a/libcore/swf/TextRecord.cpp        2009-03-11 10:36:40 +0000
+++ b/libcore/swf/TextRecord.cpp        2009-04-02 07:42:17 +0000
@@ -152,7 +152,7 @@
     mat.concatenate(this_mat);
 
     cxform cx = inst->get_world_cxform();
-    SWFMatrix base_matrix = mat;
+    const SWFMatrix base_matrix = mat;
 
     // Starting positions.
     float x = 0.0f;


reply via email to

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