From 9ad38383fe840e2eae99fd459205ba4a346e7ba8 Mon Sep 17 00:00:00 2001 From: Rick Winter Date: Tue, 2 Mar 2021 13:42:25 -0800 Subject: [PATCH] Make ModifiedConditions Nullable. (#1761) * Make ModifiedConditions Nullable. Add access helpers for Nullable. --- .../inc/azure/core/modified_conditions.hpp | 5 +- .../azure-core/inc/azure/core/nullable.hpp | 64 ++++++++++++++++++- .../test/ut/modified_conditions.cpp | 4 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/sdk/core/azure-core/inc/azure/core/modified_conditions.hpp b/sdk/core/azure-core/inc/azure/core/modified_conditions.hpp index b4698a8b0..ea7268208 100644 --- a/sdk/core/azure-core/inc/azure/core/modified_conditions.hpp +++ b/sdk/core/azure-core/inc/azure/core/modified_conditions.hpp @@ -9,6 +9,7 @@ #pragma once #include "azure/core/datetime.hpp" +#include "azure/core/nullable.hpp" #include @@ -23,11 +24,11 @@ namespace Azure { namespace Core { * @brief Optionally limit requests to resources that have only been modified since this point * in time. */ - Azure::Core::DateTime IfModifiedSince; + Azure::Core::Nullable IfModifiedSince; /** * @brief Optionally limit requests to resources that have remained unmodified. */ - Azure::Core::DateTime IfUnmodifiedSince; + Azure::Core::Nullable IfUnmodifiedSince; }; }} // namespace Azure::Core diff --git a/sdk/core/azure-core/inc/azure/core/nullable.hpp b/sdk/core/azure-core/inc/azure/core/nullable.hpp index 665c50ba4..3e140cef8 100644 --- a/sdk/core/azure-core/inc/azure/core/nullable.hpp +++ b/sdk/core/azure-core/inc/azure/core/nullable.hpp @@ -261,10 +261,72 @@ namespace Azure { namespace Core { return std::move(m_value); } + // observers + /** * @brief `operator bool` on the condition of #Azure::Core::Nullable::HasValue. */ - explicit operator bool() const noexcept { return HasValue(); } + constexpr explicit operator bool() const noexcept { return HasValue(); } + + /** + * @brief Accesses the contained value. + * @return Returns a pointer to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr const T* operator->() const { return std::addressof(m_value); } + + /** + * @brief Accesses the contained value. + * @return Returns a pointer to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr T* operator->() { return std::addressof(m_value); } + + /** + * @brief Accesses the contained value. + * @return Returns a reference to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr const T& operator*() const& { return m_value; } + + /** + * @brief Accesses the contained value. + * @return Returns a reference to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr T& operator*() & { return m_value; } + + /** + * @brief Accesses the contained value. + * @return Returns a reference to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr T&& operator*() && { return std::move(m_value); } + + /** + * @brief Accesses the contained value. + * @return Returns a reference to the contained value. + * @warning The behavior is undefined if `*this` does not contain a value. + * @note This operator does not check whether the #Nullable contains a value! + You can do so manually by using #HasValue() or simply operator #bool(). + Alternatively, if checked access is needed, #GetValue() or #ValueOr() may be used. + */ + constexpr const T&& operator*() const&& { return std::move(m_value); } /** * @brief Get the contained value, returns \p other if value is absent. diff --git a/sdk/core/azure-core/test/ut/modified_conditions.cpp b/sdk/core/azure-core/test/ut/modified_conditions.cpp index e6d5a1750..81dc2c8a0 100644 --- a/sdk/core/azure-core/test/ut/modified_conditions.cpp +++ b/sdk/core/azure-core/test/ut/modified_conditions.cpp @@ -18,9 +18,9 @@ TEST(ModifiedConditions, Basic) = DateTime::Parse("2013-11-19T14:30:59.1234567Z", DateTime::DateFormat::Rfc3339); EXPECT_EQ( - conditions.IfModifiedSince.ToString(DateTime::DateFormat::Rfc3339), + conditions.IfModifiedSince->ToString(DateTime::DateFormat::Rfc3339), "2013-11-19T14:30:59.1234567Z"); EXPECT_EQ( - conditions.IfUnmodifiedSince.ToString(DateTime::DateFormat::Rfc3339), + conditions.IfUnmodifiedSince->ToString(DateTime::DateFormat::Rfc3339), "2013-11-19T14:30:59.1234567Z"); }