summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorArnaud Versini <arnaud.versini@gmail.com>2015-05-23 14:32:22 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-05-26 08:13:35 +0000
commit6a4a55d5f48e52dd4a5094028d729ac4cc9d766e (patch)
treeec74c881092a920fae623f423566a9039626d2e0 /basic
parentb255913e412a7894928f92e29d6445bc412a87db (diff)
BASIC: User std::unique_ptr in basic runtime
Change-Id: Iac7efdad78cf2f827cbddbc671dd0d1b5ae1d467 Reviewed-on: https://gerrit.libreoffice.org/15874 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/inc/runtime.hxx20
-rw-r--r--basic/source/runtime/methods.cxx10
-rw-r--r--basic/source/runtime/methods1.cxx2
-rw-r--r--basic/source/runtime/runtime.cxx43
4 files changed, 34 insertions, 41 deletions
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index fc7d093d26c6..f2bcba9c72c3 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -31,6 +31,7 @@
#include <i18nlangtag/lang.h>
#include <vector>
+#include <memory>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/container/XEnumeration.hpp>
#include <unotools/localedatawrapper.hxx>
@@ -134,11 +135,14 @@ class SbiInstance
SbiRTLData aRTLData;
- SbiIoSystem* pIosys; // file system
- SbiDdeControl* pDdeCtrl; // DDE
- SbiDllMgr* pDllMgr; // DLL-Calls (DECLARE)
+ // file system
+ std::unique_ptr<SbiIoSystem> pIosys;
+ // DDE
+ std::unique_ptr<SbiDdeControl> pDdeCtrl;
+ // DLL-Calls (DECLARE)
+ std::unique_ptr<SbiDllMgr> pDllMgr;
+ std::unique_ptr<SvNumberFormatter> pNumberFormatter;
StarBASIC* pBasic;
- SvNumberFormatter* pNumberFormatter;
LanguageType meFormatterLangType;
DateFormat meFormatterDateFormat;
sal_uInt32 nStdDateIdx, nStdTimeIdx, nStdDateTimeIdx;
@@ -185,8 +189,8 @@ public:
SbMethod* GetCaller( sal_uInt16 );
SbModule* GetActiveModule();
- SbiIoSystem* GetIoSystem() { return pIosys; }
- SbiDdeControl* GetDdeControl() { return pDdeCtrl; }
+ SbiIoSystem* GetIoSystem() { return pIosys.get(); }
+ SbiDdeControl* GetDdeControl() { return pDdeCtrl.get(); }
StarBASIC* GetBasic() { return pBasic; }
SbiDllMgr* GetDllMgr();
SbiRTLData* GetRTLData() const { return const_cast<SbiRTLData*>(&aRTLData); }
@@ -197,8 +201,8 @@ public:
sal_uInt32 GetStdDateTimeIdx() const { return nStdDateTimeIdx; }
// offer NumberFormatter also static
- static void PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
- sal_uInt32 &rnStdDateIdx, sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
+ static SvNumberFormatter* PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
+ sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
LanguageType* peFormatterLangType=NULL, DateFormat* peFormatterDateFormat=NULL );
};
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index a2bb3467e015..ea1d8c207c00 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2137,7 +2137,7 @@ RTLFUNC(DateValue)
else
{
sal_uInt32 n; // Dummy
- SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, n, n );
}
sal_uInt32 nIndex = 0;
@@ -2205,7 +2205,7 @@ RTLFUNC(TimeValue)
else
{
sal_uInt32 n;
- SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, n, n );
}
sal_uInt32 nIndex = 0;
@@ -2428,7 +2428,7 @@ RTLFUNC(Time)
else
{
sal_uInt32 n; // Dummy
- SbiInstance::PrepareNumberFormatter( pFormatter, n, nIndex, n );
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, nIndex, n );
}
pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
@@ -2485,7 +2485,7 @@ RTLFUNC(Date)
else
{
sal_uInt32 n;
- SbiInstance::PrepareNumberFormatter( pFormatter, nIndex, n, n );
+ pFormatter = SbiInstance::PrepareNumberFormatter( nIndex, n, n );
}
pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
@@ -3274,7 +3274,7 @@ RTLFUNC(FileDateTime)
else
{
sal_uInt32 n;
- SbiInstance::PrepareNumberFormatter( pFormatter, n, n, nIndex );
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, n, nIndex );
}
OUString aRes;
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index a1eca5f5a1ae..66e66d735b35 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -2542,7 +2542,7 @@ RTLFUNC(FormatDateTime)
else
{
sal_uInt32 n; // Dummy
- SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, n, n );
}
LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 5fc439950d94..dac00d643d1e 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -302,9 +302,7 @@ void SbiInstance::CalcBreakCallLevel( sal_uInt16 nFlags )
SbiInstance::SbiInstance( StarBASIC* p )
: pIosys(new SbiIoSystem)
, pDdeCtrl(new SbiDdeControl)
- , pDllMgr(0) // on demand
, pBasic(p)
- , pNumberFormatter(0)
, meFormatterLangType(LANGUAGE_DONTKNOW)
, meFormatterDateFormat(YMD)
, nStdDateIdx(0)
@@ -329,10 +327,6 @@ SbiInstance::~SbiInstance()
delete pRun;
pRun = p;
}
- delete pIosys;
- delete pDdeCtrl;
- delete pDllMgr;
- delete pNumberFormatter;
try
{
@@ -351,17 +345,15 @@ SbiInstance::~SbiInstance()
{
SAL_WARN("basic", "SbiInstance::~SbiInstance: caught an exception while disposing the components!" );
}
-
- ComponentVector.clear();
}
SbiDllMgr* SbiInstance::GetDllMgr()
{
if( !pDllMgr )
{
- pDllMgr = new SbiDllMgr;
+ pDllMgr.reset(new SbiDllMgr);
}
- return pDllMgr;
+ return pDllMgr.get();
}
// #39629 create NumberFormatter with the help of a static method now
@@ -375,25 +367,25 @@ SvNumberFormatter* SbiInstance::GetNumberFormatter()
if( eLangType != meFormatterLangType ||
eDate != meFormatterDateFormat )
{
- delete pNumberFormatter;
- pNumberFormatter = NULL;
+ pNumberFormatter.reset(nullptr);
}
}
meFormatterLangType = eLangType;
meFormatterDateFormat = eDate;
if( !pNumberFormatter )
{
- PrepareNumberFormatter( pNumberFormatter, nStdDateIdx, nStdTimeIdx, nStdDateTimeIdx,
- &meFormatterLangType, &meFormatterDateFormat );
+ pNumberFormatter.reset(PrepareNumberFormatter( nStdDateIdx, nStdTimeIdx, nStdDateTimeIdx,
+ &meFormatterLangType, &meFormatterDateFormat ));
}
- return pNumberFormatter;
+ return pNumberFormatter.get();
}
// #39629 offer NumberFormatter static too
-void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
- sal_uInt32 &rnStdDateIdx, sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
+SvNumberFormatter* SbiInstance::PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
+ sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
LanguageType* peFormatterLangType, DateFormat* peFormatterDateFormat )
{
+ SvNumberFormatter* pNumberFormater = nullptr;
LanguageType eLangType;
if( peFormatterLangType )
{
@@ -414,10 +406,10 @@ void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
eDate = aSysLocale.GetLocaleData().getDateFormat();
}
- rpNumberFormatter = new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType );
+ pNumberFormater = new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType );
sal_Int32 nCheckPos = 0; short nType;
- rnStdTimeIdx = rpNumberFormatter->GetStandardFormat( css::util::NumberFormat::TIME, eLangType );
+ rnStdTimeIdx = pNumberFormater->GetStandardFormat( css::util::NumberFormat::TIME, eLangType );
// the formatter's standard templates have only got a two-digit date
// -> registering an own format
@@ -436,14 +428,15 @@ void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
case YMD: aDateStr = "YYYY/MM/DD"; break;
}
OUString aStr( aDateStr ); // PutandConvertEntry() modifies string!
- rpNumberFormatter->PutandConvertEntry( aStr, nCheckPos, nType,
+ pNumberFormater->PutandConvertEntry( aStr, nCheckPos, nType,
rnStdDateIdx, LANGUAGE_ENGLISH_US, eLangType );
nCheckPos = 0;
OUString aStrHHMMSS(" HH:MM:SS");
aDateStr += aStrHHMMSS;
aStr = aDateStr;
- rpNumberFormatter->PutandConvertEntry( aStr, nCheckPos, nType,
+ pNumberFormater->PutandConvertEntry( aStr, nCheckPos, nType,
rnStdDateTimeIdx, LANGUAGE_ENGLISH_US, eLangType );
+ return pNumberFormater;
}
@@ -574,7 +567,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart )
pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), mpExtCaller(0), m_nLastTime(0)
{
nFlags = pe ? pe->GetDebugFlags() : 0;
- pIosys = pInst->pIosys;
+ pIosys = pInst->GetIoSystem();
pArgvStk = NULL;
pGosubStk = NULL;
pForStk = NULL;
@@ -600,11 +593,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart )
nOps = 0;
refExprStk = new SbxArray;
SetVBAEnabled( pMod->IsVBACompat() );
-#if defined __GNUC__
- SetParameters( pe ? pe->GetParameters() : (class SbxArray *)NULL );
-#else
- SetParameters( pe ? pe->GetParameters() : NULL );
-#endif
+ SetParameters( pe ? pe->GetParameters() : nullptr );
pRefSaveList = NULL;
pItemStoreList = NULL;
}