sw/source/core/inc/unoport.hxx     |   10 +++++-----
 sw/source/core/unocore/unoport.cxx |   37 ++++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 22 deletions(-)

New commits:
commit d57ad60d8ed5279a3366386553c5cefb7ae8b5bf
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 8 21:04:48 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 12 22:12:45 2022 +0200

    unique_ptr->optional in SwXTextPortion
    
    Change-Id: I6b55ed9fb907473ff2e44bfa0bd5ccced750ca60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138158
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index d0d9b5b64176..5bdade8eda6e 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -111,11 +111,11 @@ private:
         m_xMeta;
     css::uno::Reference<css::text::XTextContent> m_xLineBreak;
     css::uno::Reference<css::text::XTextContent> m_xContentControl;
-    std::unique_ptr< css::uno::Any > m_pRubyText;
-    std::unique_ptr< css::uno::Any > m_pRubyStyle;
-    std::unique_ptr< css::uno::Any > m_pRubyAdjust;
-    std::unique_ptr< css::uno::Any > m_pRubyIsAbove;
-    std::unique_ptr< css::uno::Any > m_pRubyPosition;
+    std::optional< css::uno::Any > m_oRubyText;
+    std::optional< css::uno::Any > m_oRubyStyle;
+    std::optional< css::uno::Any > m_oRubyAdjust;
+    std::optional< css::uno::Any > m_oRubyIsAbove;
+    std::optional< css::uno::Any > m_oRubyPosition;
     sw::UnoCursorPointer m_pUnoCursor;
 
     SwFrameFormat*                  m_pFrameFormat;
diff --git a/sw/source/core/unocore/unoport.cxx 
b/sw/source/core/unocore/unoport.cxx
index a10da8a9c35f..1a4c065df2cd 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -100,25 +100,28 @@ SwXTextPortion::SwXTextPortion(
     : m_pPropSet(aSwMapProvider.GetPropertySet(
                     PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
     , m_xParentText(std::move(xParent))
-    , m_pRubyText   ( bIsEnd ? nullptr : new uno::Any )
-    , m_pRubyStyle  ( bIsEnd ? nullptr : new uno::Any )
-    , m_pRubyAdjust ( bIsEnd ? nullptr : new uno::Any )
-    , m_pRubyIsAbove( bIsEnd ? nullptr : new uno::Any )
-    , m_pRubyPosition( bIsEnd ? nullptr : new uno::Any )
     , m_pFrameFormat(nullptr)
     , m_ePortionType( bIsEnd ? PORTION_RUBY_END : PORTION_RUBY_START )
     , m_bIsCollapsed(false)
 {
+    if (!bIsEnd)
+    {
+        m_oRubyText.emplace();
+        m_oRubyStyle.emplace();
+        m_oRubyAdjust.emplace();
+        m_oRubyIsAbove.emplace();
+        m_oRubyPosition.emplace();
+    }
     init( pPortionCursor);
 
     if (!bIsEnd)
     {
         const SfxPoolItem& rItem = rAttr.GetAttr();
-        rItem.QueryValue(*m_pRubyText);
-        rItem.QueryValue(*m_pRubyStyle, MID_RUBY_CHARSTYLE);
-        rItem.QueryValue(*m_pRubyAdjust, MID_RUBY_ADJUST);
-        rItem.QueryValue(*m_pRubyIsAbove, MID_RUBY_ABOVE);
-        rItem.QueryValue(*m_pRubyPosition, MID_RUBY_POSITION);
+        rItem.QueryValue(*m_oRubyText);
+        rItem.QueryValue(*m_oRubyStyle, MID_RUBY_CHARSTYLE);
+        rItem.QueryValue(*m_oRubyAdjust, MID_RUBY_ADJUST);
+        rItem.QueryValue(*m_oRubyIsAbove, MID_RUBY_ABOVE);
+        rItem.QueryValue(*m_oRubyPosition, MID_RUBY_POSITION);
     }
 }
 
@@ -357,17 +360,17 @@ void SwXTextPortion::GetPropertyValue(
         break;
         case RES_TXTATR_CJK_RUBY:
         {
-            const uno::Any* pToSet = nullptr;
+            const std::optional<uno::Any>* pToSet = nullptr;
             switch(rEntry.nMemberId)
             {
-                case MID_RUBY_TEXT :    pToSet = m_pRubyText.get();   break;
-                case MID_RUBY_ADJUST :  pToSet = m_pRubyAdjust.get(); break;
-                case MID_RUBY_CHARSTYLE:pToSet = m_pRubyStyle.get();  break;
-                case MID_RUBY_ABOVE :   pToSet = m_pRubyIsAbove.get();break;
-                case MID_RUBY_POSITION: pToSet = m_pRubyPosition.get();break;
+                case MID_RUBY_TEXT :    pToSet = &m_oRubyText;   break;
+                case MID_RUBY_ADJUST :  pToSet = &m_oRubyAdjust; break;
+                case MID_RUBY_CHARSTYLE:pToSet = &m_oRubyStyle;  break;
+                case MID_RUBY_ABOVE :   pToSet = &m_oRubyIsAbove;break;
+                case MID_RUBY_POSITION: pToSet = &m_oRubyPosition;break;
             }
             if(pToSet)
-                rVal = *pToSet;
+                rVal = **pToSet;
         }
         break;
         default:

Reply via email to