include/comphelper/SetFlagContextHelper.hxx |   58 ++++++++++++----------------
 1 file changed, 26 insertions(+), 32 deletions(-)

New commits:
commit 940f189cdfa6022d92204978e14739b86a636c5c
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Mar 29 13:32:33 2025 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Mar 29 15:06:58 2025 +0100

    Simplify SetFlagContextHelper.hxx
    
    Limit the implementation class visibility.
    Allow to define the value of the flag.
    
    Change-Id: I9ce42569895c6df044074bcc2ab77e2cd5b901ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183481
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/comphelper/SetFlagContextHelper.hxx 
b/include/comphelper/SetFlagContextHelper.hxx
index 0df596a9ee5f..92f623659c50 100644
--- a/include/comphelper/SetFlagContextHelper.hxx
+++ b/include/comphelper/SetFlagContextHelper.hxx
@@ -7,47 +7,43 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
-#define INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
+#pragma once
+
+#include <sal/config.h>
 
-#include <com/sun/star/uno/XCurrentContext.hpp>
 #include <cppuhelper/implbase.hxx>
 #include <uno/current_context.hxx>
-#include <utility>
 
 namespace comphelper
 {
-// Used to flag some named value to be true for all code running in this 
context
-class SetFlagContext final : public 
cppu::WeakImplHelper<css::uno::XCurrentContext>
+// Returns a new context layer that assigns the given boolean value to the name
+inline css::uno::Reference<css::uno::XCurrentContext> NewFlagContext(const 
OUString& sName,
+                                                                     bool 
bValue = true)
 {
-public:
-    explicit SetFlagContext(OUString sName, 
css::uno::Reference<css::uno::XCurrentContext> xContext)
-        : m_sName(std::move(sName))
-        , mxNextContext(std::move(xContext))
+    class SetFlagContext : public 
cppu::WeakImplHelper<css::uno::XCurrentContext>
     {
-    }
-    SetFlagContext(const SetFlagContext&) = delete;
-    SetFlagContext& operator=(const SetFlagContext&) = delete;
+    public:
+        SetFlagContext(const OUString& sName, bool bValue)
+            : msName(sName)
+            , mbValue(bValue)
+        {
+        }
 
-    virtual css::uno::Any SAL_CALL getValueByName(OUString const& Name) 
override
-    {
-        if (Name == m_sName)
-            return css::uno::Any(true);
-        else if (mxNextContext.is())
-            return mxNextContext->getValueByName(Name);
-        else
+        virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) 
override
+        {
+            if (Name == msName)
+                return css::uno::Any(mbValue);
+            if (mxNext)
+                return mxNext->getValueByName(Name);
             return css::uno::Any();
-    }
-
-private:
-    OUString m_sName;
-    css::uno::Reference<css::uno::XCurrentContext> mxNextContext;
-};
+        }
 
-// Returns a new context that reports the named value to be true
-inline css::uno::Reference<css::uno::XCurrentContext> NewFlagContext(const 
OUString& sName)
-{
-    return new SetFlagContext(sName, css::uno::getCurrentContext());
+    private:
+        OUString msName;
+        bool mbValue;
+        css::uno::Reference<css::uno::XCurrentContext> mxNext = 
css::uno::getCurrentContext();
+    };
+    return new SetFlagContext(sName, bValue);
 }
 
 // A specialization for preventing "Java must be enabled" interaction
@@ -66,6 +62,4 @@ inline bool IsContextFlagActive(const OUString& sName)
 
 } // namespace comphelper
 
-#endif // INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to