Kaydet (Commit) b612cf0e authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Introduce o3tl::underlyingEnumValue

Change-Id: I6554eb86326159b0da707539f45c411f61c0f3de
Reviewed-on: https://gerrit.libreoffice.org/68761
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst efbd217a
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_O3TL_UNDERLYINGENUMVALUE_HXX
#define INCLUDED_O3TL_UNDERLYINGENUMVALUE_HXX
#include <sal/config.h>
#include <type_traits>
namespace o3tl
{
// For a value e of an enumeration type T, return the corresponding value of T's underlying type:
template <typename T> constexpr std::underlying_type_t<T> underlyingEnumValue(T e)
{
return static_cast<std::underlying_type_t<T>>(e);
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -32,6 +32,7 @@
#include <formula/grammar.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <o3tl/underlyingenumvalue.hxx>
namespace com { namespace sun { namespace star {
namespace sheet {
......@@ -178,11 +179,11 @@ namespace o3tl
}
inline void applyStartToEndFlags(ScRefFlags &target,const ScRefFlags source)
{
target |= ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(source) << 4);
target |= ScRefFlags(o3tl::underlyingEnumValue(source) << 4);
}
inline void applyStartToEndFlags(ScRefFlags &target)
{
target |= ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(target) << 4);
target |= ScRefFlags(o3tl::underlyingEnumValue(target) << 4);
}
// ScAddress
......
......@@ -28,7 +28,7 @@
#include <externalrefmgr.hxx>
#include <osl/diagnose.h>
#include <o3tl/underlyingenumvalue.hxx>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/sheet/ExternalLinkInfo.hpp>
#include <com/sun/star/sheet/ExternalLinkType.hpp>
......@@ -2219,7 +2219,7 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
lcl_RowAbsFlagDiffer( nFlags ))
{
// move flags of end reference to start reference, mask with BITS to exclude FORCE_DOC flag
nFlags = ScRefFlags::VALID | (ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(nFlags) >> 4) & ScRefFlags::BITS);
nFlags = ScRefFlags::VALID | (ScRefFlags(o3tl::underlyingEnumValue(nFlags) >> 4) & ScRefFlags::BITS);
if ( bOneTab )
pDoc = nullptr;
else
......
......@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <o3tl/underlyingenumvalue.hxx>
#include <reffind.hxx>
#include <global.hxx>
#include <compiler.hxx>
......@@ -219,7 +223,7 @@ static ScRefFlags lcl_NextFlags( ScRefFlags nOld )
{
const ScRefFlags Mask_ABS = ScRefFlags::COL_ABS | ScRefFlags::ROW_ABS | ScRefFlags::TAB_ABS;
ScRefFlags nNew = nOld & Mask_ABS;
nNew = ScRefFlags( static_cast<std::underlying_type<ScRefFlags>::type>(nNew) - 1 ) & Mask_ABS; // weiterzaehlen
nNew = ScRefFlags( o3tl::underlyingEnumValue(nNew) - 1 ) & Mask_ABS; // weiterzaehlen
if (!(nOld & ScRefFlags::TAB_3D))
nNew &= ~ScRefFlags::TAB_ABS; // not 3D -> never absolute!
......
......@@ -520,8 +520,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
}
......@@ -561,11 +560,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLPartial)
// We expect NOTVALIDATED_PARTIAL_OK in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both.
// But reject NOTVALIDATED, hiding incompleteness is not OK.
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(nActual == SignatureState::NOTVALIDATED_PARTIAL_OK
|| nActual == SignatureState::PARTIAL_OK));
CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::NOTVALIDATED_PARTIAL_OK
|| nActual == SignatureState::PARTIAL_OK));
}
/// Test a typical broken OOXML signature where one stream is corrupted.
......@@ -594,8 +591,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
}
......@@ -635,11 +631,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Calc)
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell);
SignatureState nActual = pObjectShell->GetScriptingSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
......@@ -674,11 +668,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Doc)
CPPUNIT_ASSERT(pObjectShell);
SignatureState nActual = pObjectShell->GetScriptingSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
......@@ -778,8 +770,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
}
......@@ -840,10 +831,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGoodGPG)
// Our local gpg config fully trusts the signing cert, so in
// contrast to the X509 test we can fail on NOTVALIDATED here
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_EQUAL_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
SignatureState::OK, nActual);
CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
SignatureState::OK, nActual);
}
/// Test a typical ODF where all streams are GPG-signed, but we don't trust the signature.
......@@ -858,10 +847,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFUntrustedGoodGPG)
// contrast to the X509 test we can fail everything but
// NOTVALIDATED here
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_EQUAL_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
SignatureState::NOTVALIDATED, nActual);
CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
SignatureState::NOTVALIDATED, nActual);
}
/// Test a typical broken ODF signature where one stream is corrupted.
......
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