sc/inc/unitconv.hxx | 43 +++++++++----------- sc/source/core/tool/unitconv.cxx | 82 ++++++++++++++++----------------------- 2 files changed, 55 insertions(+), 70 deletions(-)
New commits: commit 051fb0d37a1f1c05ac5876fcfcc9a589938780e4 Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Wed Feb 1 21:30:57 2012 -0500 Unit converter data no longer relies on StrCollection. diff --git a/sc/inc/unitconv.hxx b/sc/inc/unitconv.hxx index be51d3c..2b000fb 100644 --- a/sc/inc/unitconv.hxx +++ b/sc/inc/unitconv.hxx @@ -31,42 +31,41 @@ #include "collect.hxx" +#include <boost/noncopyable.hpp> +#include <boost/ptr_container/ptr_map.hpp> -class ScUnitConverterData : public StrData +class ScUnitConverterData { - double fValue; - + rtl::OUString maIndexString; + double mfValue; // not implemented - ScUnitConverterData& operator=( const ScUnitConverterData& ); + ScUnitConverterData& operator=( const ScUnitConverterData& ); public: - ScUnitConverterData( const String& rFromUnit, - const String& rToUnit, double fValue = 1.0 ); - ScUnitConverterData( const ScUnitConverterData& ); - virtual ~ScUnitConverterData() {}; - - virtual ScDataObject* Clone() const; + ScUnitConverterData( const rtl::OUString& rFromUnit, + const rtl::OUString& rToUnit, double fValue = 1.0 ); + ScUnitConverterData( const ScUnitConverterData& ); + ~ScUnitConverterData(); - double GetValue() const { return fValue; } - - static void BuildIndexString( String& rStr, - const String& rFromUnit, const String& rToUnit ); + double GetValue() const; + const rtl::OUString& GetIndexString() const; + static rtl::OUString BuildIndexString( + const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit ); }; -class ScUnitConverter : public ScStrCollection +class ScUnitConverter : public boost::noncopyable { - // not implemented - ScUnitConverter( const ScUnitConverter& ); - ScUnitConverter& operator=( const ScUnitConverter& ); + typedef boost::ptr_map<rtl::OUString, ScUnitConverterData> MapType; + MapType maData; public: - ScUnitConverter( sal_uInt16 nInit = 16, sal_uInt16 nDelta = 4 ); - virtual ~ScUnitConverter() {}; + ScUnitConverter(); + ~ScUnitConverter(); - sal_Bool GetValue( double& fValue, const String& rFromUnit, - const String& rToUnit ) const; + bool GetValue( + double& fValue, const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit ) const; }; diff --git a/sc/source/core/tool/unitconv.cxx b/sc/source/core/tool/unitconv.cxx index 9392bd8..b37379c 100644 --- a/sc/source/core/tool/unitconv.cxx +++ b/sc/source/core/tool/unitconv.cxx @@ -48,52 +48,36 @@ const sal_Unicode cDelim = 0x01; // Delimiter zwischen From und To // --- ScUnitConverterData -------------------------------------------- -ScUnitConverterData::ScUnitConverterData( const String& rFromUnit, - const String& rToUnit, double fVal ) - : - StrData( rFromUnit ), - fValue( fVal ) -{ - String aTmp; - ScUnitConverterData::BuildIndexString( aTmp, rFromUnit, rToUnit ); - SetString( aTmp ); -} +ScUnitConverterData::ScUnitConverterData( + const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit, double fValue ) : + maIndexString(BuildIndexString(rFromUnit, rToUnit)), + mfValue(fValue) {} +ScUnitConverterData::ScUnitConverterData( const ScUnitConverterData& r ) : + maIndexString(r.maIndexString), + mfValue(r.mfValue) {} -ScUnitConverterData::ScUnitConverterData( const ScUnitConverterData& r ) - : - StrData( r ), - fValue( r.fValue ) +ScUnitConverterData::~ScUnitConverterData() {} + +double ScUnitConverterData::GetValue() const { + return mfValue; } - -ScDataObject* ScUnitConverterData::Clone() const +const rtl::OUString& ScUnitConverterData::GetIndexString() const { - return new ScUnitConverterData( *this ); + return maIndexString; } - -void ScUnitConverterData::BuildIndexString( String& rStr, - const String& rFromUnit, const String& rToUnit ) +rtl::OUString ScUnitConverterData::BuildIndexString( + const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit ) { -#if 1 -// case sensitive - rStr = rFromUnit; - rStr += cDelim; - rStr += rToUnit; -#else -// not case sensitive - rStr = rFromUnit; - String aTo( rToUnit ); - ScGlobal::pCharClass->toUpper( rStr ); - ScGlobal::pCharClass->toUpper( aTo ); - rStr += cDelim; - rStr += aTo; -#endif + rtl::OUStringBuffer aBuf(rFromUnit); + aBuf.append(cDelim); + aBuf.append(rToUnit); + return aBuf.makeStringAndClear(); } - // --- ScUnitConverter ------------------------------------------------ #define CFGPATH_UNIT "Office.Calc/UnitConversion" @@ -101,8 +85,7 @@ void ScUnitConverterData::BuildIndexString( String& rStr, #define CFGSTR_UNIT_TO "ToUnit" #define CFGSTR_UNIT_FACTOR "Factor" -ScUnitConverter::ScUnitConverter( sal_uInt16 nInit, sal_uInt16 nDeltaP ) : - ScStrCollection( nInit, nDeltaP, false ) +ScUnitConverter::ScUnitConverter() { // read from configuration - "convert.ini" is no longer used //! config item as member to allow change of values @@ -153,25 +136,28 @@ ScUnitConverter::ScUnitConverter( sal_uInt16 nInit, sal_uInt16 nDeltaP ) : pProperties[nIndex++] >>= fFactor; ScUnitConverterData* pNew = new ScUnitConverterData( sFromUnit, sToUnit, fFactor ); - if ( !Insert( pNew ) ) - delete pNew; + rtl::OUString aIndex = pNew->GetIndexString(); + maData.insert(aIndex, pNew); } } } } -sal_Bool ScUnitConverter::GetValue( double& fValue, const String& rFromUnit, - const String& rToUnit ) const +ScUnitConverter::~ScUnitConverter() {} + +bool ScUnitConverter::GetValue( + double& fValue, const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit ) const { - ScUnitConverterData aSearch( rFromUnit, rToUnit ); - sal_uInt16 nIndex; - if ( Search( &aSearch, nIndex ) ) + rtl::OUString aIndex = ScUnitConverterData::BuildIndexString(rFromUnit, rToUnit); + MapType::const_iterator it = maData.find(aIndex); + if (it == maData.end()) { - fValue = ((const ScUnitConverterData*)(At( nIndex )))->GetValue(); - return sal_True; + fValue = 1.0; + return false; } - fValue = 1.0; - return false; + + fValue = it->second->GetValue(); + return true; } _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits