[Libreoffice-commits] core.git: include/comphelper sw/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Tue Mar 31 16:12:20 UTC 2020
include/comphelper/flagguard.hxx | 29 ++++++++++++++++-------------
sw/source/filter/ww8/docxsdrexport.cxx | 15 +++------------
2 files changed, 19 insertions(+), 25 deletions(-)
New commits:
commit 00748b30660abe34ae980cdc7b1a24ac305a90b2
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Mar 31 17:15:36 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Mar 31 18:11:45 2020 +0200
Introduce comphelper::ValueRestorationGuard extending FlagRestorationGuard
... to any value type.
Change-Id: I808f4729478cb3f90a86ef30be8158ebc40a6b96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91428
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/include/comphelper/flagguard.hxx b/include/comphelper/flagguard.hxx
index 44d2f4f73ab4..14eee07a8401 100644
--- a/include/comphelper/flagguard.hxx
+++ b/include/comphelper/flagguard.hxx
@@ -21,37 +21,40 @@
#define INCLUDED_COMPHELPER_FLAGGUARD_HXX
#include <comphelper/scopeguard.hxx>
-
+#include <utility>
namespace comphelper
{
- //= FlagRestorationGuard
+ //= ValueRestorationGuard
- // note: can't store the originalValue in a FlagRestorationGuard member,
+ // note: can't store the originalValue in a ValueRestorationGuard member,
// because it will be used from base class dtor
- struct FlagRestorationGuard_Impl
+ template <typename T> struct ValueRestorationGuard_Impl
{
- bool & rFlag;
- bool const originalValue;
- FlagRestorationGuard_Impl(bool & i_flagRef)
- : rFlag(i_flagRef), originalValue(i_flagRef) {}
+ T& rVal;
+ T const originalValue;
+ ValueRestorationGuard_Impl(T& i_valRef)
+ : rVal(i_valRef), originalValue(i_valRef) {}
void operator()()
{
- rFlag = originalValue;
+ rVal = originalValue;
}
};
- class FlagRestorationGuard : public ScopeGuard<FlagRestorationGuard_Impl>
+ template <typename T>
+ class ValueRestorationGuard : public ScopeGuard<ValueRestorationGuard_Impl<T>>
{
public:
- FlagRestorationGuard( bool& i_flagRef, bool i_temporaryValue )
- : ScopeGuard(FlagRestorationGuard_Impl(i_flagRef))
+ template <typename T1>
+ ValueRestorationGuard(T& i_valRef, T1&& i_temporaryValue)
+ : ScopeGuard<ValueRestorationGuard_Impl<T>>(ValueRestorationGuard_Impl(i_valRef))
{
- i_flagRef = i_temporaryValue;
+ i_valRef = std::forward<T1>(i_temporaryValue);
}
};
+ typedef ValueRestorationGuard<bool> FlagRestorationGuard;
//= FlagGuard
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index 62a35f1ab3b5..55b0a4169ac2 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -1129,10 +1129,7 @@ void DocxSdrExport::writeOnlyTextOfFrame(ww8::Frame const* pParentFrame)
m_pImpl->setBodyPrAttrList(sax_fastparser::FastSerializerHelper::createAttrList());
::comphelper::FlagRestorationGuard const g(m_pImpl->m_bFlyFrameGraphic, true);
- auto const nTextTyp(m_pImpl->getExport().m_nTextTyp);
- m_pImpl->getExport().m_nTextTyp = TXT_TXTBOX;
- ::comphelper::ScopeGuard const sg(
- [this, nTextTyp]() { m_pImpl->getExport().m_nTextTyp = nTextTyp; });
+ comphelper::ValueRestorationGuard vg(m_pImpl->getExport().m_nTextTyp, TXT_TXTBOX);
m_pImpl->getExport().WriteText();
}
@@ -1388,10 +1385,7 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho
{
::comphelper::FlagRestorationGuard const g(m_pImpl->m_bFlyFrameGraphic, true);
- auto const nTextTyp(m_pImpl->getExport().m_nTextTyp);
- m_pImpl->getExport().m_nTextTyp = TXT_TXTBOX;
- ::comphelper::ScopeGuard const sg(
- [this, nTextTyp]() { m_pImpl->getExport().m_nTextTyp = nTextTyp; });
+ comphelper::ValueRestorationGuard vg(m_pImpl->getExport().m_nTextTyp, TXT_TXTBOX);
m_pImpl->getExport().WriteText();
if (m_pImpl->getParagraphSdtOpen())
{
@@ -1542,10 +1536,7 @@ void DocxSdrExport::writeVMLTextFrame(ww8::Frame const* pParentFrame, bool bText
pFS->startElementNS(XML_w, XML_txbxContent);
{
::comphelper::FlagRestorationGuard const g(m_pImpl->m_bFlyFrameGraphic, true);
- auto const nTextTyp(m_pImpl->getExport().m_nTextTyp);
- m_pImpl->getExport().m_nTextTyp = TXT_TXTBOX;
- ::comphelper::ScopeGuard const sg(
- [this, nTextTyp]() { m_pImpl->getExport().m_nTextTyp = nTextTyp; });
+ comphelper::ValueRestorationGuard vg(m_pImpl->getExport().m_nTextTyp, TXT_TXTBOX);
m_pImpl->getExport().WriteText();
if (m_pImpl->getParagraphSdtOpen())
{
More information about the Libreoffice-commits
mailing list