diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-05-28 21:21:34 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-05-28 21:21:34 +0200 |
commit | 53a066b7d1a639c6d31655bfc7c6257896fb57ef (patch) | |
tree | 35089464ca996a82c09637a38405fa6eb422d2cd /sw/source/core/inc/txtfrm.hxx | |
parent | efc64511b2c833e46ab553c8d25ea489016a4bd2 (diff) |
Replace SWAP_IF_[NOT_]SWAPPED/UNDO_SWAP with RAII classes
Change-Id: I3c2c1dd8221b6b9c884f368a65696318c698bb43
Diffstat (limited to 'sw/source/core/inc/txtfrm.hxx')
-rw-r--r-- | sw/source/core/inc/txtfrm.hxx | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index 2d1418c49966..034b2bee5361 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -779,25 +779,42 @@ inline void SwTextFrm::ResetBlinkPor() const const_cast<SwTextFrm*>(this)->bBlinkPor = false; } -#define SWAP_IF_SWAPPED( pFrm )\ - bool bUndoSwap = false; \ - if ( pFrm->IsVertical() && pFrm->IsSwapped() )\ - { \ - bUndoSwap = true; \ - const_cast<SwTextFrm*>(pFrm)->SwapWidthAndHeight(); \ +class TemporarySwap { +protected: + explicit TemporarySwap(SwTextFrm * frame, bool swap): + frame_(frame), undo_(false) + { + if (frame_->IsVertical() && swap) { + undo_ = true; + frame_->SwapWidthAndHeight(); + } } -#define SWAP_IF_NOT_SWAPPED( pFrm )\ - bool bUndoSwap = false; \ - if ( pFrm->IsVertical() && ! pFrm->IsSwapped() )\ - { \ - bUndoSwap = true; \ - const_cast<SwTextFrm*>(pFrm)->SwapWidthAndHeight(); \ + ~TemporarySwap() { + if (undo_) { + frame_->SwapWidthAndHeight(); + } } -#define UNDO_SWAP( pFrm )\ - if ( bUndoSwap )\ - const_cast<SwTextFrm*>(pFrm)->SwapWidthAndHeight(); +private: + TemporarySwap(TemporarySwap &) = delete; + void operator =(TemporarySwap &) = delete; + + SwTextFrm * frame_; + bool undo_; +}; + +class SWAP_IF_SWAPPED: private TemporarySwap { +public: + explicit SWAP_IF_SWAPPED(SwTextFrm * frame): + TemporarySwap(frame, frame->IsSwapped()) {} +}; + +class SWAP_IF_NOT_SWAPPED: private TemporarySwap { +public: + explicit SWAP_IF_NOT_SWAPPED(SwTextFrm * frame): + TemporarySwap(frame, !frame->IsSwapped()) {} +}; /** * Helper class which can be used instead of the macros if a function |