Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


(I'm having trouble with logerrit)

This replaces the ScaList class used in scaddins with/source with std::vector.

Odd issues:
- I've written a wrap around to std::vector<ScaFuncData*> since the original
ScaFuncDataList class would generate its contents in the constructor and
supported looking contents up by name.
- ScaList, ScaOUStringList and ScaFuncDataList were all defined twice. This
patch has maintained doubling up the wrapper class for the moment.

-- 
Ryan McCoskrie
North Canterbury, New Zealand
diff --git a/scaddins/source/datefunc/datefunc.cxx b/scaddins/source/datefunc/datefunc.cxx
index 64679ff..3de398d 100644
--- a/scaddins/source/datefunc/datefunc.cxx
+++ b/scaddins/source/datefunc/datefunc.cxx
@@ -35,38 +35,6 @@ using namespace ::com::sun::star;
 
 #define STR_FROM_ANSI( s )      OUString( s, strlen( s ), RTL_TEXTENCODING_MS_1252 )
 
-const sal_uInt32 ScaList::nStartSize = 16;
-const sal_uInt32 ScaList::nIncrSize = 16;
-
-ScaList::ScaList() :
-    pData( new void*[ nStartSize ] ),
-    nSize( nStartSize ),
-    nCount( 0 ),
-    nCurr( 0 )
-{
-}
-
-ScaList::~ScaList()
-{
-    delete[] pData;
-}
-
-void ScaList::_Grow()
-{
-    nSize += nIncrSize;
-
-    void** pNewData = new void*[ nSize ];
-    memcpy( pNewData, pData, nCount * sizeof( void* ) );
-
-    delete[] pData;
-    pData = pNewData;
-}
-
-ScaStringList::~ScaStringList()
-{
-    for( OUString* pStr = First(); pStr; pStr = Next() )
-        delete pStr;
-}
 
 ScaResId::ScaResId( sal_uInt16 nId, ResMgr& rResMgr ) :
     ResId( nId, rResMgr )
@@ -109,7 +77,7 @@ ScaFuncData::ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rResMgr ) :
     const ResStringArray& rArr = aArrLoader.GetStringArray();
 
     for( sal_uInt32 nIndex = 0; nIndex < rArr.Count(); nIndex++ )
-        aCompList.Append( rArr.GetString( nIndex ) );
+        aCompList.push_back( rArr.GetString( nIndex ) );
 }
 
 ScaFuncData::~ScaFuncData()
@@ -125,31 +93,30 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const
 
 
 ScaFuncDataList::ScaFuncDataList( ResMgr& rResMgr ) :
-    nLast( 0xFFFFFFFF )
+    nLast( contents.begin() )
 {
     for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ )
-        Append( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) );
+        contents.push_back( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) );
 }
 
 ScaFuncDataList::~ScaFuncDataList()
 {
-    for( ScaFuncData* pFData = First(); pFData; pFData = Next() )
-        delete pFData;
+    for( std::vector<ScaFuncData*>::iterator it = contents.begin(); it != contents.end(); ++it )
+        delete *nLast;
 }
 
-const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName ) const
+const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName )
 {
     if( aLastName == rProgrammaticName )
-        return Get( nLast );
+        return *nLast;
 
-    for( sal_uInt32 nIndex = 0; nIndex < Count(); nIndex++ )
+    for( std::vector<ScaFuncData*>::iterator it = contents.begin(); it != contents.end(); ++it )
     {
-        const ScaFuncData* pCurr = Get( nIndex );
-        if( pCurr->Is( rProgrammaticName ) )
+        if( (*it)->Is( rProgrammaticName ) )
         {
-            const_cast< ScaFuncDataList* >( this )->aLastName = rProgrammaticName;
-            const_cast< ScaFuncDataList* >( this )->nLast = nIndex;
-            return pCurr;
+            aLastName = rProgrammaticName;
+            nLast = it;
+            return *it;
         }
     }
     return NULL;
@@ -446,13 +413,13 @@ uno::Sequence< sheet::LocalizedName > SAL_CALL 
ScaDateAddIn::getCompatibilityNam
         return uno::Sequence< sheet::LocalizedName >( 0 );
 
     const ScaStringList& rStrList = pFData->GetCompNameList();
-    sal_uInt32 nCount = rStrList.Count();
+    sal_uInt32 nCount = rStrList.size();
 
     uno::Sequence< sheet::LocalizedName > aRet( nCount );
     sheet::LocalizedName* pArray = aRet.getArray();
 
     for( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ )
-        pArray[ nIndex ] = sheet::LocalizedName( GetLocale( nIndex ), *rStrList.Get( nIndex ) );
+        pArray[ nIndex ] = sheet::LocalizedName( GetLocale( nIndex ), rStrList[nIndex] );
 
     return aRet;
 }
diff --git a/scaddins/source/datefunc/datefunc.hxx b/scaddins/source/datefunc/datefunc.hxx
index 9922bdf..e2271a0 100644
--- a/scaddins/source/datefunc/datefunc.hxx
+++ b/scaddins/source/datefunc/datefunc.hxx
@@ -35,86 +35,8 @@
 #include <tools/rc.hxx>
 #include <tools/resary.hxx>
 
-class ScaList
-{
-private:
-    static const sal_uInt32     nStartSize;
-    static const sal_uInt32     nIncrSize;
-
-    void**                      pData;          // pointer array
-    sal_uInt32                  nSize;          // array size
-    sal_uInt32                  nCount;         // next index to be inserted at
-    sal_uInt32                  nCurr;          // current pos for iterations
-
-    void                        _Grow();
-    inline void                 Grow();
-
-public:
-                                ScaList();
-    virtual                     ~ScaList();
-
-    inline sal_uInt32           Count() const       { return nCount; }
-
-    inline const void*          GetObject( sal_uInt32 nIndex ) const
-                                    { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
-
-    inline void*                First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
-    inline void*                Next()  { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
-
-    inline void                 Append( void* pNew );
-};
-
-
-inline void ScaList::Grow()
-{
-    if( nCount >= nSize )
-        _Grow();
-}
-
-inline void ScaList::Append( void* pNew )
-{
-    Grow();
-    pData[ nCount++ ] = pNew;
-}
-
-
-class ScaStringList : protected ScaList
-{
-public:
-    inline                      ScaStringList() : ScaList() {};
-    virtual                     ~ScaStringList();
-
-                                using ScaList::Count;
-
-    inline const OUString* Get( sal_uInt32 nIndex ) const;
-
-    inline OUString*     First();
-    inline OUString*     Next();
-
-    using ScaList::Append;
-    inline void                 Append( const OUString& rNew );
-};
 
-
-inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
-{
-    return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
-}
-
-inline OUString* ScaStringList::First()
-{
-    return static_cast< OUString* >( ScaList::First() );
-}
-
-inline OUString* ScaStringList::Next()
-{
-    return static_cast< OUString* >( ScaList::Next() );
-}
-
-inline void ScaStringList::Append( const OUString& rNew )
-{
-    ScaList::Append( new OUString( rNew ) );
-}
+typedef std::vector<OUString> ScaStringList;
 
 
 class ScaResId : public ResId
@@ -236,43 +158,22 @@ public:
 };
 
 
-class ScaFuncDataList : private ScaList
+class ScaFuncDataList
 {
-    OUString             aLastName;
-    sal_uInt32                  nLast;
+    OUString                                    aLastName;
+    std::vector<ScaFuncData*>::iterator         nLast;
+    std::vector<ScaFuncData*>                   contents;
 
 public:
                                 ScaFuncDataList( ResMgr& rResMgr );
     virtual                     ~ScaFuncDataList();
 
-                                using ScaList::Count;
-
-    inline const ScaFuncData*   Get( sal_uInt32 nIndex ) const;
-    const ScaFuncData*          Get( const OUString& rProgrammaticName ) const;
-    inline ScaFuncData*         First();
-    inline ScaFuncData*         Next();
+    const ScaFuncData*          Get( const OUString& rProgrammaticName );
 
-    using ScaList::Append;
-    inline void                 Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
+    inline void                 Append( ScaFuncData* pNew ) { contents.push_back( pNew ); }
 };
 
 
-inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
-{
-    return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
-}
-
-inline ScaFuncData* ScaFuncDataList::First()
-{
-    return static_cast< ScaFuncData* >( ScaList::First() );
-}
-
-inline ScaFuncData* ScaFuncDataList::Next()
-{
-    return static_cast< ScaFuncData* >( ScaList::Next() );
-}
-
-
 
 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 
DateFunctionAddIn_CreateInstance(
     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
diff --git a/scaddins/source/pricing/pricing.cxx b/scaddins/source/pricing/pricing.cxx
index 21174c7..8139225 100644
--- a/scaddins/source/pricing/pricing.cxx
+++ b/scaddins/source/pricing/pricing.cxx
@@ -45,38 +45,6 @@ using namespace sca::pricing;
 
 #define STR_FROM_ANSI( s )      OUString( s, strlen( s ), RTL_TEXTENCODING_MS_1252 )
 
-const sal_uInt32 ScaList::nStartSize = 16;
-const sal_uInt32 ScaList::nIncrSize = 16;
-
-ScaList::ScaList() :
-    pData( new void*[ nStartSize ] ),
-    nSize( nStartSize ),
-    nCount( 0 ),
-    nCurr( 0 )
-{
-}
-
-ScaList::~ScaList()
-{
-    delete[] pData;
-}
-
-void ScaList::_Grow()
-{
-    nSize += nIncrSize;
-
-    void** pNewData = new void*[ nSize ];
-    memcpy( pNewData, pData, nCount * sizeof( void* ) );
-
-    delete[] pData;
-    pData = pNewData;
-}
-
-ScaStringList::~ScaStringList()
-{
-    for( OUString* pStr = First(); pStr; pStr = Next() )
-        delete pStr;
-}
 
 ScaResId::ScaResId( sal_uInt16 nId, ResMgr& rResMgr ) :
     ResId( nId, rResMgr )
@@ -114,7 +82,7 @@ ScaFuncData::ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rResMgr ) :
     const ResStringArray& rArr = aArrLoader.GetStringArray();
 
     for( sal_uInt32 nIndex = 0; nIndex < rArr.Count(); nIndex++ )
-        aCompList.Append( rArr.GetString( nIndex ) );
+        aCompList.push_back( rArr.GetString( nIndex ) );
 }
 
 ScaFuncData::~ScaFuncData()
@@ -129,32 +97,31 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const
 }
 
 ScaFuncDataList::ScaFuncDataList( ResMgr& rResMgr ) :
-    nLast( 0xFFFFFFFF )
+    nLast( contents.end() )
 {
     for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ )
-        Append( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) );
+        contents.push_back( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) );
 }
 
 ScaFuncDataList::~ScaFuncDataList()
 {
-    for( ScaFuncData* pFData = First(); pFData; pFData = Next() )
-        delete pFData;
+    for( std::vector<ScaFuncData*>::iterator it = contents.begin(); it != contents.end();  ++it )
+        delete *it;
 }
 
-const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName ) const
+const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName )
 {
     if( aLastName == rProgrammaticName ){
-        return Get( nLast );
+        return *nLast;
     }
 
-    for( sal_uInt32 nIndex = 0; nIndex < Count(); nIndex++ )
+    for( std::vector<ScaFuncData*>::iterator it = contents.begin(); it != contents.end(); ++it )
     {
-        const ScaFuncData* pCurr = Get( nIndex );
-        if( pCurr->Is( rProgrammaticName ) )
+        if( (*it)->Is( rProgrammaticName ) )
         {
-            const_cast< ScaFuncDataList* >( this )->aLastName = rProgrammaticName;
-            const_cast< ScaFuncDataList* >( this )->nLast = nIndex;
-            return pCurr;
+            aLastName = rProgrammaticName;
+            nLast = it;
+            return *it;
         }
     }
     return NULL;
@@ -453,13 +420,13 @@ uno::Sequence< sheet::LocalizedName > SAL_CALL 
ScaPricingAddIn::getCompatibility
         return uno::Sequence< sheet::LocalizedName >( 0 );
 
     const ScaStringList& rStrList = pFData->GetCompNameList();
-    sal_uInt32 nCount = rStrList.Count();
+    sal_uInt32 nCount = rStrList.size();
 
     uno::Sequence< sheet::LocalizedName > aRet( nCount );
     sheet::LocalizedName* pArray = aRet.getArray();
 
     for( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ )
-        pArray[ nIndex ] = sheet::LocalizedName( GetLocale( nIndex ), *rStrList.Get( nIndex ) );
+        pArray[ nIndex ] = sheet::LocalizedName( GetLocale( nIndex ), rStrList[nIndex] );
 
     return aRet;
 }
diff --git a/scaddins/source/pricing/pricing.hxx b/scaddins/source/pricing/pricing.hxx
index 21a3c49..bd80096 100644
--- a/scaddins/source/pricing/pricing.hxx
+++ b/scaddins/source/pricing/pricing.hxx
@@ -47,87 +47,8 @@
 namespace sca {
 namespace pricing {
 
-class ScaList
-{
-private:
-    static const sal_uInt32     nStartSize;
-    static const sal_uInt32     nIncrSize;
-
-    void**                      pData;          // pointer array
-    sal_uInt32                  nSize;          // array size
-    sal_uInt32                  nCount;         // next index to be inserted at
-    sal_uInt32                  nCurr;          // current pos for iterations
-
-    void                        _Grow();
-    inline void                 Grow();
-
-public:
-                                ScaList();
-    virtual                     ~ScaList();
-
-    inline sal_uInt32           Count() const       { return nCount; }
-
-    inline const void*          GetObject( sal_uInt32 nIndex ) const
-                                    { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
-
-    inline void*                First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
-    inline void*                Next()  { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
-
-    inline void                 Append( void* pNew );
-};
-
-
-inline void ScaList::Grow()
-{
-    if( nCount >= nSize )
-        _Grow();
-}
-
-inline void ScaList::Append( void* pNew )
-{
-    Grow();
-    pData[ nCount++ ] = pNew;
-}
-
-
-class ScaStringList : protected ScaList
-{
-public:
-    inline                      ScaStringList() : ScaList() {};
-    virtual                     ~ScaStringList();
-
-                                using ScaList::Count;
-
-    inline const OUString* Get( sal_uInt32 nIndex ) const;
-
-    inline OUString*     First();
-    inline OUString*     Next();
-
-    using ScaList::Append;
-    inline void                 Append( const OUString& rNew );
-};
-
-
-inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
-{
-    return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
-}
-
-inline OUString* ScaStringList::First()
-{
-    return static_cast< OUString* >( ScaList::First() );
-}
-
-inline OUString* ScaStringList::Next()
-{
-    return static_cast< OUString* >( ScaList::Next() );
-}
-
-inline void ScaStringList::Append( const OUString& rNew )
-{
-    ScaList::Append( new OUString( rNew ) );
-}
 
+typedef std::vector<OUString> ScaStringList;
 
 class ScaResId : public ResId
 {
@@ -248,42 +169,23 @@ public:
 };
 
 
-class ScaFuncDataList : private ScaList
+class ScaFuncDataList
 {
-    OUString             aLastName;
-    sal_uInt32                  nLast;
+    OUString                                    aLastName;
+    std::vector<ScaFuncData*>::iterator         nLast;
+    std::vector<ScaFuncData*>                   contents;
 
 public:
                                 ScaFuncDataList( ResMgr& rResMgr );
     virtual                     ~ScaFuncDataList();
 
-                                using ScaList::Count;
-
     inline const ScaFuncData*   Get( sal_uInt32 nIndex ) const;
-    const ScaFuncData*          Get( const OUString& rProgrammaticName ) const;
-    inline ScaFuncData*         First();
-    inline ScaFuncData*         Next();
+    const ScaFuncData*          Get( const OUString& rProgrammaticName );
 
-    using ScaList::Append;
-    inline void                 Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
+    inline void                 Append( ScaFuncData* pNew ) { contents.push_back( pNew ); }
 };
 
 
-inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
-{
-    return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
-}
-
-inline ScaFuncData* ScaFuncDataList::First()
-{
-    return static_cast< ScaFuncData* >( ScaList::First() );
-}
-
-inline ScaFuncData* ScaFuncDataList::Next()
-{
-    return static_cast< ScaFuncData* >( ScaList::Next() );
-}
-
 } // namespace pricing
 } // namespace sca
 

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.