[Libreoffice-commits] core.git: officecfg/registry sc/source
Tor Lillqvist
tml at collabora.com
Fri Jan 23 03:59:10 PST 2015
officecfg/registry/schema/org/openoffice/Office/Calc.xcs | 10 +-
sc/source/core/tool/calcconfig.cxx | 56 ++-------------
sc/source/core/tool/formulaopt.cxx | 4 -
3 files changed, 15 insertions(+), 55 deletions(-)
New commits:
commit 34a6096dab1b2bb122318cc0027c11c5cbcbb516
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Jan 23 12:47:52 2015 +0200
Use symbolic (not numeric) opcodes in the registry for the OpenCL use subset
Makes it easier to edit them manually directly in the registry files.
(Something end-users are of course not expected to do, but admins or hackers
may want to do.) Also guards against the possibility of the numeric values of
the opcodes being changed. I figured out how to do the mapping from symbolic
names to enum values and back without an ScDocument, turned out it was not
complicated after all.
Change-Id: I8bd97f256f7d777162c1b629bf82285544e86d70
diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index 4e20f9e..7ef9afb 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -1368,12 +1368,12 @@
<prop oor:name="OpenCLSubsetOpCodes" oor:type="xs:string" oor:nillable="false">
<!-- UIHints: Tools - Options Spreadsheet Formula -->
<info>
- <desc>The list of operator and function opcodes for which to use OpenCL. If a
- formula contains only these operators and functions, it
- might be calculated using OpenCL.</desc>
- <!-- numeric values correspond to RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;NORMDIST;SUMIFS -->
+ <desc>The list of operator and function opcodes (in
+ English) for which to use OpenCL. If OpenCLSubsetOnly is
+ true, and a formula contains only these operators and
+ functions, it might be calculated using OpenCL.</desc>
</info>
- <value>66;82;83;84;88;102;103;104;149;204;209;213;222;223;224;225;226;227;236;403</value>
+ <value>RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;NORMDIST;SUMIFS</value>
</prop>
<prop oor:name="OpenCLAutoSelect" oor:type="xs:boolean" oor:nillable="false">
<!-- UIHints: Tools - Options Spreadsheet Formula -->
diff --git a/sc/source/core/tool/calcconfig.cxx b/sc/source/core/tool/calcconfig.cxx
index f380d13..4e9292a 100644
--- a/sc/source/core/tool/calcconfig.cxx
+++ b/sc/source/core/tool/calcconfig.cxx
@@ -110,46 +110,11 @@ std::ostream& operator<<(std::ostream& rStream, const ScCalcConfig& rConfig)
return rStream;
}
-namespace {
-
-formula::FormulaCompiler::OpCodeMapPtr setup()
-{
- SfxObjectShell* pObjShell = SfxObjectShell::Current();
- ScDocShell* pScDocShell = PTR_CAST(ScDocShell, pObjShell);
-
- if (pScDocShell)
- {
- ScDocument& rDoc(pScDocShell->GetDocument());
- ScCompiler* pComp(new ScCompiler(&rDoc, ScAddress()));
- return pComp->GetOpCodeMap(css::sheet::FormulaLanguage::NATIVE);
- }
-
- return nullptr;
-}
-
-} // anonymous namespace
-
-OUString ScOpCodeSetToNumberString(const ScCalcConfig::OpCodeSet& rOpCodes)
-{
- OUStringBuffer result;
-
- for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
- {
- if (i != rOpCodes.cbegin())
- result.append(';');
- result.append(static_cast<sal_Int32>(*i));
- }
-
- return result.toString();
-}
-
OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
{
OUStringBuffer result;
- formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
-
- if (!pOpCodeMap)
- return ScOpCodeSetToNumberString(rOpCodes);
+ formula::FormulaCompiler aCompiler;
+ formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
{
@@ -164,16 +129,15 @@ OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
{
ScCalcConfig::OpCodeSet result;
- formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
+ formula::FormulaCompiler aCompiler;
+ formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
- OUString s(rOpCodes + ";");
-
- const formula::OpCodeHashMap *pHashMap(nullptr);
- if (pOpCodeMap)
- pHashMap = pOpCodeMap->getHashMap();
+ const formula::OpCodeHashMap *pHashMap(pOpCodeMap->getHashMap());
sal_Int32 fromIndex(0);
sal_Int32 semicolon;
+ OUString s(rOpCodes + ";");
+
while ((semicolon = s.indexOf(';', fromIndex)) >= 0)
{
if (semicolon > fromIndex)
@@ -182,7 +146,7 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
sal_Int32 n = element.toInt32();
if (n > 0 || (n == 0 && element == "0"))
result.insert(static_cast<OpCode>(n));
- else if (pHashMap)
+ else
{
auto opcode(pHashMap->find(element));
if (opcode != pHashMap->end())
@@ -190,10 +154,6 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
else
SAL_WARN("sc.opencl", "Unrecognized OpCode " << element << " in OpCode set string");
}
- else
- {
- SAL_WARN("sc.opencl", "No current doc, can't convert from OpCode name to value");
- }
}
fromIndex = semicolon+1;
}
diff --git a/sc/source/core/tool/formulaopt.cxx b/sc/source/core/tool/formulaopt.cxx
index 5da7b01..5038055 100644
--- a/sc/source/core/tool/formulaopt.cxx
+++ b/sc/source/core/tool/formulaopt.cxx
@@ -496,7 +496,7 @@ void ScFormulaCfg::UpdateFromProperties( const Sequence<OUString>& aNames )
break;
case SCFORMULAOPT_OPENCL_SUBSET_OPS:
{
- OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
+ OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
pValues[nProp] >>= sVal;
GetCalcConfig().maOpenCLSubsetOpCodes = ScStringToOpCodeSet(sVal);
}
@@ -643,7 +643,7 @@ void ScFormulaCfg::Commit()
break;
case SCFORMULAOPT_OPENCL_SUBSET_OPS:
{
- OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
+ OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
pValues[nProp] <<= sVal;
}
break;
More information about the Libreoffice-commits
mailing list