Kaydet (Commit) a9cfb745 authored tarafından Tobias Lippert's avatar Tobias Lippert Kaydeden (comit) Caolán McNamara

Replace handwritten reference counting with shared_ptr

This will help to avoid race conditions because the shared pointers
are thread safe and use atomic increments.

Conflicts:
	include/vcl/settings.hxx
	vcl/source/app/settings.cxx

Change-Id: Ie3d27d6412167855a0cea1442676b81b733c15e8
üst 441ef2e9
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <i18nlangtag/languagetag.hxx> #include <i18nlangtag/languagetag.hxx>
#include <unotools/syslocale.hxx> #include <unotools/syslocale.hxx>
#include <boost/shared_ptr.hpp>
class CollatorWrapper; class CollatorWrapper;
class LocaleDataWrapper; class LocaleDataWrapper;
...@@ -44,12 +46,11 @@ namespace vcl { ...@@ -44,12 +46,11 @@ namespace vcl {
class ImplMouseData class ImplMouseData
{ {
friend class MouseSettings; friend class MouseSettings;
public:
ImplMouseData(); ImplMouseData();
ImplMouseData( const ImplMouseData& rData ); ImplMouseData( const ImplMouseData& rData );
private: private:
sal_uLong mnRefCount;
sal_uLong mnOptions; sal_uLong mnOptions;
sal_uLong mnDoubleClkTime; sal_uLong mnDoubleClkTime;
long mnDoubleClkWidth; long mnDoubleClkWidth;
...@@ -97,7 +98,7 @@ class VCL_DLLPUBLIC MouseSettings ...@@ -97,7 +98,7 @@ class VCL_DLLPUBLIC MouseSettings
void CopyData(); void CopyData();
private: private:
ImplMouseData* mpData; boost::shared_ptr<ImplMouseData> mpData;
public: public:
MouseSettings(); MouseSettings();
...@@ -241,13 +242,12 @@ class ImplStyleData ...@@ -241,13 +242,12 @@ class ImplStyleData
{ {
friend class StyleSettings; friend class StyleSettings;
public:
ImplStyleData(); ImplStyleData();
ImplStyleData( const ImplStyleData& rData ); ImplStyleData( const ImplStyleData& rData );
void SetStandardStyles();
private: private:
sal_uLong mnRefCount; void SetStandardStyles();
Color maActiveBorderColor; Color maActiveBorderColor;
Color maActiveColor; Color maActiveColor;
Color maActiveColor2; Color maActiveColor2;
...@@ -434,7 +434,7 @@ class VCL_DLLPUBLIC StyleSettings ...@@ -434,7 +434,7 @@ class VCL_DLLPUBLIC StyleSettings
void CopyData(); void CopyData();
private: private:
ImplStyleData* mpData; boost::shared_ptr<ImplStyleData> mpData;
public: public:
StyleSettings(); StyleSettings();
...@@ -833,8 +833,8 @@ public: ...@@ -833,8 +833,8 @@ public:
void SetOptions( sal_uLong nOptions ) void SetOptions( sal_uLong nOptions )
{ CopyData(); mpData->mnOptions = nOptions; } { CopyData(); mpData->mnOptions = nOptions; }
sal_uLong GetOptions() const sal_uLong GetOptions() const;
{ return mpData->mnOptions; }
void SetAutoMnemonic( bool bAutoMnemonic ) void SetAutoMnemonic( bool bAutoMnemonic )
{ CopyData(); mpData->mnAutoMnemonic = (sal_uInt16)bAutoMnemonic; } { CopyData(); mpData->mnAutoMnemonic = (sal_uInt16)bAutoMnemonic; }
bool GetAutoMnemonic() const bool GetAutoMnemonic() const
...@@ -958,15 +958,15 @@ protected: ...@@ -958,15 +958,15 @@ protected:
class ImplMiscData class ImplMiscData
{ {
friend class MiscSettings; friend class MiscSettings;
public:
ImplMiscData(); ImplMiscData();
ImplMiscData( const ImplMiscData& rData ); ImplMiscData( const ImplMiscData& rData );
private: private:
sal_uLong mnRefCount; AutoState mnEnableATT;
AutoState mnEnableATT;
bool mbEnableLocalizedDecimalSep; bool mbEnableLocalizedDecimalSep;
AutoState mnDisablePrinting; AutoState mnDisablePrinting;
}; };
// ---------------- // ----------------
...@@ -978,7 +978,7 @@ class VCL_DLLPUBLIC MiscSettings ...@@ -978,7 +978,7 @@ class VCL_DLLPUBLIC MiscSettings
void CopyData(); void CopyData();
private: private:
ImplMiscData* mpData; boost::shared_ptr<ImplMiscData> mpData;
public: public:
MiscSettings(); MiscSettings();
...@@ -1006,12 +1006,11 @@ public: ...@@ -1006,12 +1006,11 @@ public:
class ImplHelpData class ImplHelpData
{ {
friend class HelpSettings; friend class HelpSettings;
public:
ImplHelpData(); ImplHelpData();
ImplHelpData( const ImplHelpData& rData ); ImplHelpData( const ImplHelpData& rData );
private: private:
sal_uLong mnRefCount;
sal_uLong mnOptions; sal_uLong mnOptions;
sal_uLong mnTipDelay; sal_uLong mnTipDelay;
sal_uLong mnTipTimeout; sal_uLong mnTipTimeout;
...@@ -1027,7 +1026,7 @@ class VCL_DLLPUBLIC HelpSettings ...@@ -1027,7 +1026,7 @@ class VCL_DLLPUBLIC HelpSettings
void CopyData(); void CopyData();
private: private:
ImplHelpData* mpData; boost::shared_ptr<ImplHelpData> mpData;
public: public:
HelpSettings(); HelpSettings();
...@@ -1063,14 +1062,13 @@ public: ...@@ -1063,14 +1062,13 @@ public:
// ----------------------- // -----------------------
class ImplAllSettingsData class ImplAllSettingsData
{ {
friend class AllSettings; public:
ImplAllSettingsData();
ImplAllSettingsData(); ImplAllSettingsData( const ImplAllSettingsData& rData );
ImplAllSettingsData( const ImplAllSettingsData& rData ); ~ImplAllSettingsData();
~ImplAllSettingsData();
friend class AllSettings;
private: private:
sal_uLong mnRefCount;
MouseSettings maMouseSettings; MouseSettings maMouseSettings;
StyleSettings maStyleSettings; StyleSettings maStyleSettings;
MiscSettings maMiscSettings; MiscSettings maMiscSettings;
...@@ -1111,7 +1109,7 @@ class VCL_DLLPUBLIC AllSettings ...@@ -1111,7 +1109,7 @@ class VCL_DLLPUBLIC AllSettings
void CopyData(); void CopyData();
private: private:
ImplAllSettingsData* mpData; boost::shared_ptr<ImplAllSettingsData> mpData;
public: public:
AllSettings(); AllSettings();
...@@ -1125,8 +1123,7 @@ public: ...@@ -1125,8 +1123,7 @@ public:
void SetStyleSettings( const StyleSettings& rSet ) void SetStyleSettings( const StyleSettings& rSet )
{ CopyData(); mpData->maStyleSettings = rSet; } { CopyData(); mpData->maStyleSettings = rSet; }
const StyleSettings& GetStyleSettings() const const StyleSettings& GetStyleSettings() const;
{ return mpData->maStyleSettings; }
void SetMiscSettings( const MiscSettings& rSet ) void SetMiscSettings( const MiscSettings& rSet )
{ CopyData(); mpData->maMiscSettings = rSet; } { CopyData(); mpData->maMiscSettings = rSet; }
......
...@@ -48,6 +48,9 @@ using namespace ::com::sun::star; ...@@ -48,6 +48,9 @@ using namespace ::com::sun::star;
#include "svdata.hxx" #include "svdata.hxx"
#include "impimagetree.hxx" #include "impimagetree.hxx"
#include <boost/make_shared.hpp>
// ======================================================================= // =======================================================================
...@@ -55,7 +58,6 @@ using namespace ::com::sun::star; ...@@ -55,7 +58,6 @@ using namespace ::com::sun::star;
ImplMouseData::ImplMouseData() ImplMouseData::ImplMouseData()
{ {
mnRefCount = 1;
mnOptions = 0; mnOptions = 0;
mnDoubleClkTime = 500; mnDoubleClkTime = 500;
mnDoubleClkWidth = 2; mnDoubleClkWidth = 2;
...@@ -83,7 +85,6 @@ ImplMouseData::ImplMouseData() ...@@ -83,7 +85,6 @@ ImplMouseData::ImplMouseData()
ImplMouseData::ImplMouseData( const ImplMouseData& rData ) ImplMouseData::ImplMouseData( const ImplMouseData& rData )
{ {
mnRefCount = 1;
mnOptions = rData.mnOptions; mnOptions = rData.mnOptions;
mnDoubleClkTime = rData.mnDoubleClkTime; mnDoubleClkTime = rData.mnDoubleClkTime;
mnDoubleClkWidth = rData.mnDoubleClkWidth; mnDoubleClkWidth = rData.mnDoubleClkWidth;
...@@ -110,49 +111,28 @@ ImplMouseData::ImplMouseData( const ImplMouseData& rData ) ...@@ -110,49 +111,28 @@ ImplMouseData::ImplMouseData( const ImplMouseData& rData )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MouseSettings::MouseSettings() MouseSettings::MouseSettings()
: mpData(boost::make_shared<ImplMouseData>())
{ {
mpData = new ImplMouseData();
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MouseSettings::MouseSettings( const MouseSettings& rSet ) MouseSettings::MouseSettings( const MouseSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MouseSettings: RefCount overflow" );
// copy shared instance data and increment reference counter
mpData = rSet.mpData; mpData = rSet.mpData;
mpData->mnRefCount++;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MouseSettings::~MouseSettings() MouseSettings::~MouseSettings()
{ {
// delete data if last reference
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
const MouseSettings& MouseSettings::operator =( const MouseSettings& rSet ) const MouseSettings& MouseSettings::operator =( const MouseSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MouseSettings: RefCount overflow" );
// increment reference counter first, to be able to assign oneself
rSet.mpData->mnRefCount++;
// delete data if last reference
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
mpData = rSet.mpData; mpData = rSet.mpData;
return *this; return *this;
} }
...@@ -160,11 +140,9 @@ const MouseSettings& MouseSettings::operator =( const MouseSettings& rSet ) ...@@ -160,11 +140,9 @@ const MouseSettings& MouseSettings::operator =( const MouseSettings& rSet )
void MouseSettings::CopyData() void MouseSettings::CopyData()
{ {
// copy if another references exist // copy if other references exist
if ( mpData->mnRefCount != 1 ) if ( ! mpData.unique() ) {
{ mpData = boost::make_shared<ImplMouseData>(*mpData);
mpData->mnRefCount--;
mpData = new ImplMouseData( *mpData );
} }
} }
...@@ -208,7 +186,6 @@ ImplStyleData::ImplStyleData() : ...@@ -208,7 +186,6 @@ ImplStyleData::ImplStyleData() :
maPersonaHeaderBitmap(), maPersonaHeaderBitmap(),
maPersonaFooterBitmap() maPersonaFooterBitmap()
{ {
mnRefCount = 1;
mnScrollBarSize = 16; mnScrollBarSize = 16;
mnMinThumbSize = 16; mnMinThumbSize = 16;
mnSplitSize = 3; mnSplitSize = 3;
...@@ -318,7 +295,6 @@ ImplStyleData::ImplStyleData( const ImplStyleData& rData ) : ...@@ -318,7 +295,6 @@ ImplStyleData::ImplStyleData( const ImplStyleData& rData ) :
maPersonaHeaderBitmap( rData.maPersonaHeaderBitmap ), maPersonaHeaderBitmap( rData.maPersonaHeaderBitmap ),
maPersonaFooterBitmap( rData.maPersonaFooterBitmap ) maPersonaFooterBitmap( rData.maPersonaFooterBitmap )
{ {
mnRefCount = 1;
mnBorderSize = rData.mnBorderSize; mnBorderSize = rData.mnBorderSize;
mnTitleHeight = rData.mnTitleHeight; mnTitleHeight = rData.mnTitleHeight;
mnFloatTitleHeight = rData.mnFloatTitleHeight; mnFloatTitleHeight = rData.mnFloatTitleHeight;
...@@ -463,30 +439,21 @@ void ImplStyleData::SetStandardStyles() ...@@ -463,30 +439,21 @@ void ImplStyleData::SetStandardStyles()
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
StyleSettings::StyleSettings() StyleSettings::StyleSettings()
: mpData(boost::make_shared<ImplStyleData>())
{ {
mpData = new ImplStyleData();
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
StyleSettings::StyleSettings( const StyleSettings& rSet ) StyleSettings::StyleSettings( const StyleSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "StyleSettings: RefCount overflow" );
// copy shared instance data and increment reference counter
mpData = rSet.mpData; mpData = rSet.mpData;
mpData->mnRefCount++;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
StyleSettings::~StyleSettings() StyleSettings::~StyleSettings()
{ {
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
} }
const Size& StyleSettings::GetListBoxPreviewDefaultPixelSize() const const Size& StyleSettings::GetListBoxPreviewDefaultPixelSize() const
...@@ -853,19 +820,7 @@ Color StyleSettings::GetSeparatorColor() const ...@@ -853,19 +820,7 @@ Color StyleSettings::GetSeparatorColor() const
const StyleSettings& StyleSettings::operator =( const StyleSettings& rSet ) const StyleSettings& StyleSettings::operator =( const StyleSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "StyleSettings: RefCount overflow" );
// increase reference counter first, to be able to assign oneself
rSet.mpData->mnRefCount++;
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
mpData = rSet.mpData; mpData = rSet.mpData;
return *this; return *this;
} }
...@@ -874,10 +829,8 @@ const StyleSettings& StyleSettings::operator =( const StyleSettings& rSet ) ...@@ -874,10 +829,8 @@ const StyleSettings& StyleSettings::operator =( const StyleSettings& rSet )
void StyleSettings::CopyData() void StyleSettings::CopyData()
{ {
// copy if other references exist // copy if other references exist
if ( mpData->mnRefCount != 1 ) if ( ! mpData.unique() ) {
{ mpData = boost::make_shared<ImplStyleData>(*mpData);
mpData->mnRefCount--;
mpData = new ImplStyleData( *mpData );
} }
} }
...@@ -1002,7 +955,6 @@ bool StyleSettings::operator ==( const StyleSettings& rSet ) const ...@@ -1002,7 +955,6 @@ bool StyleSettings::operator ==( const StyleSettings& rSet ) const
ImplMiscData::ImplMiscData() ImplMiscData::ImplMiscData()
{ {
mnRefCount = 1;
mnEnableATT = AUTO_STATE_AUTO; mnEnableATT = AUTO_STATE_AUTO;
mnDisablePrinting = AUTO_STATE_AUTO; mnDisablePrinting = AUTO_STATE_AUTO;
static const char* pEnv = getenv("SAL_DECIMALSEP_ENABLED" ); // set default without UI static const char* pEnv = getenv("SAL_DECIMALSEP_ENABLED" ); // set default without UI
...@@ -1013,7 +965,6 @@ ImplMiscData::ImplMiscData() ...@@ -1013,7 +965,6 @@ ImplMiscData::ImplMiscData()
ImplMiscData::ImplMiscData( const ImplMiscData& rData ) ImplMiscData::ImplMiscData( const ImplMiscData& rData )
{ {
mnRefCount = 1;
mnEnableATT = rData.mnEnableATT; mnEnableATT = rData.mnEnableATT;
mnDisablePrinting = rData.mnDisablePrinting; mnDisablePrinting = rData.mnDisablePrinting;
mbEnableLocalizedDecimalSep = rData.mbEnableLocalizedDecimalSep; mbEnableLocalizedDecimalSep = rData.mbEnableLocalizedDecimalSep;
...@@ -1022,49 +973,28 @@ ImplMiscData::ImplMiscData( const ImplMiscData& rData ) ...@@ -1022,49 +973,28 @@ ImplMiscData::ImplMiscData( const ImplMiscData& rData )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MiscSettings::MiscSettings() MiscSettings::MiscSettings()
: mpData(boost::make_shared<ImplMiscData>())
{ {
mpData = new ImplMiscData();
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MiscSettings::MiscSettings( const MiscSettings& rSet ) MiscSettings::MiscSettings( const MiscSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MiscSettings: RefCount overflow" );
// copy shared instance data and increment reference counter
mpData = rSet.mpData; mpData = rSet.mpData;
mpData->mnRefCount++;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
MiscSettings::~MiscSettings() MiscSettings::~MiscSettings()
{ {
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
const MiscSettings& MiscSettings::operator =( const MiscSettings& rSet ) const MiscSettings& MiscSettings::operator =( const MiscSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MiscSettings: RefCount overflow" );
// increase reference counter first, to be able to assign oneself
rSet.mpData->mnRefCount++;
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
mpData = rSet.mpData; mpData = rSet.mpData;
return *this; return *this;
} }
...@@ -1073,10 +1003,8 @@ const MiscSettings& MiscSettings::operator =( const MiscSettings& rSet ) ...@@ -1073,10 +1003,8 @@ const MiscSettings& MiscSettings::operator =( const MiscSettings& rSet )
void MiscSettings::CopyData() void MiscSettings::CopyData()
{ {
// copy if other references exist // copy if other references exist
if ( mpData->mnRefCount != 1 ) if ( ! mpData.unique() ) {
{ mpData = boost::make_shared<ImplMiscData>(*mpData);
mpData->mnRefCount--;
mpData = new ImplMiscData( *mpData );
} }
} }
...@@ -1251,7 +1179,6 @@ bool MiscSettings::GetEnableLocalizedDecimalSep() const ...@@ -1251,7 +1179,6 @@ bool MiscSettings::GetEnableLocalizedDecimalSep() const
ImplHelpData::ImplHelpData() ImplHelpData::ImplHelpData()
{ {
mnRefCount = 1;
mnOptions = 0; mnOptions = 0;
mnTipDelay = 500; mnTipDelay = 500;
mnTipTimeout = 3000; mnTipTimeout = 3000;
...@@ -1262,7 +1189,6 @@ ImplHelpData::ImplHelpData() ...@@ -1262,7 +1189,6 @@ ImplHelpData::ImplHelpData()
ImplHelpData::ImplHelpData( const ImplHelpData& rData ) ImplHelpData::ImplHelpData( const ImplHelpData& rData )
{ {
mnRefCount = 1;
mnOptions = rData.mnOptions; mnOptions = rData.mnOptions;
mnTipDelay = rData.mnTipDelay; mnTipDelay = rData.mnTipDelay;
mnTipTimeout = rData.mnTipTimeout; mnTipTimeout = rData.mnTipTimeout;
...@@ -1272,49 +1198,28 @@ ImplHelpData::ImplHelpData( const ImplHelpData& rData ) ...@@ -1272,49 +1198,28 @@ ImplHelpData::ImplHelpData( const ImplHelpData& rData )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
HelpSettings::HelpSettings() HelpSettings::HelpSettings()
: mpData(boost::make_shared<ImplHelpData>())
{ {
mpData = new ImplHelpData();
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
HelpSettings::HelpSettings( const HelpSettings& rSet ) HelpSettings::HelpSettings( const HelpSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "HelpSettings: RefCount overflow" );
// copy shared instance data and increment reference counter
mpData = rSet.mpData; mpData = rSet.mpData;
mpData->mnRefCount++;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
HelpSettings::~HelpSettings() HelpSettings::~HelpSettings()
{ {
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
const HelpSettings& HelpSettings::operator =( const HelpSettings& rSet ) const HelpSettings& HelpSettings::operator =( const HelpSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "HelpSettings: RefCount overflow" );
// increase reference counter first, to be able to assign oneself
rSet.mpData->mnRefCount++;
// delete data if last reference
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
mpData = rSet.mpData; mpData = rSet.mpData;
return *this; return *this;
} }
...@@ -1322,11 +1227,9 @@ const HelpSettings& HelpSettings::operator =( const HelpSettings& rSet ) ...@@ -1322,11 +1227,9 @@ const HelpSettings& HelpSettings::operator =( const HelpSettings& rSet )
void HelpSettings::CopyData() void HelpSettings::CopyData()
{ {
// copy of other references exist // copy if other references exist
if ( mpData->mnRefCount != 1 ) if ( ! mpData.unique() ) {
{ mpData = boost::make_shared<ImplHelpData>(*mpData);
mpData->mnRefCount--;
mpData = new ImplHelpData( *mpData );
} }
} }
...@@ -1353,7 +1256,6 @@ ImplAllSettingsData::ImplAllSettingsData() ...@@ -1353,7 +1256,6 @@ ImplAllSettingsData::ImplAllSettingsData()
maLocale( LANGUAGE_SYSTEM ), maLocale( LANGUAGE_SYSTEM ),
maUILocale( LANGUAGE_SYSTEM ) maUILocale( LANGUAGE_SYSTEM )
{ {
mnRefCount = 1;
mnSystemUpdate = SETTINGS_ALLSETTINGS; mnSystemUpdate = SETTINGS_ALLSETTINGS;
mnWindowUpdate = SETTINGS_ALLSETTINGS; mnWindowUpdate = SETTINGS_ALLSETTINGS;
mpLocaleDataWrapper = NULL; mpLocaleDataWrapper = NULL;
...@@ -1373,7 +1275,6 @@ ImplAllSettingsData::ImplAllSettingsData( const ImplAllSettingsData& rData ) : ...@@ -1373,7 +1275,6 @@ ImplAllSettingsData::ImplAllSettingsData( const ImplAllSettingsData& rData ) :
maLocale( rData.maLocale ), maLocale( rData.maLocale ),
maUILocale( rData.maUILocale ) maUILocale( rData.maUILocale )
{ {
mnRefCount = 1;
mnSystemUpdate = rData.mnSystemUpdate; mnSystemUpdate = rData.mnSystemUpdate;
mnWindowUpdate = rData.mnWindowUpdate; mnWindowUpdate = rData.mnWindowUpdate;
// Pointer couldn't shared and objects haven't a copy ctor // Pointer couldn't shared and objects haven't a copy ctor
...@@ -1400,51 +1301,28 @@ ImplAllSettingsData::~ImplAllSettingsData() ...@@ -1400,51 +1301,28 @@ ImplAllSettingsData::~ImplAllSettingsData()
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
AllSettings::AllSettings() AllSettings::AllSettings()
: mpData(boost::make_shared<ImplAllSettingsData>())
{ {
mpData = new ImplAllSettingsData();
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
AllSettings::AllSettings( const AllSettings& rSet ) AllSettings::AllSettings( const AllSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "Settings: RefCount overflow" );
// copy shared instance data and increse reference counter
mpData = rSet.mpData; mpData = rSet.mpData;
mpData->mnRefCount++;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
AllSettings::~AllSettings() AllSettings::~AllSettings()
{ {
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
const AllSettings& AllSettings::operator =( const AllSettings& rSet ) const AllSettings& AllSettings::operator =( const AllSettings& rSet )
{ {
DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "AllSettings: RefCount overflow" );
// increase reference counter first, to be able to assign oneself
rSet.mpData->mnRefCount++;
// if last reference then delete data
if ( mpData->mnRefCount == 1 )
delete mpData;
else
mpData->mnRefCount--;
mpData = rSet.mpData; mpData = rSet.mpData;
return *this; return *this;
} }
...@@ -1452,13 +1330,11 @@ const AllSettings& AllSettings::operator =( const AllSettings& rSet ) ...@@ -1452,13 +1330,11 @@ const AllSettings& AllSettings::operator =( const AllSettings& rSet )
void AllSettings::CopyData() void AllSettings::CopyData()
{ {
// copy if other references exist // copy if other references exist
if ( mpData->mnRefCount != 1 ) if ( ! mpData.unique() ) {
{ mpData = boost::make_shared<ImplAllSettingsData>(*mpData);
mpData->mnRefCount--;
mpData = new ImplAllSettingsData( *mpData );
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1747,4 +1623,16 @@ void AllSettings::LocaleSettingsChanged( sal_uInt32 nHint ) ...@@ -1747,4 +1623,16 @@ void AllSettings::LocaleSettingsChanged( sal_uInt32 nHint )
Application::SetSettings( aAllSettings ); Application::SetSettings( aAllSettings );
} }
const StyleSettings&
AllSettings::GetStyleSettings() const
{
return mpData->maStyleSettings;
}
sal_uLong
StyleSettings::GetOptions() const
{
return mpData->mnOptions;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment