[PATCH spice-xpi 1/6] add parseInt() and parseFloat() into Generator::generateConnectVars() output

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

 



Javascript proper casting.

---
 generator/generator.cpp | 34 ++++++++++++++++++++++++++++++----
 generator/generator.h   |  1 +
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/generator/generator.cpp b/generator/generator.cpp
index ee3eedd..48b34d2 100644
--- a/generator/generator.cpp
+++ b/generator/generator.cpp
@@ -157,11 +157,14 @@ void Generator::generateConnectVars()
     for (it = m_attributes.begin(); it != m_attributes.end(); ++it) {
         std::cout << "    embed." << it->getIdentifier() << " = "
                   << "document.getElementById(\""
-                  << it->getIdentifier() << "Toggled\").checked ? "
-                  << "document.getElementById(\""
+                  << it->getIdentifier() << "Toggled\").checked ? ";
+        bool generated_cast = generateConnectVarsParse(*it);
+        std::cout << "document.getElementById(\""
                   << it->getIdentifier() << "\")."
-                  << (it->getType() == Token::T_BOOLEAN ? "checked" : "value")
-                  << " : \"\";\n";
+                  << (it->getType() == Token::T_BOOLEAN ? "checked" : "value");
+        if (generated_cast)
+            std::cout << ")";
+        std::cout << " : \"\";\n";
     }
     std::cout << "}\n\n</script>\n\n";
 }
@@ -280,3 +283,26 @@ bool Generator::methodEnabled(const Method &method, const Method::MethodParam &p
     std::set<std::string>::iterator found = s_default_methods.find(id);
     return found != s_default_methods.end();
 }
+
+bool Generator::generateConnectVarsParse(const Attribute &attr)
+{
+    switch (attr.getType()) {
+    case Token::T_FLOAT:
+    case Token::T_DOUBLE:
+        std::cout << "parseFloat(";
+        return true;
+    case Token::T_UNSIGNED:
+    case Token::T_SHORT:
+    case Token::T_LONG:
+    case Token::T_LONG_LONG:
+    case Token::T_OCTET:
+    case Token::T_NUMBER:
+    case Token::T_UNSIGNED_SHORT:
+    case Token::T_UNSIGNED_LONG:
+    case Token::T_UNSIGNED_LONG_LONG:
+        std::cout << "parseInt(";
+        return true;
+    }
+
+    return false;
+}
diff --git a/generator/generator.h b/generator/generator.h
index 0a9bd3f..3dfde3a 100644
--- a/generator/generator.h
+++ b/generator/generator.h
@@ -47,6 +47,7 @@ private:
     static std::string attributeToHtmlElement(const Attribute &attr);
     static bool attributeEnabled(const Attribute &attr);
     static bool methodEnabled(const Method &method, const Method::MethodParam &param);
+    static bool generateConnectVarsParse(const Attribute &attr);
 
 private:
     std::list<Attribute> m_attributes;
-- 
Peter Hatina
ENG Server Experience, System Management
Red Hat Czech, Brno

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]