[PATCH 1/8] fdo#38831 convert SvStrings to std::vector glos*.cxx/hxx + misc
Brad Sowden
code at sowden.org
Tue Dec 27 16:11:32 PST 2011
---
sw/inc/swunohelper.hxx | 6 ++-
sw/source/core/unocore/swunohelper.cxx | 8 +--
sw/source/ui/inc/glosdoc.hxx | 11 +---
sw/source/ui/misc/glosdoc.cxx | 90 ++++++++++++-------------------
sw/source/ui/utlui/gloslst.cxx | 10 ++--
5 files changed, 50 insertions(+), 75 deletions(-)
diff --git a/sw/inc/swunohelper.hxx b/sw/inc/swunohelper.hxx
index 9f7b05b..6d61d2e 100644
--- a/sw/inc/swunohelper.hxx
+++ b/sw/inc/swunohelper.hxx
@@ -32,6 +32,8 @@
#include <sal/types.h>
#include "swdllapi.h"
+#include <vector>
+
namespace com { namespace sun { namespace star {
namespace uno {
class Any;
@@ -39,7 +41,6 @@ namespace com { namespace sun { namespace star {
}}}
class String;
-class SvStrings;
class SvPtrarr;
namespace SWUnoHelper {
@@ -68,7 +69,8 @@ SW_DLLPUBLIC sal_Bool UCB_IsReadOnlyFileName( const String& rURL );
// pDateTime != 0 -> returns also the modified date/time of
// the files in a SvPtrarr -->
// !! objects must be deleted from the caller!!
-sal_Bool UCB_GetFileListOfFolder( const String& rURL, SvStrings& rList,
+sal_Bool UCB_GetFileListOfFolder( const String& rURL,
+ std::vector<String*>& rList,
const String* pExtension = 0,
SvPtrarr* pDateTimeList = 0 );
diff --git a/sw/source/core/unocore/swunohelper.cxx b/sw/source/core/unocore/swunohelper.cxx
index 9946c2c..c3896fa 100644
--- a/sw/source/core/unocore/swunohelper.cxx
+++ b/sw/source/core/unocore/swunohelper.cxx
@@ -26,8 +26,6 @@
*
************************************************************************/
-
-#define _SVSTDARR_STRINGS
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/ucb/XContentIdentifier.hpp>
@@ -204,7 +202,8 @@ sal_Bool UCB_IsDirectory( const String& rURL )
// pDateTime != 0 -> returns also the modified date/time of
// the files in a SvPtrarr -->
// !! objects must be deleted from the caller!!
-sal_Bool UCB_GetFileListOfFolder( const String& rURL, SvStrings& rList,
+sal_Bool UCB_GetFileListOfFolder( const String& rURL,
+ std::vector<String*>& rList,
const String* pExtension,
SvPtrarr* pDateTimeList )
{
@@ -245,8 +244,7 @@ sal_Bool UCB_GetFileListOfFolder( const String& rURL, SvStrings& rList,
sTitle.Equals( *pExtension,
sTitle.Len() - nExtLen, nExtLen )) )
{
- String* pStr = new String( sTitle );
- rList.Insert( pStr, rList.Count() );
+ rList.push_back( new String(sTitle) );
if( pDateTimeList )
{
diff --git a/sw/source/ui/inc/glosdoc.hxx b/sw/source/ui/inc/glosdoc.hxx
index 2cea838..7588509 100644
--- a/sw/source/ui/inc/glosdoc.hxx
+++ b/sw/source/ui/inc/glosdoc.hxx
@@ -29,11 +29,9 @@
#define _GLOSDOC_HXX
#include <tools/string.hxx>
-#include <svl/svarray.hxx>
#include <com/sun/star/text/XAutoTextGroup.hpp>
class SwTextBlocks;
-class SvStrings;
class SwDocShell;
#ifndef SW_DECL_SWDOCSHELL_DEFINED
@@ -43,10 +41,7 @@ SV_DECL_REF( SwDocShell )
#endif
#include <cppuhelper/weakref.hxx>
-#ifndef INCLUDED_VECTOR
#include <vector>
-#define INCLUDED_VECTOR
-#endif
#include "swdllapi.h"
typedef ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XAutoTextGroup > AutoTextGroupRef;
@@ -67,11 +62,11 @@ class SW_DLLPUBLIC SwGlossaries
String m_sOldErrPath;
String m_sErrPath;
std::vector<String*> m_vPathArr;
- SvStrings *m_pGlosArr;
- sal_Bool m_bError;
+ std::vector<String*> *m_pGlosArr;
+ sal_Bool m_bError;
SW_DLLPRIVATE SwTextBlocks* GetGlosDoc(const String &rName, sal_Bool bCreate = sal_True) const;
- SW_DLLPRIVATE SvStrings *GetNameList();
+ SW_DLLPRIVATE std::vector<String*>* GetNameList();
// implementation in unoatxt.cxx
SW_DLLPRIVATE void RemoveFileFromList( const String& rGroup );
diff --git a/sw/source/ui/misc/glosdoc.cxx b/sw/source/ui/misc/glosdoc.cxx
index 1e35c49..39a7207 100644
--- a/sw/source/ui/misc/glosdoc.cxx
+++ b/sw/source/ui/misc/glosdoc.cxx
@@ -31,7 +31,6 @@
#include <com/sun/star/container/XNamed.hpp>
-#define _SVSTDARR_STRINGS
#include <unotools/transliterationwrapper.hxx>
#include <svl/svstdarr.hxx>
@@ -115,7 +114,7 @@ String SwGlossaries::GetDefName()
------------------------------------------------------------------------*/
sal_uInt16 SwGlossaries::GetGroupCnt()
{
- return GetNameList()->Count();
+ return static_cast<sal_uInt16>(GetNameList()->size());
}
/*------------------------------------------------------------------------
@@ -156,7 +155,7 @@ sal_Bool SwGlossaries::FindGroupName(String & rGroup)
String SwGlossaries::GetGroupName(sal_uInt16 nGroupId)
{
- OSL_ENSURE(nGroupId < m_pGlosArr->Count(), "Textbausteinarray ueberindiziert");
+ OSL_ENSURE(static_cast<size_t>(nGroupId) < m_pGlosArr->size(), "Textbausteinarray ueberindiziert");
return *(*m_pGlosArr)[nGroupId];
}
@@ -181,23 +180,18 @@ String SwGlossaries::GetGroupTitle( const String& rGroupName )
SwTextBlocks* SwGlossaries::GetGroupDoc(const String &rName,
sal_Bool bCreate) const
{
- // insert to the list of text blocks if applicable
+ // insert to the list of text blocks if applicable
if(bCreate && m_pGlosArr)
{
- const String aName(rName);
- const sal_uInt16 nCount = m_pGlosArr->Count();
- sal_uInt16 i;
-
- for( i = 0; i < nCount; ++i)
+ std::vector<String*>::const_iterator it(m_pGlosArr->begin());
+ for(; it != m_pGlosArr->end(); ++it)
{
- const String *pName = (*m_pGlosArr)[i];
- if(*pName == aName)
+ if(**it == rName)
break;
}
- if(i == nCount)
+ if( it == m_pGlosArr->end() )
{ // block not in the list
- String *pTmp = new String(aName);
- m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
+ m_pGlosArr->push_back(new String(rName));
}
}
return GetGlosDoc( rName, bCreate );
@@ -227,10 +221,7 @@ sal_Bool SwGlossaries::NewGroupDoc(String& rGroupName, const String& rTitle)
SwTextBlocks *pBlock = GetGlosDoc( sNewGroup );
if(pBlock)
{
- String *pTmp =
- new String(sNewGroup);
- SvStrings* pList = GetNameList();
- pList->Insert(pTmp, pList->Count());
+ GetNameList()->push_back(new String(sNewGroup));
pBlock->SetName(rTitle);
PutGroupDoc(pBlock);
rGroupName = sNewGroup;
@@ -279,11 +270,10 @@ sal_Bool SwGlossaries::RenameGroupDoc(
rNewGroup = sNewFileName.Copy(0, nFileNameLen);
rNewGroup += GLOS_DELIM;
rNewGroup += String::CreateFromInt32(nNewPath);
- String *pTmp = new String(rNewGroup);
if(!m_pGlosArr)
GetNameList();
else
- m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
+ m_pGlosArr->push_back(new String(rNewGroup));
sNewFilePath += INET_PATH_TOKEN;
sNewFilePath += sNewFileName ;
@@ -326,20 +316,13 @@ sal_Bool SwGlossaries::DelGroupDoc(const String &rName)
SwGlossaries::~SwGlossaries()
{
- sal_uInt16 nCount = m_pGlosArr? m_pGlosArr->Count() : 0;
- sal_uInt16 i;
-
- for( i = 0; i < nCount; ++i)
- {
- String *pTmp = (*m_pGlosArr)[i];
- delete pTmp;
- }
+ for(std::vector<String*>::const_iterator it(m_pGlosArr->begin()); it != m_pGlosArr->end(); ++it)
+ delete *it;
+ delete m_pGlosArr;
for(std::vector<String*>::const_iterator it(m_vPathArr.begin()); it != m_vPathArr.end(); ++it)
delete *it;
- delete m_pGlosArr;
-
InvalidateUNOOjects();
}
@@ -383,37 +366,37 @@ SwTextBlocks* SwGlossaries::GetGlosDoc( const String &rName, sal_Bool bCreate )
/*------------------------------------------------------------------------
Description: access to the list of names; read in if applicable
------------------------------------------------------------------------*/
-SvStrings* SwGlossaries::GetNameList()
+std::vector<String*>* SwGlossaries::GetNameList()
{
if( !m_pGlosArr )
{
- m_pGlosArr = new SvStrings;
+ m_pGlosArr = new std::vector<String*>;
String sExt( SwGlossaries::GetExtension() );
for( size_t i = 0; i < m_vPathArr.size(); i++ )
{
- SvStrings aFiles( 16, 16 );
+ std::vector<String*> aFiles;
SWUnoHelper::UCB_GetFileListOfFolder( *m_vPathArr[i], aFiles, &sExt );
- for( sal_uInt16 nFiles = 0, nFEnd = aFiles.Count();
- nFiles < nFEnd; ++nFiles )
+ for( std::vector<String*>::const_iterator filesIt(aFiles.begin());
+ filesIt != aFiles.end(); ++filesIt)
{
- String* pTitle = aFiles[ nFiles ];
+ String *pTitle = *filesIt;
String sName( pTitle->Copy( 0, pTitle->Len() - sExt.Len() ));
sName += GLOS_DELIM;
sName += String::CreateFromInt32( static_cast<sal_Int16>(i) );
- m_pGlosArr->Insert( new String(sName), m_pGlosArr->Count() );
+ m_pGlosArr->push_back( new String(sName) );
// don't need any more these pointers
delete pTitle;
}
}
- if(!m_pGlosArr->Count())
+ if( m_pGlosArr->empty() )
{
// the standard block is inside of the path's first part
String *pTmp = new String( SwGlossaries::GetDefName() );
(*pTmp) += GLOS_DELIM;
(*pTmp) += '0';
- m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
+ m_pGlosArr->push_back( pTmp );
}
}
return m_pGlosArr;
@@ -432,10 +415,10 @@ SwGlossaries::SwGlossaries() :
/* --------------------------------------------------
* #61050# double paths cause irritation - get rid of it
* --------------------------------------------------*/
-sal_Bool lcl_FindSameEntry(const SvStrings& rDirArr, const String& rEntryURL)
+sal_Bool lcl_FindSameEntry(const std::vector<String*>& rDirArr, const String& rEntryURL)
{
- for(sal_uInt16 i = 0; i < rDirArr.Count(); i++)
- if(rEntryURL == (*rDirArr.GetObject(i)))
+ for(std::vector<String*>::const_iterator it(rDirArr.begin()); it != rDirArr.end(); ++it)
+ if( **it == rEntryURL )
return sal_True;
return sal_False;
}
@@ -454,7 +437,7 @@ void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
m_vPathArr.clear();
sal_uInt16 nTokenCount = m_aPath.GetTokenCount(SVT_SEARCHPATH_DELIMITER);
- SvStrings aDirArr;
+ std::vector<String*> aDirArr;
for( sal_uInt16 i = 0; i < nTokenCount; i++ )
{
String sPth(m_aPath.GetToken(i, SVT_SEARCHPATH_DELIMITER));
@@ -465,7 +448,7 @@ void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
{
continue;
}
- aDirArr.Insert(new String(sPth), aDirArr.Count());
+ aDirArr.push_back(new String(sPth));
if( !FStatHelper::IsFolder( sPth ) )
{
if( m_sErrPath.Len() )
@@ -476,7 +459,8 @@ void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
else
m_vPathArr.push_back(new String(sPth));
}
- aDirArr.DeleteAndDestroy(0, aDirArr.Count());
+ for(std::vector<String*>::const_iterator it(aDirArr.begin()); it != aDirArr.end(); ++it)
+ delete *it;
if(!nTokenCount ||
(m_sErrPath.Len() && (bPathChanged || m_sOldErrPath != m_sErrPath)) )
@@ -494,10 +478,8 @@ void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
if(m_pGlosArr)
{
- for(sal_uInt16 i = 0; i < m_pGlosArr->Count(); ++i)
- {
- delete (String *)(*m_pGlosArr)[i];
- }
+ for(std::vector<String*>::const_iterator it(m_pGlosArr->begin()); it != m_pGlosArr->end(); ++it)
+ delete *it;
DELETEZ(m_pGlosArr);
GetNameList();
}
@@ -520,11 +502,9 @@ void SwGlossaries::RemoveFileFromList( const String& rGroup )
{
if(m_pGlosArr)
{
- const sal_uInt16 nCount = m_pGlosArr->Count();
- for(sal_uInt16 i = 0; i < nCount; ++i)
+ for(std::vector<String*>::iterator it(m_pGlosArr->begin()); it != m_pGlosArr->end(); ++it)
{
- String *pTmp = (*m_pGlosArr)[i];
- if(*pTmp == rGroup)
+ if(**it == rGroup)
{
rtl::OUString aUName = rGroup;
{
@@ -569,8 +549,8 @@ void SwGlossaries::RemoveFileFromList( const String& rGroup )
}
}
- m_pGlosArr->Remove(i);
- delete pTmp;
+ delete *it;
+ m_pGlosArr->erase(it);
break;
}
}
diff --git a/sw/source/ui/utlui/gloslst.cxx b/sw/source/ui/utlui/gloslst.cxx
index 860b5d1..b19f92d 100644
--- a/sw/source/ui/utlui/gloslst.cxx
+++ b/sw/source/ui/utlui/gloslst.cxx
@@ -31,7 +31,6 @@
#define _SVSTDARR_STRINGSDTOR
#define _SVSTDARR_STRINGSISORTDTOR
-#define _SVSTDARR_STRINGS
#include <svl/svstdarr.hxx>
#include <tools/urlobj.hxx>
#include <vcl/dialog.hxx>
@@ -50,6 +49,8 @@
#include <gloslst.hxx>
#include <swunohelper.hxx>
+#include <vector>
+
#include <utlui.hrc>
#include <gloslst.hrc>
@@ -325,16 +326,15 @@ void SwGlossaryList::Update()
for( size_t nPath = 0; nPath < pPathArr->size(); nPath++ )
{
SvStringsDtor aFoundGroupNames;
- SvStrings aFiles( 16, 16 );
+ std::vector<String*> aFiles;
SvPtrarr aDateTimeArr( 16, 16 );
SWUnoHelper::UCB_GetFileListOfFolder( *(*pPathArr)[nPath], aFiles,
&sExt, &aDateTimeArr );
- for( sal_uInt16 nFiles = 0, nFEnd = aFiles.Count();
- nFiles < nFEnd; ++nFiles )
+ for( size_t nFiles = 0; nFiles < aFiles.size(); ++nFiles )
{
String* pTitle = aFiles[ nFiles ];
- ::DateTime* pDT = (::DateTime*) aDateTimeArr[ nFiles ];
+ ::DateTime* pDT = (::DateTime*) aDateTimeArr[ static_cast<sal_uInt16>(nFiles) ];
String sName( pTitle->Copy( 0, pTitle->Len() - sExt.Len() ));
--
1.7.7.4
--------------090003010206000902010305--
More information about the LibreOffice
mailing list