Skip to content

Commit

Permalink
feat: replaced infra::Optional with std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
daantimmer committed May 6, 2024
1 parent 20c3726 commit d0ed1ac
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion preview/interfaces/BufferedDisplaySsd1306.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace services
hal::I2cAddress address;
bool initializing = true;

infra::Optional<infra::Bitmap> bitmap;
std::optional<infra::Bitmap> bitmap;

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32f407)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32f746)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (7-2018-q2, RelWithDebInfo, stm32f767)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (8-2019-q3, RelWithDebInfo, stm32f767)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32f767)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (9-2020-q2, RelWithDebInfo, stm32f767)

‘optional’ in namespace ‘std’ does not name a template type

Check failure on line 34 in preview/interfaces/BufferedDisplaySsd1306.hpp

View workflow job for this annotation

GitHub Actions / CodeQL

‘optional’ in namespace ‘std’ does not name a template type
infra::Point position;
infra::AutoResetFunction<void()> onDone;

Expand Down
4 changes: 2 additions & 2 deletions preview/interfaces/test/TestViewPainterBufferedDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class ViewPainterBufferedDisplayTest
{
EXPECT_CALL(display, PixelFormat()).WillRepeatedly(testing::Return(infra::PixelFormat::rgb565));

viewPainter.Emplace(buffer, display, bitmapPainter);
viewPainter.emplace(buffer, display, bitmapPainter);
}

std::array<uint8_t, 8 * 16 * 2> buffer;
testing::StrictMock<hal::BufferedDisplayMock> display;
testing::StrictMock<hal::BitmapPainterMock> bitmapPainter;
testing::StrictMock<services::ViewMock> view;
infra::Optional<services::ViewPainterBufferedDisplay> viewPainter;
std::optional<services::ViewPainterBufferedDisplay> viewPainter;
};

TEST_F(ViewPainterBufferedDisplayTest, Paint)
Expand Down
18 changes: 9 additions & 9 deletions preview/touch/TouchScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace services
, touchDelta(touchDelta)
{}

void TouchScreen::Measure(const infra::Function<void(infra::Optional<infra::Point> position)>& onTouched)
void TouchScreen::Measure(const infra::Function<void(std::optional<infra::Point> position)>& onTouched)
{
assert(this->onTouched == nullptr);
this->onTouched = onTouched;

state.Emplace<StateTouchMeasurement>(*this, false);
state.emplace<StateTouchMeasurement>(*this, false);
}

TouchScreen::StateTouchMeasurement::StateTouchMeasurement(TouchScreen& touchScreen, bool finalMeasurement)
Expand Down Expand Up @@ -50,16 +50,16 @@ namespace services
{
if (xTouchResult >= yTouchResult + touchScreen.touchDelta)
{
touchScreen.onTouched(infra::none);
touchScreen.state.Emplace<StateIdle>();
touchScreen.onTouched(std::nullopt);
touchScreen.state.emplace<StateIdle>();
}
else if (finalMeasurement)
{
touchScreen.onTouched(infra::MakeOptional(infra::Point(touchScreen.xResult, touchScreen.yResult)));
touchScreen.state.Emplace<StateIdle>();
touchScreen.onTouched(std::make_optional(infra::Point(touchScreen.xResult, touchScreen.yResult)));
touchScreen.state.emplace<StateIdle>();
}
else
touchScreen.state.Emplace<StateXMeasurement>(touchScreen);
touchScreen.state.emplace<StateXMeasurement>(touchScreen);
}

TouchScreen::StateXMeasurement::StateXMeasurement(TouchScreen& touchScreen)
Expand All @@ -79,7 +79,7 @@ namespace services
void TouchScreen::StateXMeasurement::OnMeasurementDone(uint32_t pixelPosition)
{
touchScreen.xResult = pixelPosition;
touchScreen.state.Emplace<StateYMeasurement>(touchScreen);
touchScreen.state.emplace<StateYMeasurement>(touchScreen);
}

TouchScreen::StateYMeasurement::StateYMeasurement(TouchScreen& touchScreen)
Expand All @@ -99,6 +99,6 @@ namespace services
void TouchScreen::StateYMeasurement::OnMeasurementDone(uint32_t pixelPosition)
{
touchScreen.yResult = pixelPosition;
touchScreen.state.Emplace<StateTouchMeasurement>(touchScreen, true);
touchScreen.state.emplace<StateTouchMeasurement>(touchScreen, true);
}
}
4 changes: 2 additions & 2 deletions preview/touch/TouchScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace services

TouchScreen(hal::GpioPin& xPlus, hal::GpioPin& xMinus, hal::GpioPin& yPlus, hal::GpioPin& yMinus, infra::CreatorBase<AnalogToDigitalPin, void()>& xPlusAnalogPin, infra::CreatorBase<AnalogToDigitalPin, void()>& yPlusAnalogPin, uint32_t touchDelta);

void Measure(const infra::Function<void(infra::Optional<infra::Point> position)>& onTouched);
void Measure(const infra::Function<void(std::optional<infra::Point> position)>& onTouched);

private:
class State
Expand Down Expand Up @@ -103,7 +103,7 @@ namespace services
infra::CreatorBase<AnalogToDigitalPin, void()>& yPlusAnalogPin;
uint32_t touchDelta;

infra::AutoResetFunction<void(infra::Optional<infra::Point> position)> onTouched;
infra::AutoResetFunction<void(std::optional<infra::Point> position)> onTouched;
infra::PolymorphicVariant<State, StateIdle, StateTouchMeasurement, StateXMeasurement, StateYMeasurement> state;

uint32_t xResult;
Expand Down
2 changes: 1 addition & 1 deletion preview/touch/TouchScreenToTouchRecipientInteractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace services
if (!measurementBusy)
{
measurementBusy = true;
touchScreen.Measure([this](infra::Optional<infra::Point> position)
touchScreen.Measure([this](std::optional<infra::Point> position)
{
if (position)
{
Expand Down
6 changes: 3 additions & 3 deletions preview/touch/TouchSpinInteger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace services
, to(to)
, circular(circular)
, distancePerIncrement(distancePerIncrement)
, width(infra::MakeOptional(width))
, width(std::make_optional(width))
{}

void TouchSpinInteger::StartTouch(infra::Point point)
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace services

void TouchSpinInteger::StopTouch()
{
startTouch = infra::none;
startTouch = std::nullopt;
}

void TouchSpinInteger::Swipe(Direction direction)
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace services
{
valueString.clear();
infra::StringOutputStream stream(valueString);
if (width != infra::none)
if (width != std::nullopt)
stream << infra::Width(*width, '0') << value;
else
stream << value;
Expand Down
4 changes: 2 additions & 2 deletions preview/touch/TouchSpinInteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ namespace services
int32_t to;
bool circular;
uint16_t distancePerIncrement;
infra::Optional<uint8_t> width;
std::optional<uint8_t> width;

infra::Optional<infra::Point> startTouch;
std::optional<infra::Point> startTouch;
int32_t stepsReported = 0;

infra::BoundedString::WithStorage<12> valueString;
Expand Down
8 changes: 4 additions & 4 deletions preview/touch/test/TestTouchScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class TouchScreenTest
services::TouchScreen::PixelPosition yTouchResult{ 0 };

infra::Function<void()> onMeasurementDone;
infra::Function<void(infra::Optional<infra::Point> position)> onResult = [](infra::Optional<infra::Point> position) {};
infra::Function<void(std::optional<infra::Point> position)> onResult = [](std::optional<infra::Point> position) {};
};

TEST_F(TouchScreenTest, Measure_results_in_touch_measurement)
Expand All @@ -137,7 +137,7 @@ TEST_F(TouchScreenTest, Measure_results_in_touch_measurement)

TEST_F(TouchScreenTest, on_no_touch_none_is_reported)
{
infra::VerifyingFunctionMock<void(infra::Optional<infra::Point>)> expectOnResult(infra::none);
infra::VerifyingFunctionMock<void(std::optional<infra::Point>)> expectOnResult(std::nullopt);
onResult = expectOnResult;

xTouchResult = services::TouchScreen::PixelPosition{ 400 };
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST_F(TouchScreenTest, after_measurement_is_done_y_measurement_starts)

TEST_F(TouchScreenTest, after_last_measurement_result_is_reported)
{
infra::VerifyingFunctionMock<void(infra::Optional<infra::Point>)> expectOnResult(infra::MakeOptional(infra::Point()));
infra::VerifyingFunctionMock<void(std::optional<infra::Point>)> expectOnResult(std::make_optional(infra::Point()));
onResult = expectOnResult;

DoTouchMeasurement();
Expand All @@ -190,7 +190,7 @@ TEST_F(TouchScreenTest, after_last_measurement_result_is_reported)

TEST_F(TouchScreenTest, on_touch_position_is_reported)
{
infra::VerifyingFunctionMock<void(infra::Optional<infra::Point>)> expectOnResult(infra::MakeOptional(infra::Point(42, 134)));
infra::VerifyingFunctionMock<void(std::optional<infra::Point>)> expectOnResult(std::make_optional(infra::Point(42, 134)));
onResult = expectOnResult;

xResult = services::TouchScreen::PixelPosition{ 42 };
Expand Down
6 changes: 3 additions & 3 deletions preview/views/HorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ namespace services

void HorizontalLayout::Add(View& view, uint16_t proportion, VerticalAlignment alignment)
{
views.push_back(detail::LayoutViewInfo{ &view, infra::MakeOptional(alignment), proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ &view, std::make_optional(alignment), proportion, static_cast<uint8_t>(views.size()) });
view.SetParent(*this);
}

void HorizontalLayout::AddFill(View& view, uint16_t proportion)
{
views.push_back(detail::LayoutViewInfo{ &view, infra::none, proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ &view, std::nullopt, proportion, static_cast<uint8_t>(views.size()) });
view.SetParent(*this);
}

void HorizontalLayout::AddDummy(uint16_t proportion)
{
assert(proportion != 0);
views.push_back(detail::LayoutViewInfo{ nullptr, infra::none, proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ nullptr, std::nullopt, proportion, static_cast<uint8_t>(views.size()) });
}

void HorizontalLayout::BringToFront(View& view)
Expand Down
2 changes: 1 addition & 1 deletion preview/views/HorizontalLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace services
struct LayoutViewInfo
{
View* view;
infra::Optional<VerticalAlignment> alignment; // No alignment means fill up the available space in the vertical direction
std::optional<VerticalAlignment> alignment; // No alignment means fill up the available space in the vertical direction
uint16_t proportion;
uint8_t paintOrder;
infra::Region drawRegion;
Expand Down
6 changes: 3 additions & 3 deletions preview/views/VerticalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ namespace services

void VerticalLayout::Add(View& view, uint16_t proportion, HorizontalAlignment alignment)
{
views.push_back(detail::LayoutViewInfo{ &view, infra::MakeOptional(Flip(alignment)), proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ &view, std::make_optional(Flip(alignment)), proportion, static_cast<uint8_t>(views.size()) });
view.SetParent(*this);
}

void VerticalLayout::AddFill(View& view, uint16_t proportion)
{
views.push_back(detail::LayoutViewInfo{ &view, infra::none, proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ &view, std::nullopt, proportion, static_cast<uint8_t>(views.size()) });
view.SetParent(*this);
}

void VerticalLayout::AddDummy(uint16_t proportion)
{
assert(proportion != 0);
views.push_back(detail::LayoutViewInfo{ nullptr, infra::none, proportion, static_cast<uint8_t>(views.size()) });
views.push_back(detail::LayoutViewInfo{ nullptr, std::nullopt, proportion, static_cast<uint8_t>(views.size()) });
}

void VerticalLayout::BringToFront(View& view)
Expand Down
4 changes: 2 additions & 2 deletions preview/views/ViewDisableableText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ namespace services
DrawLine(TextRegion(), canvas, boundingRegion);

auto fadingRegion = FadingRegion();
if (fadingRegion != infra::none)
if (fadingRegion != std::nullopt)
DrawLine(*fadingRegion, canvas, boundingRegion);
}
}

void ViewDisableableFadingText::Enable(bool newEnabled)
{
Dirty(TextRegion() | FadingRegion().ValueOr(infra::Region()));
Dirty(TextRegion() | FadingRegion().value_or(infra::Region()));
enabled = newEnabled;
}

Expand Down
6 changes: 3 additions & 3 deletions preview/views/ViewFadingText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace services
return ViewText::TextRegion();
}

infra::Optional<infra::Region> ViewFadingText::FadingRegion() const
std::optional<infra::Region> ViewFadingText::FadingRegion() const
{
if (fadeTimer.Armed())
{
Expand All @@ -107,10 +107,10 @@ namespace services
if (fadeDirection == Direction::down || fadeDirection == Direction::right)
deltaBuffer = -deltaBuffer;

return infra::MakeOptional(ViewText::TextRegion() >> deltaBuffer);
return std::make_optional(ViewText::TextRegion() >> deltaBuffer);
}
}

return infra::none;
return std::nullopt;
}
}
2 changes: 1 addition & 1 deletion preview/views/ViewFadingText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace services
void FadeIn(infra::BoundedConstString newText, Direction from);

infra::Region TextRegion() const;
infra::Optional<infra::Region> FadingRegion() const;
std::optional<infra::Region> FadingRegion() const;

private:
infra::BoundedString& buffer1;
Expand Down
6 changes: 3 additions & 3 deletions preview/views/ViewFramedTextButtonWithPopOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace services
ViewFramedTextButton::Activate();

FramedTextButtonAttributes attributes = Attributes();
popOut.Emplace(regionOffset, FramedTextAttributes{ attributes.frameColour, attributes.activatedBackgroundColour, attributes.textColour, attributes.font }, Text());
popOut.emplace(regionOffset, FramedTextAttributes{ attributes.frameColour, attributes.activatedBackgroundColour, attributes.textColour, attributes.font }, Text());
popOut->SetParent(*this);
popOut->SetViewRegion(ViewRegion());
Dirty(popOut->ViewRegion());
Expand All @@ -21,7 +21,7 @@ namespace services
void ViewFramedTextButtonWithPopOut::Deactivate()
{
Dirty(popOut->DrawRegion());
popOut = infra::none;
popOut = std::nullopt;

ViewFramedTextButton::Deactivate();
}
Expand All @@ -46,7 +46,7 @@ namespace services
{
ViewFramedTextButton::ViewRegionChanged();

if (popOut != infra::none)
if (popOut != std::nullopt)
popOut->SetViewRegion(ViewRegion());
}
}
2 changes: 1 addition & 1 deletion preview/views/ViewFramedTextButtonWithPopOut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace services

private:
infra::RegionOffset regionOffset;
infra::Optional<ViewOffsetRegion::WithView<ViewFramedText>> popOut;
std::optional<ViewOffsetRegion::WithView<ViewFramedText>> popOut;
};
}

Expand Down

0 comments on commit d0ed1ac

Please sign in to comment.