Kaydet (Commit) 2d2ef979 authored tarafından Xisco Fauli's avatar Xisco Fauli Kaydeden (comit) Noel Grandin

tdf#89329: use shared_ptr for pImpl in menuoptions

Change-Id: I93ece349dc15ea9af00c661ac34fed80a57ea3d2
Reviewed-on: https://gerrit.libreoffice.org/26318Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst dad8d71f
......@@ -25,6 +25,7 @@
#include <tools/link.hxx>
#include <osl/mutex.hxx>
#include <unotools/options.hxx>
#include <memory>
/*-************************************************************************************************************
@short forward declaration to our private date container implementation
......@@ -43,18 +44,6 @@ class SvtMenuOptions_Impl;
class SAL_WARN_UNUSED SVT_DLLPUBLIC SvtMenuOptions: public utl::detail::Options
{
public:
/*-****************************************************************************************************
@short standard constructor and destructor
@descr This will initialize an instance with default values.
We implement these class with a refcount mechanism! Every instance of this class increase it
at create and decrease it at delete time - but all instances use the same data container!
He is implemented as a static member ...
@seealso member m_nRefCount
@seealso member m_pDataContainer
*//*-*****************************************************************************************************/
SvtMenuOptions();
virtual ~SvtMenuOptions();
......@@ -91,17 +80,7 @@ class SAL_WARN_UNUSED SVT_DLLPUBLIC SvtMenuOptions: public utl::detail::Options
SVT_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex();
private:
/*Attention
Don't initialize these static members in these headers!
a) Double defined symbols will be detected ...
b) and unresolved externals exist at linking time.
Do it in your source only.
*/
static SvtMenuOptions_Impl* m_pDataContainer ;
static sal_Int32 m_nRefCount ;
std::shared_ptr<SvtMenuOptions_Impl> m_pImpl;
}; // class SvtMenuOptions
......
......@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svtools/menuoptions.hxx>
#include <unotools/configmgr.hxx>
#include <unotools/configitem.hxx>
......@@ -31,10 +30,8 @@
#include <list>
// namespaces
using namespace ::utl ;
using namespace ::osl ;
using namespace ::com::sun::star::uno ;
......@@ -58,37 +55,29 @@ using namespace ::com::sun::star::uno ;
#include <tools/link.hxx>
// private declarations!
class SvtMenuOptions_Impl : public ConfigItem
{
// private member
private:
bool m_bDontHideDisabledEntries ; /// cache "DontHideDisabledEntries" of Menu section
bool m_bFollowMouse ; /// cache "FollowMouse" of Menu section
TriState m_eMenuIcons ; /// cache "MenuIcons" of Menu section
// public methods
public:
// constructor / destructor
SvtMenuOptions_Impl();
virtual ~SvtMenuOptions_Impl();
// override methods of baseclass
/*-****************************************************************************************************
@short called for notify of configmanager
@descr These method is called from the ConfigManager before application ends or from the
......@@ -104,7 +93,6 @@ class SvtMenuOptions_Impl : public ConfigItem
// public interface
/*-****************************************************************************************************
@short access method to get internal values
@descr These methods give us a chance to regulate access to our internal values.
......@@ -124,10 +112,8 @@ class SvtMenuOptions_Impl : public ConfigItem
// tdf#93451: don't Commit() here, it's too early
}
// private methods
private:
virtual void ImplCommit() override;
......@@ -142,7 +128,6 @@ class SvtMenuOptions_Impl : public ConfigItem
static Sequence< OUString > impl_GetPropertyNames();
};
// constructor
SvtMenuOptions_Impl::SvtMenuOptions_Impl()
......@@ -215,7 +200,6 @@ SvtMenuOptions_Impl::SvtMenuOptions_Impl()
EnableNotification( seqNames );
}
// destructor
SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
......@@ -223,7 +207,6 @@ SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
assert(!IsModified()); // should have been committed
}
// public method
void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
......@@ -276,7 +259,6 @@ void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons);
}
// public method
void SvtMenuOptions_Impl::ImplCommit()
......@@ -315,7 +297,6 @@ void SvtMenuOptions_Impl::ImplCommit()
PutProperties( seqNames, seqValues );
}
// private method
Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames()
......@@ -334,77 +315,54 @@ Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames()
return seqPropertyNames;
}
// initialize static member
// DON'T DO IT IN YOUR HEADER!
// see definition for further information
SvtMenuOptions_Impl* SvtMenuOptions::m_pDataContainer = nullptr ;
sal_Int32 SvtMenuOptions::m_nRefCount = 0 ;
// constructor
std::weak_ptr<SvtMenuOptions_Impl> m_pMenuOptions;
SvtMenuOptions::SvtMenuOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetOwnStaticMutex() );
// Increase our refcount ...
++m_nRefCount;
// ... and initialize our data container only if it not already!
if( m_pDataContainer == nullptr )
{
m_pDataContainer = new SvtMenuOptions_Impl();
m_pImpl = m_pMenuOptions.lock();
if( !m_pImpl )
{
m_pImpl = std::make_shared<SvtMenuOptions_Impl>();
m_pMenuOptions = m_pImpl;
svtools::ItemHolder2::holdConfigItem(E_MENUOPTIONS);
}
}
// destructor
SvtMenuOptions::~SvtMenuOptions()
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetOwnStaticMutex() );
// Decrease our refcount.
--m_nRefCount;
// If last instance was deleted ...
// we must destroy our static data container!
if( m_nRefCount <= 0 )
{
delete m_pDataContainer;
m_pDataContainer = nullptr;
}
}
m_pImpl.reset();
}
// public method
bool SvtMenuOptions::IsEntryHidingEnabled() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->IsEntryHidingEnabled();
return m_pImpl->IsEntryHidingEnabled();
}
// public method
TriState SvtMenuOptions::GetMenuIconsState() const
{
MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->GetMenuIconsState();
return m_pImpl->GetMenuIconsState();
}
// public method
void SvtMenuOptions::SetMenuIconsState(TriState eState)
{
MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->SetMenuIconsState(eState);
m_pImpl->SetMenuIconsState(eState);
}
// private method
Mutex& SvtMenuOptions::GetOwnStaticMutex()
......
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