[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Feb 6 18:23:26 PST 2012
sc/inc/callform.hxx | 40 ++++++++++-------
sc/source/core/data/funcdesc.cxx | 8 +--
sc/source/core/inc/adiasync.hxx | 13 ++---
sc/source/core/tool/adiasync.cxx | 12 ++---
sc/source/core/tool/callform.cxx | 88 ++++++++++++++++++++++-----------------
sc/source/core/tool/compiler.cxx | 13 ++---
sc/source/core/tool/interpr4.cxx | 7 +--
sc/source/core/tool/parclass.cxx | 41 +++++++++---------
sc/source/ui/unoobj/funcuno.cxx | 20 ++++----
9 files changed, 130 insertions(+), 112 deletions(-)
New commits:
commit 9ccaa4b1468527bbec12d7e0fccf4ea443478f50
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Mon Feb 6 21:22:29 2012 -0500
FuncCollection no longer a child of ScSortedCollection.
diff --git a/sc/inc/callform.hxx b/sc/inc/callform.hxx
index 4708a47..f72a7f1 100644
--- a/sc/inc/callform.hxx
+++ b/sc/inc/callform.hxx
@@ -33,6 +33,8 @@
#include <rtl/ustring.hxx>
+#include <boost/ptr_container/ptr_map.hpp>
+
#define MAXFUNCPARAM 16
#define MAXARRSIZE 0xfffe
@@ -57,9 +59,11 @@ enum ParamType
};
class ModuleData;
-class FuncData : public ScDataObject
+
+class FuncData
{
-friend class FuncCollection;
+ friend class FuncCollection;
+
const ModuleData* pModuleData;
rtl::OUString aInternalName;
rtl::OUString aFuncName;
@@ -78,7 +82,6 @@ public:
const ParamType* peType,
ParamType eType);
FuncData(const FuncData& rData);
- virtual ScDataObject* Clone() const { return new FuncData(*this); }
const rtl::OUString& GetModuleName() const;
const rtl::OUString& GetInternalName() const { return aInternalName; }
@@ -87,27 +90,32 @@ public:
ParamType GetParamType(sal_uInt16 nIndex) const { return eParamType[nIndex]; }
ParamType GetReturnType() const { return eParamType[0]; }
ParamType GetAsyncType() const { return eAsyncType; }
- bool Call(void** ppParam);
+ bool Call(void** ppParam) const;
bool Unadvice(double nHandle);
- // name and description of parameter nParam.
- // nParam==0 => Desc := function description,
- // Name := n/a
- bool getParamDesc( ::rtl::OUString& aName, ::rtl::OUString& aDesc, sal_uInt16 nParam );
-
+ // name and description of parameter nParam.
+ // nParam==0 => Desc := function description,
+ // Name := n/a
+ bool getParamDesc( ::rtl::OUString& aName, ::rtl::OUString& aDesc, sal_uInt16 nParam ) const;
};
-class FuncCollection : public ScSortedCollection
+class FuncCollection
{
+ typedef boost::ptr_map<rtl::OUString, FuncData> MapType;
+ MapType maData;
public:
- FuncCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = false) : ScSortedCollection ( nLim, nDel, bDup ) {}
- FuncCollection(const FuncCollection& rFuncCollection) : ScSortedCollection ( rFuncCollection ) {}
+ typedef MapType::const_iterator const_iterator;
+
+ FuncCollection();
+ FuncCollection(const FuncCollection& r);
+
+ const FuncData* findByName(const rtl::OUString& rName) const;
+ FuncData* findByName(const rtl::OUString& rName);
+ void insert(FuncData* pNew);
- virtual ScDataObject* Clone() const { return new FuncCollection(*this); }
- FuncData* operator[]( const sal_uInt16 nIndex) const {return (FuncData*)At(nIndex);}
- virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
- bool SearchFunc( const rtl::OUString& rName, sal_uInt16& rIndex ) const;
+ const_iterator begin() const;
+ const_iterator end() const;
};
diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx
index cbaeb21..4175eff 100644
--- a/sc/source/core/data/funcdesc.cxx
+++ b/sc/source/core/data/funcdesc.cxx
@@ -379,7 +379,6 @@ ScFunctionList::ScFunctionList() :
{
ScFuncDesc* pDesc = NULL;
xub_StrLen nStrLen = 0;
- FuncCollection* pFuncColl;
::std::list<ScFuncDesc*> tmpFuncList;
sal_uInt16 nDescBlock[] =
{
@@ -441,11 +440,12 @@ ScFunctionList::ScFunctionList() :
::rtl::OUString aDefArgDescNone = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("none"));
::rtl::OUString aArgName, aArgDesc;
- pFuncColl = ScGlobal::GetFuncCollection();
- for (sal_uInt16 i = 0; i < pFuncColl->GetCount(); ++i)
+ const FuncCollection& rFuncColl = *ScGlobal::GetFuncCollection();
+ FuncCollection::const_iterator it = rFuncColl.begin(), itEnd = rFuncColl.end();
+ for (; it != itEnd; ++it)
{
+ const FuncData* pAddInFuncData = it->second;
pDesc = new ScFuncDesc;
- FuncData *pAddInFuncData = (FuncData*)pFuncColl->At(i);
sal_uInt16 nArgs = pAddInFuncData->GetParamCount() - 1;
pAddInFuncData->getParamDesc( aArgName, aArgDesc, 0 );
pDesc->nFIndex = nNextId++; // ??? OpCode vergeben
diff --git a/sc/source/core/inc/adiasync.hxx b/sc/source/core/inc/adiasync.hxx
index 4d47d3d..cfb3c21 100644
--- a/sc/source/core/inc/adiasync.hxx
+++ b/sc/source/core/inc/adiasync.hxx
@@ -59,16 +59,15 @@ private:
String* pStr;
};
ScAddInDocs* pDocs; // Liste der benutzenden Dokumente
- FuncData* pFuncData; // Zeiger auf die Daten in der Collection
+ FuncData* mpFuncData; // Zeiger auf die Daten in der Collection
sal_uLong nHandle; // wird von double auf sal_uLong gecasted
- ParamType eType; // PTR_DOUBLE oder PTR_STRING Ergebnis
+ ParamType meType; // PTR_DOUBLE oder PTR_STRING Ergebnis
sal_Bool bValid; // ob Wert gueltig
public:
- // cTor nur wenn ScAddInAsync::Get fehlschlaegt!
- // nIndex: Index aus der FunctionCollection
- ScAddInAsync( sal_uLong nHandle, sal_uInt16 nIndex,
- ScDocument* pDoc );
+ // cTor nur wenn ScAddInAsync::Get fehlschlaegt!
+ // nIndex: Index aus der FunctionCollection
+ ScAddInAsync(sal_uLong nHandle, FuncData* pFuncData, ScDocument* pDoc);
// default-cTor nur fuer das eine globale aSeekObj !!!
ScAddInAsync();
virtual ~ScAddInAsync();
@@ -76,7 +75,7 @@ public:
static void CallBack( sal_uLong nHandle, void* pData );
static void RemoveDocument( ScDocument* pDocument );
sal_Bool IsValid() const { return bValid; }
- ParamType GetType() const { return eType; }
+ ParamType GetType() const { return meType; }
double GetValue() const { return nVal; }
const String& GetString() const { return *pStr; }
sal_Bool HasDocument( ScDocument* pDoc ) const
diff --git a/sc/source/core/tool/adiasync.cxx b/sc/source/core/tool/adiasync.cxx
index e7b21a8..20cfc65 100644
--- a/sc/source/core/tool/adiasync.cxx
+++ b/sc/source/core/tool/adiasync.cxx
@@ -68,16 +68,16 @@ ScAddInAsync::ScAddInAsync() :
-ScAddInAsync::ScAddInAsync( sal_uLong nHandleP, sal_uInt16 nIndex, ScDocument* pDoc ) :
+ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, FuncData* pFuncData, ScDocument* pDoc) :
SvtBroadcaster(),
pStr( NULL ),
+ mpFuncData(pFuncData),
nHandle( nHandleP ),
+ meType(pFuncData->GetAsyncType()),
bValid( false )
{
pDocs = new ScAddInDocs( 1 );
pDocs->Insert( pDoc );
- pFuncData = (FuncData*)ScGlobal::GetFuncCollection()->At(nIndex);
- eType = pFuncData->GetAsyncType();
theAddInAsyncTbl.Insert( this );
}
@@ -89,8 +89,8 @@ ScAddInAsync::~ScAddInAsync()
if ( nHandle )
{
// im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
- pFuncData->Unadvice( (double)nHandle );
- if ( eType == PTR_STRING && pStr ) // mit Typvergleich wg. Union!
+ mpFuncData->Unadvice( (double)nHandle );
+ if ( meType == PTR_STRING && pStr ) // mit Typvergleich wg. Union!
delete pStr;
delete pDocs;
}
@@ -124,7 +124,7 @@ void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
delete p;
return ;
}
- switch ( p->eType )
+ switch ( p->meType )
{
case PTR_DOUBLE :
p->nVal = *(double*)pData;
diff --git a/sc/source/core/tool/callform.cxx b/sc/source/core/tool/callform.cxx
index 3c9d5f0..ab0b8fc 100644
--- a/sc/source/core/tool/callform.cxx
+++ b/sc/source/core/tool/callform.cxx
@@ -39,8 +39,6 @@
#include "global.hxx"
#include "adiasync.hxx"
-#include <boost/ptr_container/ptr_map.hpp>
-
//------------------------------------------------------------------------
extern "C" {
@@ -88,6 +86,21 @@ typedef void (CALLTYPE* FARPROC) ( void );
#define ADVICE "Advice"
#define UNADVICE "Unadvice"
+class ModuleData
+{
+friend class ModuleCollection;
+ rtl::OUString aName;
+ osl::Module* pInstance;
+public:
+ ModuleData(const rtl::OUString& rStr, osl::Module* pInst) : aName(rStr), pInstance(pInst) {}
+ ModuleData(const ModuleData& rData) : aName(rData.aName) {pInstance = new osl::Module(aName);}
+ ~ModuleData() { delete pInstance; }
+
+ const rtl::OUString& GetName() const { return aName; }
+ osl::Module* GetInstance() const { return pInstance; }
+ void FreeInstance() { delete pInstance; pInstance = 0; }
+};
+
FuncData::FuncData(const rtl::OUString& rIName) :
pModuleData (NULL),
aInternalName (rIName),
@@ -122,7 +135,6 @@ FuncData::FuncData(const ModuleData*pModule,
//------------------------------------------------------------------------
FuncData::FuncData(const FuncData& rData) :
- ScDataObject(),
pModuleData (rData.pModuleData),
aInternalName (rData.aInternalName),
aFuncName (rData.aFuncName),
@@ -134,38 +146,6 @@ FuncData::FuncData(const FuncData& rData) :
eParamType[i] = rData.eParamType[i];
}
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-short FuncCollection::Compare(ScDataObject* pKey1, ScDataObject* pKey2) const
-{
- return (short) ScGlobal::GetpTransliteration()->compareString(
- ((FuncData*)pKey1)->aInternalName, ((FuncData*)pKey2)->aInternalName );
-}
-
-//------------------------------------------------------------------------
-
-bool FuncCollection::SearchFunc( const rtl::OUString& rName, sal_uInt16& rIndex ) const
-{
- FuncData aDataObj(rName);
- return Search( &aDataObj, rIndex );
-}
-
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-class ModuleData
-{
-friend class ModuleCollection;
- rtl::OUString aName;
- osl::Module* pInstance;
-public:
- ModuleData(const rtl::OUString& rStr, osl::Module* pInst) : aName(rStr), pInstance(pInst) {}
- ModuleData(const ModuleData& rData) : aName(rData.aName) {pInstance = new osl::Module(aName);}
- ~ModuleData() { delete pInstance; }
-
- const rtl::OUString& GetName() const { return aName; }
- osl::Module* GetInstance() const { return pInstance; }
- void FreeInstance() { delete pInstance; pInstance = 0; }
-};
-
namespace {
class ModuleCollection
@@ -277,7 +257,7 @@ bool InitExternalFunc(const rtl::OUString& rModuleName)
nParamCount,
eParamType,
eAsyncType );
- pFuncCol->Insert(pFuncData);
+ pFuncCol->insert(pFuncData);
}
bRet = sal_True;
}
@@ -298,7 +278,7 @@ void ExitExternalFunc()
//------------------------------------------------------------------------
-bool FuncData::Call(void** ppParam)
+bool FuncData::Call(void** ppParam) const
{
bool bRet = false;
osl::Module* pLib = pModuleData->GetInstance();
@@ -413,7 +393,7 @@ const rtl::OUString& FuncData::GetModuleName() const
return pModuleData->GetName();
}
-bool FuncData::getParamDesc( ::rtl::OUString& aName, ::rtl::OUString& aDesc, sal_uInt16 nParam )
+bool FuncData::getParamDesc( ::rtl::OUString& aName, ::rtl::OUString& aDesc, sal_uInt16 nParam ) const
{
bool bRet = false;
if ( nParam <= nParamCount )
@@ -440,4 +420,36 @@ bool FuncData::getParamDesc( ::rtl::OUString& aName, ::rtl::OUString& aDesc, sal
return bRet;
}
+FuncCollection::FuncCollection() {}
+FuncCollection::FuncCollection(const FuncCollection& r) : maData(r.maData) {}
+
+const FuncData* FuncCollection::findByName(const rtl::OUString& rName) const
+{
+ MapType::const_iterator it = maData.find(rName);
+ return it == maData.end() ? NULL : it->second;
+}
+
+FuncData* FuncCollection::findByName(const rtl::OUString& rName)
+{
+ MapType::iterator it = maData.find(rName);
+ return it == maData.end() ? NULL : it->second;
+}
+
+void FuncCollection::insert(FuncData* pNew)
+{
+ rtl::OUString aName = pNew->GetInternalName();
+ maData.insert(aName, pNew);
+}
+
+FuncCollection::const_iterator FuncCollection::begin() const
+{
+ return maData.begin();
+}
+
+FuncCollection::const_iterator FuncCollection::end() const
+{
+ return maData.end();
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index c7dc18a..162eaf5 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -188,7 +188,7 @@ void ScCompiler::DeInit()
bool ScCompiler::IsEnglishSymbol( const String& rName )
{
// function names are always case-insensitive
- String aUpper( ScGlobal::pCharClass->uppercase( rName ) );
+ rtl::OUString aUpper = ScGlobal::pCharClass->uppercase(rName);
// 1. built-in function name
OpCode eOp = ScCompiler::GetEnglishOpCode( aUpper );
@@ -197,15 +197,14 @@ bool ScCompiler::IsEnglishSymbol( const String& rName )
return true;
}
// 2. old add in functions
- sal_uInt16 nIndex;
- if ( ScGlobal::GetFuncCollection()->SearchFunc( aUpper, nIndex ) )
+ if (ScGlobal::GetFuncCollection()->findByName(aUpper))
{
return true;
}
// 3. new (uno) add in functions
- String aIntName(ScGlobal::GetAddInCollection()->FindFunction( aUpper, false ));
- if (aIntName.Len())
+ rtl::OUString aIntName = ScGlobal::GetAddInCollection()->FindFunction(aUpper, false);
+ if (!aIntName.isEmpty())
{
return true;
}
@@ -2522,9 +2521,7 @@ bool ScCompiler::IsOpCode( const String& rName, bool bInArray )
if (!aIntName.Len())
{
// Old (deprecated) addins first for legacy.
- sal_uInt16 nIndex;
- bFound = ScGlobal::GetFuncCollection()->SearchFunc( cSymbol, nIndex);
- if (bFound)
+ if (ScGlobal::GetFuncCollection()->findByName(cSymbol))
{
ScRawToken aToken;
aToken.SetExternal( cSymbol );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index b6492dd..fac1d34 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -2495,13 +2495,12 @@ void ScInterpreter::ScDBGet()
void ScInterpreter::ScExternal()
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScExternal" );
- sal_uInt16 nIndex;
sal_uInt8 nParamCount = GetByte();
String aUnoName;
String aFuncName( ScGlobal::pCharClass->uppercase( pCur->GetExternal() ) );
- if (ScGlobal::GetFuncCollection()->SearchFunc(aFuncName, nIndex))
+ FuncData* pFuncData = ScGlobal::GetFuncCollection()->findByName(aFuncName);
+ if (pFuncData)
{
- FuncData* pFuncData = (FuncData*)ScGlobal::GetFuncCollection()->At(nIndex);
if (nParamCount <= MAXFUNCPARAM && nParamCount == pFuncData->GetParamCount() - 1)
{
ParamType eParamType[MAXFUNCPARAM];
@@ -2645,7 +2644,7 @@ void ScInterpreter::ScExternal()
ScAddInAsync* pAs = ScAddInAsync::Get( nHandle );
if ( !pAs )
{
- pAs = new ScAddInAsync( nHandle, nIndex, pDok );
+ pAs = new ScAddInAsync(nHandle, pFuncData, pDok);
pMyFormulaCell->StartListening( *pAs );
}
else
diff --git a/sc/source/core/tool/parclass.cxx b/sc/source/core/tool/parclass.cxx
index 7add078..e8509a3 100644
--- a/sc/source/core/tool/parclass.cxx
+++ b/sc/source/core/tool/parclass.cxx
@@ -324,31 +324,34 @@ ScParameterClassification::GetExternalParameterType( const formula::FormulaToken
{
Type eRet = Unknown;
// similar to ScInterpreter::ScExternal()
- sal_uInt16 nIndex;
- String aUnoName;
- String aFuncName( ScGlobal::pCharClass->uppercase( pToken->GetExternal()));
- if ( ScGlobal::GetFuncCollection()->SearchFunc( aFuncName, nIndex) )
+ rtl::OUString aFuncName = ScGlobal::pCharClass->uppercase( pToken->GetExternal());
{
- FuncData* pFuncData = (FuncData*)ScGlobal::GetFuncCollection()->At(
- nIndex);
- if ( nParameter >= pFuncData->GetParamCount() )
- eRet = Bounds;
- else
+ const FuncData* pFuncData = ScGlobal::GetFuncCollection()->findByName(aFuncName);
+ if (pFuncData)
{
- switch ( pFuncData->GetParamType( nParameter) )
+ if ( nParameter >= pFuncData->GetParamCount() )
+ eRet = Bounds;
+ else
{
- case PTR_DOUBLE:
- case PTR_STRING:
- eRet = Value;
- break;
- default:
- eRet = Reference;
- // also array types are created using an area reference
+ switch ( pFuncData->GetParamType( nParameter) )
+ {
+ case PTR_DOUBLE:
+ case PTR_STRING:
+ eRet = Value;
+ break;
+ default:
+ eRet = Reference;
+ // also array types are created using an area reference
+ }
}
+ return eRet;
}
}
- else if ( (aUnoName = ScGlobal::GetAddInCollection()->FindFunction(
- aFuncName, false)).Len() )
+
+ rtl::OUString aUnoName =
+ ScGlobal::GetAddInCollection()->FindFunction(aFuncName, false);
+
+ if (!aUnoName.isEmpty())
{
// the relevant parts of ScUnoAddInCall without having to create one
const ScUnoAddInFuncData* pFuncData =
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 4297d72..6eac293 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -355,7 +355,7 @@ SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFunctionAccess )
sal_Bool lcl_AddFunctionToken( ScTokenArray& rArray, const rtl::OUString& rName,const ScCompiler& rCompiler )
{
// function names are always case-insensitive
- String aUpper( ScGlobal::pCharClass->uppercase( rName ) );
+ rtl::OUString aUpper = ScGlobal::pCharClass->uppercase(rName);
// same options as in ScCompiler::IsOpCode:
// 1. built-in function name
@@ -364,25 +364,25 @@ sal_Bool lcl_AddFunctionToken( ScTokenArray& rArray, const rtl::OUString& rName,
if ( eOp != ocNone )
{
rArray.AddOpCode( eOp );
- return sal_True;
+ return true;
}
// 2. old add in functions
- sal_uInt16 nIndex;
- if ( ScGlobal::GetFuncCollection()->SearchFunc( aUpper, nIndex ) )
+ if (ScGlobal::GetFuncCollection()->findByName(aUpper))
{
- rArray.AddExternal( aUpper.GetBuffer() );
- return sal_True;
+ rArray.AddExternal(aUpper.getStr());
+ return true;
}
// 3. new (uno) add in functions
- String aIntName(ScGlobal::GetAddInCollection()->FindFunction( aUpper, false ));
- if (aIntName.Len())
+ rtl::OUString aIntName =
+ ScGlobal::GetAddInCollection()->FindFunction(aUpper, false);
+ if (!aIntName.isEmpty())
{
- rArray.AddExternal( aIntName.GetBuffer() ); // international name
- return sal_True;
+ rArray.AddExternal(aIntName.getStr()); // international name
+ return true;
}
return false; // no valid function name
More information about the Libreoffice-commits
mailing list