Make ModifiedConditions Nullable. (#1761)

* Make ModifiedConditions Nullable.
Add access helpers for Nullable.
This commit is contained in:
Rick Winter 2021-03-02 13:42:25 -08:00 committed by GitHub
parent e04624f9a5
commit 9ad38383fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#pragma once
#include "azure/core/datetime.hpp"
#include "azure/core/nullable.hpp"
#include <string>
@ -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<Azure::Core::DateTime> IfModifiedSince;
/**
* @brief Optionally limit requests to resources that have remained unmodified.
*/
Azure::Core::DateTime IfUnmodifiedSince;
Azure::Core::Nullable<Azure::Core::DateTime> IfUnmodifiedSince;
};
}} // namespace Azure::Core

View File

@ -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.

View File

@ -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");
}