commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r779478 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp
Date Thu, 28 May 2009 08:33:40 GMT
Author: mturk
Date: Thu May 28 08:33:40 2009
New Revision: 779478

URL: http://svn.apache.org/viewvc?rev=779478&view=rev
Log:
Use OLE macros instead directly referencing VARIANT struct members

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp?rev=779478&r1=779477&r2=779478&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp Thu May 28 08:33:40
2009
@@ -48,7 +48,26 @@
     if (!v)
         return 0;
     VariantInit(v);
-    return  ACR_PointerCreate(_E, v, 0, variant_callback);
+    return ACR_PointerCreate(_E, v, 0, variant_callback);
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jobject, VARIANT, alloc1)(ACR_JNISTDARGS, jstring str)
+{
+    jobject r = NULL;
+    VARIANT *v = (VARIANT *)ACR_Calloc(_E, THROW_FMARK, sizeof(VARIANT));
+
+    UNREFERENCED_O;
+    if (!v)
+        return 0;
+    WITH_WSTR(str) {
+        VariantInit(v);
+        V_VT(v)   = VT_BSTR;
+        V_BSTR(v) = SysAllocString(J2W(str));
+        r = ACR_PointerCreate(_E, v, 0, variant_callback);
+    } END_WITH_WSTR(str);
+
+    return r;
 }
 
 extern "C"
@@ -57,7 +76,7 @@
     VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
 
     if (v)
-        return v->vt;
+        return V_VT(v);
     else
         return VT_NULL;
 }
@@ -69,47 +88,47 @@
 
     if (!v)
         return 0;
-    switch (v->vt) {
+    switch (V_VT(v)) {
         case VT_BOOL:
-            return v->boolVal;
+            return V_BOOL(v);
         break;
         case VT_I1:
         case VT_UI1:
-            return v->bVal;
+            return V_UI1(v);
         break;
         case VT_I2:
-            return v->iVal;
+            return V_I2(v);
         break;
         case VT_UI2:
-            return v->uiVal;
+            return V_UI2(v);
         break;
         case VT_I4:
-            return v->lVal;
+            return V_I4(v);
         break;
         case VT_UI4:
-            return v->ulVal;
+            return V_UI4(v);
         break;
         case VT_INT:
-            return v->intVal;
+            return V_INT(v);
         break;
         case VT_UINT:
-            return v->uintVal;
+            return V_UINT(v);
         break;
         case VT_R4:
-            return (int)(v->fltVal);
+            return (int)(V_R4(v));
         break;
         case VT_R8:
-            return (int)(v->dblVal);
+            return (int)(V_R8(v));
         break;
         case VT_ERROR:
-            return (int)(v->scode);
+            return (int)(V_ERROR(v));
         break;
         case VT_BSTR:
-            return SysStringLen(v->bstrVal);
+            return SysStringLen(V_BSTR(v));
         break;
     }
-    if (v->vt & VT_ARRAY) {
-        SAFEARRAY *sa = v->parray;
+    if (V_ISARRAY(v)) {
+        SAFEARRAY *sa = V_ARRAY(v);
         long lb, ub;
 
         SafeArrayGetLBound(sa, 1, &lb);
@@ -128,56 +147,59 @@
 
     if (!v)
         return 0;
-    switch (v->vt) {
+    switch (V_VT(v)) {
         case VT_BOOL:
-            return v->boolVal;
+            return V_BOOL(v);
         break;
         case VT_I1:
         case VT_UI1:
-            return v->bVal;
+            return V_UI1(v);
         break;
         case VT_I2:
-            return v->iVal;
+            return V_I2(v);
         break;
         case VT_UI2:
-            return v->uiVal;
+            return V_UI2(v);
         break;
         case VT_I4:
-            return v->lVal;
+            return V_I4(v);
         break;
         case VT_UI4:
-            return v->ulVal;
+            return V_UI4(v);
         break;
         case VT_I8:
-            return v->llVal;
+            return V_I8(v);
         break;
         case VT_UI8:
-            return v->ullVal;
+            return (jlong)V_I8(v);
         break;
         case VT_INT:
-            return v->intVal;
+            return V_INT(v);
         break;
         case VT_UINT:
-            return v->uintVal;
+            return V_UINT(v);
         break;
         case VT_R4:
-            return (jlong)(v->fltVal);
+            return (jlong)(V_R4(v));
         break;
         case VT_R8:
-            return (jlong)(v->dblVal);
+            return (jlong)(V_R8(v));
         break;
         case VT_CY:
-            return v->cyVal.int64;
+            return V_CY(v).int64;
         break;
         case VT_ERROR:
-            return v->scode;
+            return V_ERROR(v);
+        break;
+        case VT_DATE:
+            return (jlong)V_DATE(v);
         break;
         case VT_BSTR:
-            return SysStringLen(v->bstrVal);
+            return SysStringLen(V_BSTR(v));
         break;
     }
-    if (v->vt & VT_ARRAY) {
-        SAFEARRAY *sa = v->parray;
+    if (V_ISARRAY(v)) {
+        SAFEARRAY *sa = V_ARRAY(v);
         long lb, ub;
 
         SafeArrayGetLBound(sa, 1, &lb);
@@ -190,21 +212,81 @@
 }
 
 extern "C"
+ACR_JNI_PLATFORM_DECLARE(jdouble, VARIANT, getdv0)(ACR_JNISTDARGS)
+{
+    VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
+
+    if (!v)
+        return 0.0;
+    switch (V_VT(v)) {
+        case VT_BOOL:
+            return V_BOOL(v) * 1.0;
+        break;
+        case VT_I1:
+        case VT_UI1:
+            return V_UI1(v);
+        break;
+        case VT_I2:
+            return V_I2(v);
+        break;
+        case VT_UI2:
+            return V_UI2(v);
+        break;
+        case VT_I4:
+            return V_I4(v);
+        break;
+        case VT_UI4:
+            return V_UI4(v);
+        break;
+        case VT_I8:
+            return (double)V_I8(v);
+        break;
+        case VT_UI8:
+            return (double)((jlong)V_I8(v));
+        break;
+        case VT_INT:
+            return V_INT(v);
+        break;
+        case VT_UINT:
+            return V_UINT(v);
+        break;
+        case VT_R4:
+            return (double)V_R4(v);
+        break;
+        case VT_R8:
+            return V_R8(v);
+        break;
+        case VT_CY:
+            return (double)V_CY(v).int64;
+        break;
+        case VT_ERROR:
+            return V_ERROR(v);
+        break;
+        case VT_DATE:
+            return V_DATE(v);
+        break;
+    }
+    return 0.0;
+}
+
+extern "C"
 ACR_JNI_PLATFORM_DECLARE(jstring, VARIANT, getsv0)(ACR_JNISTDARGS)
 {
     jstring s = NULL;
-    HRESULT  r;
-    VARIANT  c;
+    HRESULT r;
+    VARIANT c;
     VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
 
     if (!v)
         return 0;
-    switch (v->vt) {
+    switch (V_VT(v)) {
+        case VT_NULL:
+        break;
         case VT_EMPTY:
             s = _E->NewString(L"", 0);
         break;
         case VT_BSTR:
-            s = _E->NewString(v->bstrVal, SysStringLen(v->bstrVal));
+            s = _E->NewString(V_BSTR(v), SysStringLen(V_BSTR(v)));
         break;
         default:
             VariantInit(&c);
@@ -212,11 +294,12 @@
                                   VARIANT_ALPHABOOL | VARIANT_NOUSEROVERRIDE,
                                   VT_BSTR);
             if (SUCCEEDED(r)) {
-                s = _E->NewString(c.bstrVal, SysStringLen(c.bstrVal));
+                s = _E->NewString(V_BSTR(&c), SysStringLen(V_BSTR(&c)));
                 VariantClear(&c);
             }
             else {
                 /* TODO: Pick Exception to be thrown
+                 * for conversion error.
                  */
             }
         break;



Mime
View raw message