AOptional#
Utility wrapper implementing the stack-allocated (fast) optional idiom.
| Header: | #include <AUI/Common/AOptional.h> |
| CMake: | aui_link(my_target PUBLIC aui::core) |
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
constexpr auto REGEX_DATE = ctre::match<"([0-9]+)\\.([0-9]+)\\.([0-9]{4})">;
struct DateTextFieldState {
AProperty<AOptional<system_clock::time_point>> parsed;
ASpinlockMutex userChangesText;
};
auto formatDate(system_clock::time_point date) { return "{0:%d}.{0:%m}.{0:%G}"_format(date); }
Public Methods#
constructor#
Constructs an optional containing the given value (explicit conversion).
- Arguments
rhsValue to store
Copy constructor.
Move constructor.
Converting copy constructor.
Converting move constructor.
bool#
Boolean conversion operator.
- Returns
- true if contains value, false otherwise
Examples:
examples/app/minesweeper/src/CellView.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
mCellValueCopy = mCell;
}
AView::render(context);
if (bool(mCell & FieldCell::OPEN)) {
int count = field_cell::getBombCountAround(mCell);
if (count) {
AFontStyle fs;
fs.size = getHeight() * 6 / 7;
fs.align = ATextAlign::CENTER;
examples/7guis/cells/src/Tokens.cpp
7GUIs Cells - Spreadsheet processor (Excel).
continue;
}
if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
t->reverseByte();
out << token::Identifier { t->readStringWhile([](char c) -> bool { return std::isalnum(c); }) };
continue;
}
throw AException("UNEXPECTED {}"_format(c));
}
}
emplace#
Constructs the contained value in-place.
- Arguments
argsArguments to forward to the constructor- Returns
- Reference to this optional
hasValue#
Checks if the optional contains a value.
- Returns
- true if contains value, false otherwise
Examples:
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
ptr#
Get pointer to contained value.
- Returns
- Pointer to contained value
Examples:
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
},
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
},
Centered {
_new<CellsView>(aui::ptr::fake_shared(&mCells)) AUI_OVERRIDE_STYLE {
Expanding(),
BackgroundSolid(AColor::BLACK),
},
},
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
AUI_REACT(mState.history.nextAction != mState.history.end()), AUI_SLOT(it)::setEnabled);
},
},
},
_new<CircleDrawArea>(aui::ptr::fake_shared(&mState)),
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
}
private:
State mState;
Get const pointer to contained value.
- Returns
- Const pointer to contained value
Examples:
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
},
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
},
Centered {
_new<CellsView>(aui::ptr::fake_shared(&mCells)) AUI_OVERRIDE_STYLE {
Expanding(),
BackgroundSolid(AColor::BLACK),
},
},
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
AUI_REACT(mState.history.nextAction != mState.history.end()), AUI_SLOT(it)::setEnabled);
},
},
},
_new<CircleDrawArea>(aui::ptr::fake_shared(&mState)),
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
}
private:
State mState;
value#
Access the contained value.
- Returns
- Reference to the contained value
Examples:
examples/7guis/cells/tests/FormulaTests.cpp
7GUIs Cells - Spreadsheet processor (Excel).
TEST_F(Cells_Formula, ChangePropagation) {
mSpreadsheet[{1, 0}].expression = "=A0+1";
mSpreadsheet[{0, 0}].expression = "228";
EXPECT_EQ(std::get<double>(mSpreadsheet[{1, 0}].value.value()), 229);
mSpreadsheet[{0, 0}].expression = "0";
EXPECT_EQ(std::get<double>(mSpreadsheet[{1, 0}].value.value()), 1);
}
examples/7guis/temperature_converter/src/main.cpp
7GUIs Temperature Converter - Fahrenheit to Celsius and vice versa.
TemperatureConverterWindow() : AWindow("AUI - 7GUIs - TempConv", 300_dp, 50_dp) {
setContents(Centered {
Horizontal {
myPicker() AUI_LET {
biConnect(it->value(), mCelsius);
it->focus();
},
Label { "°C" },
Label { "=" } AUI_OVERRIDE_STYLE { Margin { {}, 16_dp } },
myPicker() AUI_LET { biConnect(it->value(), mFahrenheit); },
Access the contained value.
- Returns
- Const reference to the contained value
Examples:
examples/7guis/cells/tests/FormulaTests.cpp
7GUIs Cells - Spreadsheet processor (Excel).
TEST_F(Cells_Formula, ChangePropagation) {
mSpreadsheet[{1, 0}].expression = "=A0+1";
mSpreadsheet[{0, 0}].expression = "228";
EXPECT_EQ(std::get<double>(mSpreadsheet[{1, 0}].value.value()), 229);
mSpreadsheet[{0, 0}].expression = "0";
EXPECT_EQ(std::get<double>(mSpreadsheet[{1, 0}].value.value()), 1);
}
examples/7guis/temperature_converter/src/main.cpp
7GUIs Temperature Converter - Fahrenheit to Celsius and vice versa.
TemperatureConverterWindow() : AWindow("AUI - 7GUIs - TempConv", 300_dp, 50_dp) {
setContents(Centered {
Horizontal {
myPicker() AUI_LET {
biConnect(it->value(), mCelsius);
it->focus();
},
Label { "°C" },
Label { "=" } AUI_OVERRIDE_STYLE { Margin { {}, 16_dp } },
myPicker() AUI_LET { biConnect(it->value(), mFahrenheit); },
valueOr#
value or alternative (either value or callback)
- Arguments
alternative
valueOrException#
value or exception
value or exception