Skip to content

feat: replaced infra::Optional's implementation with std::optional #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/mdns/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(int argc, const char* argv[], const char* env[])
static infra::BoundedString::WithStorage<32> name{ "discovery" };
static services::DnsHostnameInPartsHelper<1> text{ services::DnsHostnameInParts(name) };
static services::IPv4Address ip{ 127, 0, 0, 1 };
static services::BonjourServer server(network.DatagramFactory(), network.Multicast(), name, "", "", infra::MakeOptional(ip), infra::none, 80, text);
static services::BonjourServer server(network.DatagramFactory(), network.Multicast(), name, "", "", std::make_optional(ip), infra::none, 80, text);

network.Run();

Expand Down
3 changes: 1 addition & 2 deletions examples/websocket_client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "hal/generic/SynchronousRandomDataGeneratorGeneric.hpp"
#include "hal/generic/TimerServiceGeneric.hpp"
#include "services/network/ConnectionFactoryWithNameResolver.hpp"
#include "services/network/HttpClientBasic.hpp"
#include "services/network/HttpClientImpl.hpp"
#include "services/network/WebSocketClientConnectionObserver.hpp"
#include "services/network_instantiations/NetworkAdapter.hpp"
Expand Down Expand Up @@ -163,7 +162,7 @@ int main(int argc, const char* argv[], const char* env[])
static infra::Creator<services::Stoppable, services::HttpClientWebSocketInitiation, void(services::WebSocketClientObserverFactory & clientObserverFactory, services::HttpClientWebSocketInitiationResult & result, hal::SynchronousRandomDataGenerator & randomDataGenerator)> httpClientInitiationCreator{ [](infra::Optional<services::HttpClientWebSocketInitiation>& value, services::WebSocketClientObserverFactory& clientObserverFactory,
services::HttpClientWebSocketInitiationResult& result, hal::SynchronousRandomDataGenerator& randomDataGenerator)
{
value.Emplace(clientObserverFactory, clientConnector, result, randomDataGenerator);
value.emplace(clientObserverFactory, clientConnector, result, randomDataGenerator);
} };
static services::WebSocketClientFactorySingleConnection webSocketFactory{ randomDataGenerator, { httpClientInitiationCreator } };

Expand Down
22 changes: 11 additions & 11 deletions infra/event/test/TestQueueForOneReaderOneIrqWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QueueForOneReaderOneIrqWriterTest

TEST_F(QueueForOneReaderOneIrqWriterTest, add_element)
{
queue.Emplace(buffer, [this]()
queue.emplace(buffer, [this]()
{
queue->Get();
callback.callback();
Expand All @@ -33,7 +33,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, add_element)

TEST_F(QueueForOneReaderOneIrqWriterTest, add_range)
{
queue.Emplace(buffer, [this]()
queue.emplace(buffer, [this]()
{
while (!queue->Empty())
queue->Get();
Expand All @@ -48,7 +48,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, add_range)

TEST_F(QueueForOneReaderOneIrqWriterTest, consume_1_before_get)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

queue->AddFromInterrupt(0);
queue->AddFromInterrupt(1);
Expand All @@ -59,7 +59,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, consume_1_before_get)

TEST_F(QueueForOneReaderOneIrqWriterTest, get_without_consume_using_array_operator)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

std::array<uint8_t, 4> data = { { 0, 1, 2, 3 } };
queue->AddFromInterrupt(data);
Expand All @@ -76,7 +76,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, get_without_consume_using_array_operat

TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

EXPECT_TRUE(queue->ContiguousRange().empty());

Expand All @@ -89,7 +89,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange)

TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_while_queue_is_wrapped)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

std::array<uint8_t, 3> data = { { 0, 1, 2 } };
queue->AddFromInterrupt(data);
Expand All @@ -108,7 +108,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_while_queue_is_wra

TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_with_offset)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

std::array<uint8_t, 3> data = { { 0, 1, 2 } };
queue->AddFromInterrupt(data);
Expand All @@ -123,7 +123,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_with_offset)

TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_with_offset_while_queue_is_wrapped)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});

std::array<uint8_t, 3> data = { { 0, 1, 2 } };
queue->AddFromInterrupt(data);
Expand All @@ -142,7 +142,7 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, get_ContiguousRange_with_offset_while_

TEST_F(QueueForOneReaderOneIrqWriterTest, Size)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});
std::array<uint8_t, 4> full = { { 3, 1, 2, 4 } };
std::array<uint8_t, 1> data1 = { { 7 } };
std::array<uint8_t, 2> data2 = { { 5, 1 } };
Expand All @@ -169,13 +169,13 @@ TEST_F(QueueForOneReaderOneIrqWriterTest, Size)

TEST_F(QueueForOneReaderOneIrqWriterTest, EmptySize)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});
EXPECT_EQ(sizeof(buffer) - 1, queue->EmptySize());
}

TEST_F(QueueForOneReaderOneIrqWriterTest, StreamReader)
{
queue.Emplace(buffer, [this]() {});
queue.emplace(buffer, [this]() {});
std::array<uint8_t, 4> full = { { 1, 2, 3, 4 } };
queue->AddFromInterrupt(full);

Expand Down
9 changes: 4 additions & 5 deletions infra/stream/InputStream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "infra/stream/InputStream.hpp"
#include "infra/util/Base64.hpp"
#include <cassert>

namespace infra
{
Expand Down Expand Up @@ -288,7 +287,7 @@ namespace infra
SkipSpaces();

v = 0;
for (std::size_t i = 0; (i != width.ValueOr(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
for (std::size_t i = 0; (i != width.value_or(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
{
char c = static_cast<char>(Reader().Peek(ErrorPolicy()));

Expand All @@ -309,7 +308,7 @@ namespace infra
SkipSpaces();

v = 0;
for (std::size_t i = 0; (i != width.ValueOr(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
for (std::size_t i = 0; (i != width.value_or(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
{
char c = static_cast<char>(Reader().Peek(ErrorPolicy()));

Expand Down Expand Up @@ -365,7 +364,7 @@ namespace infra

v = 0;

for (std::size_t i = 0; (i != width.ValueOr(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
for (std::size_t i = 0; (i != width.value_or(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
{
char c = static_cast<char>(Reader().Peek(ErrorPolicy()));

Expand All @@ -391,7 +390,7 @@ namespace infra

v = 0;

for (std::size_t i = 0; (i != width.ValueOr(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
for (std::size_t i = 0; (i != width.value_or(std::numeric_limits<std::size_t>::max()) && !Reader().Empty()) || i == 0; ++i)
{
char c = static_cast<char>(Reader().Peek(ErrorPolicy()));

Expand Down
1 change: 1 addition & 0 deletions infra/stream/OutputStream.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "infra/stream/OutputStream.hpp"
#include "infra/util/Base64.hpp"
#include <cmath>
#include <limits>

Expand Down
2 changes: 0 additions & 2 deletions infra/stream/OutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

#include "infra/stream/StreamErrorPolicy.hpp"
#include "infra/stream/StreamManipulators.hpp"
#include "infra/util/Base64.hpp"
#include "infra/util/BoundedString.hpp"
#include "infra/util/ByteRange.hpp"
#include "infra/util/Function.hpp"
#include "infra/util/IntegerNormalization.hpp"
#include "infra/util/Optional.hpp"
#include <type_traits>

namespace infra
Expand Down
2 changes: 0 additions & 2 deletions infra/stream/StringOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define INFRA_STRING_OUTPUT_STREAM_HPP

#include "infra/stream/OutputStream.hpp"
#include "infra/stream/StreamManipulators.hpp"
#include "infra/util/BoundedString.hpp"
#include <cstdint>

namespace infra
{
Expand Down
22 changes: 11 additions & 11 deletions infra/syntax/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ namespace infra
for (auto& keyValue : *this)
{
if (keyValue.key == key && keyValue.value.Is<T>())
return infra::MakeOptional(keyValue.value.Get<T>());
return std::make_optional(keyValue.value.Get<T>());
}

return infra::none;
Expand Down Expand Up @@ -881,37 +881,37 @@ namespace infra
infra::Optional<JsonValue> JsonIterator::ConvertValue(JsonToken::Token token)
{
if (token.Is<JsonToken::String>())
return infra::MakeOptional(JsonValue(token.Get<JsonToken::String>().Value()));
return std::make_optional(JsonValue(token.Get<JsonToken::String>().Value()));
else if (token.Is<JsonBiggerInt>())
return ReadInteger(token);
else if (token.Is<JsonFloat>())
return infra::MakeOptional(JsonValue(token.Get<JsonFloat>()));
return std::make_optional(JsonValue(token.Get<JsonFloat>()));
else if (token.Is<JsonToken::Boolean>())
return infra::MakeOptional(JsonValue(token.Get<JsonToken::Boolean>().Value()));
return std::make_optional(JsonValue(token.Get<JsonToken::Boolean>().Value()));
else if (token.Is<JsonToken::LeftBrace>())
return ReadObjectValue(token);
else if (token.Is<JsonToken::LeftBracket>())
return ReadArrayValue(token);
else if (token.Is<JsonToken::Null>())
return infra::MakeOptional(JsonValue(JsonObject()));
return std::make_optional(JsonValue(JsonObject()));
else
return infra::none;
}

infra::Optional<JsonValue> JsonIterator::ReadInteger(const JsonToken::Token& token)
{
if ((!token.Get<JsonBiggerInt>().Negative() && token.Get<JsonBiggerInt>().Value() <= std::numeric_limits<int32_t>::max()) || (token.Get<JsonBiggerInt>().Negative() && token.Get<JsonBiggerInt>().Value() <= static_cast<uint64_t>(-static_cast<int64_t>(std::numeric_limits<int32_t>::min()))))
return infra::MakeOptional(JsonValue(static_cast<int32_t>(token.Get<JsonBiggerInt>().Value() * (token.Get<JsonBiggerInt>().Negative() ? -1 : 1))));
return std::make_optional(JsonValue(static_cast<int32_t>(token.Get<JsonBiggerInt>().Value() * (token.Get<JsonBiggerInt>().Negative() ? -1 : 1))));
else
return infra::MakeOptional(JsonValue(token.Get<JsonBiggerInt>()));
return std::make_optional(JsonValue(token.Get<JsonBiggerInt>()));
}

infra::Optional<JsonValue> JsonIterator::ReadObjectValue(const JsonToken::Token& token)
{
infra::Optional<JsonToken::RightBrace> objectEnd = SearchObjectEnd();

if (objectEnd)
return infra::MakeOptional(JsonValue(JsonObject(objectString.substr(token.Get<JsonToken::LeftBrace>().Index(), objectEnd->Index() + 1 - token.Get<JsonToken::LeftBrace>().Index()))));
return std::make_optional(JsonValue(JsonObject(objectString.substr(token.Get<JsonToken::LeftBrace>().Index(), objectEnd->Index() + 1 - token.Get<JsonToken::LeftBrace>().Index()))));
else
return infra::none;
}
Expand All @@ -921,7 +921,7 @@ namespace infra
infra::Optional<JsonToken::RightBracket> arrayEnd = SearchArrayEnd();

if (arrayEnd)
return infra::MakeOptional(JsonValue(JsonArray(objectString.substr(token.Get<JsonToken::LeftBracket>().Index(), arrayEnd->Index() + 1 - token.Get<JsonToken::LeftBracket>().Index()))));
return std::make_optional(JsonValue(JsonArray(objectString.substr(token.Get<JsonToken::LeftBracket>().Index(), arrayEnd->Index() + 1 - token.Get<JsonToken::LeftBracket>().Index()))));
else
return infra::none;
}
Expand All @@ -941,7 +941,7 @@ namespace infra
}

if (token.Is<JsonToken::RightBrace>())
return infra::MakeOptional(token.Get<JsonToken::RightBrace>());
return std::make_optional(token.Get<JsonToken::RightBrace>());
return infra::none;
}

Expand All @@ -960,7 +960,7 @@ namespace infra
}

if (token.Is<JsonToken::RightBracket>())
return infra::MakeOptional(token.Get<JsonToken::RightBracket>());
return std::make_optional(token.Get<JsonToken::RightBracket>());
else
return infra::none;
}
Expand Down
6 changes: 3 additions & 3 deletions infra/syntax/JsonObjectNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace infra
infra::Optional<std::string> JsonOptionalObjectNavigator::operator/(JsonStringNavigatorToken token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand All @@ -142,15 +142,15 @@ namespace infra
infra::Optional<int32_t> JsonOptionalObjectNavigator::operator/(JsonIntegerNavigatorToken token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}

infra::Optional<bool> JsonOptionalObjectNavigator::operator/(JsonBoolNavigatorToken token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand Down
16 changes: 8 additions & 8 deletions infra/syntax/JsonObjectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace infra
if (subObject == infra::none)
return {};

return infra::MakeOptional(token.transformation(*subObject));
return std::make_optional(token.transformation(*subObject));
}

template<class Result>
Expand All @@ -218,7 +218,7 @@ namespace infra
if (subArray == infra::none)
return {};

return infra::MakeOptional(token.transformation(*subArray));
return std::make_optional(token.transformation(*subArray));
}

template<class Result>
Expand All @@ -238,14 +238,14 @@ namespace infra
if (member == infra::none)
return {};

return infra::MakeOptional(token.transformation(member->ToStdString()));
return std::make_optional(token.transformation(member->ToStdString()));
}

template<class Result>
infra::Optional<Result> JsonOptionalObjectNavigator::operator/(JsonTransformObjectNavigatorToken<Result> token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand All @@ -263,7 +263,7 @@ namespace infra
infra::Optional<Result> JsonOptionalObjectNavigator::operator/(JsonTransformArrayNavigatorToken<Result> token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand All @@ -272,7 +272,7 @@ namespace infra
infra::Optional<Result> JsonOptionalObjectNavigator::operator/(JsonTransformOptionalArrayNavigatorToken<Result> token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand All @@ -281,7 +281,7 @@ namespace infra
infra::Optional<Result> JsonOptionalObjectNavigator::operator/(JsonTransformStringNavigatorToken<Result> token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand All @@ -290,7 +290,7 @@ namespace infra
infra::Optional<Result> JsonOptionalObjectNavigator::operator/(JsonTransformOptionalStringNavigatorToken<Result> token) const
{
if (navigator != infra::none)
return infra::MakeOptional(*navigator / token);
return std::make_optional(*navigator / token);
else
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion infra/syntax/XmlFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace infra

XmlTagFormatter& XmlTagFormatter::operator=(XmlTagFormatter&& other) noexcept
{
stream = other.stream;
stream.emplace(std::move(other.stream.value()));
other.stream = infra::none;

return *this;
Expand Down
Loading
Loading