incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ar...@apache.org
Subject svn commit: r1381446 - in /incubator/ooo/trunk/main: formula/inc/formula/ formula/source/core/resource/ sc/inc/ sc/source/core/inc/ sc/source/core/tool/ sc/source/ui/src/
Date Thu, 06 Sep 2012 00:35:27 GMT
Author: arist
Date: Thu Sep  6 00:35:26 2012
New Revision: 1381446

URL: http://svn.apache.org/viewvc?rev=1381446&view=rev
Log:
calcishmakkica: #i114428# implement XOR

From: Eike Rathke <erack@apache.org>

Original Author: Marina Plakalovic <makkica@openoffice.org>
Original Committer: Eike Rathke [er] <eike.rathke@oracle.com>

# HG changeset patch
# User Eike Rathke [er] <eike.rathke@oracle.com>
# Date 1284060031 -7200
# Node ID 528da6bfd0daed4355d745590d5ac3a319b08fb4
# Parent  237cb91dd986ff11eb100cc631206cda102e91f7

Modified:
    incubator/ooo/trunk/main/formula/inc/formula/compiler.hrc
    incubator/ooo/trunk/main/formula/inc/formula/opcode.hxx
    incubator/ooo/trunk/main/formula/source/core/resource/core_resource.src
    incubator/ooo/trunk/main/sc/inc/helpids.h
    incubator/ooo/trunk/main/sc/inc/scmatrix.hxx
    incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx
    incubator/ooo/trunk/main/sc/source/core/tool/interpr1.cxx
    incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx
    incubator/ooo/trunk/main/sc/source/core/tool/parclass.cxx
    incubator/ooo/trunk/main/sc/source/core/tool/scmatrix.cxx
    incubator/ooo/trunk/main/sc/source/ui/src/scfuncs.src

Modified: incubator/ooo/trunk/main/formula/inc/formula/compiler.hrc
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/formula/inc/formula/compiler.hrc?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/formula/inc/formula/compiler.hrc (original)
+++ incubator/ooo/trunk/main/formula/inc/formula/compiler.hrc Thu Sep  6 00:35:26 2012
@@ -389,9 +389,10 @@
 #define SC_OPCODE_CHISQ_DIST        393
 #define SC_OPCODE_CHISQ_INV         394
 #define SC_OPCODE_AVERAGE_IF        395
-#define SC_OPCODE_STOP_2_PAR        396
+#define SC_OPCODE_XOR               396
+#define SC_OPCODE_STOP_2_PAR        397
 
-#define SC_OPCODE_LAST_OPCODE_ID    395      /* last OpCode */
+#define SC_OPCODE_LAST_OPCODE_ID    396      /* last OpCode */
 
 /*** Interna ***/
 #define SC_OPCODE_INTERNAL_BEGIN   9999

Modified: incubator/ooo/trunk/main/formula/inc/formula/opcode.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/formula/inc/formula/opcode.hxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/formula/inc/formula/opcode.hxx (original)
+++ incubator/ooo/trunk/main/formula/inc/formula/opcode.hxx Thu Sep  6 00:35:26 2012
@@ -385,6 +385,7 @@ enum OpCodeEnum
         ocGetPivotData      = SC_OPCODE_GET_PIVOT_DATA,
         ocEuroConvert       = SC_OPCODE_EUROCONVERT,
 		ocNumberValue		= SC_OPCODE_NUMBERVALUE,
+		ocXor               = SC_OPCODE_XOR,
 	// internal stuff
 		ocInternalBegin		= SC_OPCODE_INTERNAL_BEGIN,
 		ocTTT				= SC_OPCODE_TTT,

Modified: incubator/ooo/trunk/main/formula/source/core/resource/core_resource.src
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/formula/source/core/resource/core_resource.src?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/formula/source/core/resource/core_resource.src (original)
+++ incubator/ooo/trunk/main/formula/source/core/resource/core_resource.src Thu Sep  6 00:35:26
2012
@@ -52,6 +52,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGL
 	String SC_OPCODE_GREATER_EQUAL { Text = ">=" ; };
 	String SC_OPCODE_AND { Text = "AND" ; };
 	String SC_OPCODE_OR { Text = "OR" ; };
+	String SC_OPCODE_XOR { Text = "XOR" ; };
 	String SC_OPCODE_INTERSECT { Text = "!" ; };
 	String SC_OPCODE_UNION { Text = "~" ; };
 	String SC_OPCODE_RANGE { Text = ":" ; };
@@ -381,6 +382,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGL
 	String SC_OPCODE_GREATER_EQUAL { Text = ">=" ; };
 	String SC_OPCODE_AND { Text = "AND" ; };
 	String SC_OPCODE_OR { Text = "OR" ; };
+	String SC_OPCODE_XOR { Text = "XOR" ; };
 	String SC_OPCODE_INTERSECT { Text = "!" ; };
 	String SC_OPCODE_UNION { Text = "~" ; };
 	String SC_OPCODE_RANGE { Text = ":" ; };
@@ -719,6 +721,10 @@ Resource RID_STRLIST_FUNCTION_NAMES
 	{
 		Text [ en-US ] = "OR" ;
 	};
+	String SC_OPCODE_XOR
+	{
+		Text [ en-US ] = "XOR" ;
+	};
 	String SC_OPCODE_INTERSECT { Text = "!" ; };
 	String SC_OPCODE_UNION { Text = "~" ; };
 	String SC_OPCODE_RANGE { Text = ":" ; };

Modified: incubator/ooo/trunk/main/sc/inc/helpids.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/helpids.h?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/helpids.h (original)
+++ incubator/ooo/trunk/main/sc/inc/helpids.h Thu Sep  6 00:35:26 2012
@@ -486,6 +486,7 @@
 #define HID_FUNC_WENN                                           "SC_HID_FUNC_WENN"
 #define HID_FUNC_ODER                                           "SC_HID_FUNC_ODER"
 #define HID_FUNC_UND                                            "SC_HID_FUNC_UND"
+#define HID_FUNC_XOR                                            "SC_HID_FUNC_XOR"
 
 #define HID_FUNC_ABS                                            "SC_HID_FUNC_ABS"
 #define HID_FUNC_POTENZ                                         "SC_HID_FUNC_POTENZ"

Modified: incubator/ooo/trunk/main/sc/inc/scmatrix.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/scmatrix.hxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/scmatrix.hxx (original)
+++ incubator/ooo/trunk/main/sc/inc/scmatrix.hxx Thu Sep  6 00:35:26 2012
@@ -426,6 +426,7 @@ public:
 
     double And();       // logical AND of all matrix values, or NAN
     double Or();        // logical OR of all matrix values, or NAN
+    double Xor();       // logical XOR of all matrix values, or NAN
 
     // All other matrix functions  MatMult, MInv, ...  are in ScInterpreter
     // to be numerically safe.

Modified: incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx Thu Sep  6 00:35:26 2012
@@ -386,6 +386,7 @@ void ScLessEqual();
 void ScGreaterEqual();
 void ScAnd();
 void ScOr();
+void ScXor();
 void ScNot();
 void ScNeg();
 void ScPercentSign();

Modified: incubator/ooo/trunk/main/sc/source/core/tool/interpr1.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/interpr1.cxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/interpr1.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/interpr1.cxx Thu Sep  6 00:35:26 2012
@@ -1332,6 +1332,106 @@ void ScInterpreter::ScOr()
     }
 }
 
+void ScInterpreter::ScXor()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "makkica", "ScInterpreter::ScXor" );
+    nFuncFmtType = NUMBERFORMAT_LOGICAL;
+    short nParamCount = GetByte();
+    if ( MustHaveParamCountMin( nParamCount, 1 ) )
+    {
+        bool bHaveValue = false;
+        short nRes = 0;
+        size_t nRefInList = 0;
+        while( nParamCount-- > 0)
+        {
+            if ( !nGlobalError )
+            {
+                switch ( GetStackType() )
+                {
+                    case svDouble :
+                        bHaveValue = true;
+                        nRes ^= ( PopDouble() != 0.0 );
+                        break;
+                    case svString :
+                        Pop();
+                        SetError( errNoValue );
+                        break;
+                    case svSingleRef :
+                        {
+                            ScAddress aAdr;
+                            PopSingleRef( aAdr );
+                            if ( !nGlobalError )
+                            {
+                                ScBaseCell* pCell = GetCell( aAdr );
+                                if ( HasCellValueData( pCell ) )
+                                {
+                                    bHaveValue = true;
+                                    nRes ^= ( GetCellValue( aAdr, pCell ) != 0.0 );
+                                }
+                                /* TODO: set error? Excel doesn't have XOR, but
+                                 * doesn't set an error in this case for AND and
+                                 * OR. */
+                            }
+                        }
+                        break;
+                    case svDoubleRef:
+                    case svRefList:
+                        {
+                            ScRange aRange;
+                            PopDoubleRef( aRange, nParamCount, nRefInList);
+                            if ( !nGlobalError )
+                            {
+                                double fVal;
+                                sal_uInt16 nErr = 0;
+                                ScValueIterator aValIter( pDok, aRange );
+                                if ( aValIter.GetFirst( fVal, nErr ) )
+                                {
+                                    bHaveValue = true;
+                                    do
+                                    {
+                                        nRes ^= ( fVal != 0.0 );
+                                    } while ( (nErr == 0) &&
+                                            aValIter.GetNext( fVal, nErr ) );
+                                }
+                                SetError( nErr );
+                            }
+                        }
+                        break;
+                    case svMatrix:
+                        {
+                            bHaveValue = true;
+                            ScMatrixRef pMat = GetMatrix();
+                            if ( pMat )
+                            {
+                                bHaveValue = true;
+                                double fVal = pMat->Xor();
+                                sal_uInt16 nErr = GetDoubleErrorValue( fVal );
+                                if ( nErr )
+                                {
+                                    SetError( nErr );
+                                    nRes = 0;
+                                }
+                                else
+                                    nRes ^= (fVal != 0.0);
+                            }
+                            // else: GetMatrix did set errIllegalParameter
+                        }
+                        break;
+                    default:
+                        Pop();
+                        SetError( errIllegalParameter);
+                }
+            }
+            else
+                Pop();
+        }
+        if ( bHaveValue )
+            PushInt( nRes );
+        else
+            PushNoValue();
+    }
+}
+
 
 void ScInterpreter::ScNeg()
 {

Modified: incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx Thu Sep  6 00:35:26 2012
@@ -3446,6 +3446,7 @@ StackVar ScInterpreter::Interpret()
                 case ocGreaterEqual     : ScGreaterEqual();             break;
                 case ocAnd              : ScAnd();                      break;
                 case ocOr               : ScOr();                       break;
+                case ocXor              : ScXor();                      break;
                 case ocIntersect        : ScIntersect();                break;
                 case ocRange            : ScRangeFunc();                break;
                 case ocUnion            : ScUnionFunc();                break;

Modified: incubator/ooo/trunk/main/sc/source/core/tool/parclass.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/parclass.cxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/parclass.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/parclass.cxx Thu Sep  6 00:35:26 2012
@@ -79,6 +79,7 @@ const ScParameterClassification::RawData
     { ocAveDev,          {{ Reference                                            }, true
}},
     { ocAverage,         {{ Reference                                            }, true
}},
     { ocAverageA,        {{ Reference                                            }, true
}},
+    { ocAverageIf,       {{ Reference, Value, Reference                          }, false
}},
     { ocCell,            {{ Value, Reference                                     }, false
}},
     { ocColumn,          {{ Reference                                            }, false
}},
     { ocColumns,         {{ Reference                                            }, true
}},
@@ -173,7 +174,6 @@ const ScParameterClassification::RawData
     { ocSubTotal,        {{ Value, Reference                                     }, true
}},
     { ocSum,             {{ Reference                                            }, true
}},
     { ocSumIf,           {{ Reference, Value, Reference                          }, false
}},
-    { ocAverageIf,       {{ Reference, Value, Reference                          }, false
}},
     { ocSumProduct,      {{ ForceArray                                           }, true
}},
     { ocSumSQ,           {{ Reference                                            }, true
}},
     { ocSumX2MY2,        {{ ForceArray, ForceArray                               }, false
}},
@@ -189,6 +189,7 @@ const ScParameterClassification::RawData
     { ocVarP,            {{ Reference                                            }, true
}},
     { ocVarPA,           {{ Reference                                            }, true
}},
     { ocVLookup,         {{ Value, Reference, Value, Value                       }, false
}},
+    { ocXor,             {{ Reference                                            }, true
}},
     { ocZTest,           {{ Reference, Value, Value                              }, false
}},
     // Excel doubts:
     // ocT: Excel says (and handles) Reference, error? This means no position

Modified: incubator/ooo/trunk/main/sc/source/core/tool/scmatrix.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/scmatrix.cxx?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/scmatrix.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/scmatrix.cxx Thu Sep  6 00:35:26 2012
@@ -852,3 +852,32 @@ double ScMatrix::Or()
 	}
 	return bOr;
 }
+
+// @Author Marina Plakalovic
+// Computes the logical XOR of elements
+double ScMatrix::Xor()
+{
+    SCSIZE n = nColCount * nRowCount;
+    bool bXor = false;
+    if ( mnValType )
+    {
+        for ( SCSIZE j=0; j<n; j++ )
+            if ( !IsValueType( mnValType[j]) )
+            {   // assuming a CompareMat this is an error
+                return CreateDoubleError( errIllegalArgument );
+            }
+            else if ( ::rtl::math::isFinite( pMat[j].fVal))
+                bXor ^= (pMat[j].fVal != 0.0);
+            else
+                return pMat[j].fVal;    // DoubleError
+    }
+    else
+    {
+        for ( SCSIZE j=0; j<n; j++ )
+            if ( ::rtl::math::isFinite( pMat[j].fVal))
+                bXor ^= (pMat[j].fVal != 0.0);
+            else
+                return pMat[j].fVal;    // DoubleError
+    }
+    return bXor;
+}

Modified: incubator/ooo/trunk/main/sc/source/ui/src/scfuncs.src
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/src/scfuncs.src?rev=1381446&r1=1381445&r2=1381446&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/src/scfuncs.src (original)
+++ incubator/ooo/trunk/main/sc/source/ui/src/scfuncs.src Thu Sep  6 00:35:26 2012
@@ -2656,6 +2656,31 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS1
 			Text [ en-US ] = "Logical value 1, logical value 2;...are 1 to 30 conditions to be tested
and each returns either TRUE or FALSE." ;
 		};
 	};
+
+	// -=*# Resource for function XOR #*=-
+	Resource SC_OPCODE_XOR
+	{
+		String 1 // Description
+		{
+			Text [ en-US ] = "Returns TRUE if exactly one of the arguments is TRUE." ;
+		};
+		ExtraData =
+		{
+            0;
+			ID_FUNCTION_GRP_LOGIC;
+			U2S( HID_FUNC_XOR );
+			VAR_ARGS;	0;
+            0;
+		};
+		String 2 // Name of Parameter 1
+		{
+			Text [ en-US ] = "Logical value " ;
+		};
+		String 3 // Description of Parameter 1
+		{
+			Text [ en-US ] = "Logical value 1, logical value 2,... are 1 to 30 conditions to be tested
and which return either TRUE or FALSE." ;
+		};
+	};
      // -=*# Resource for function ABS #*=-
 	Resource SC_OPCODE_ABS
 	{



Mime
View raw message