AByteBuffer#
std::vector-like growing array for byte storage.
Header: | #include <AUI/Common/AByteBuffer.h> |
CMake: | aui_link(my_target PUBLIC aui::core) |
Public Methods#
at#
Gets value of specified type by byte index relative to the beginning of internal buffer.
- Arguments
byteIndex
byte offset realtive to the beginning of internal buffer- Returns
- data
Examples#
examples/7guis/cells/src/AST.cpp
7GUIs Cells - Spreadsheet processor (Excel).
Gets value of specified type by byte index relative to the beginning of internal buffer.
- Arguments
byteIndex
byte offset realtive to the beginning of internal buffer- Returns
- data
Examples#
examples/7guis/cells/src/AST.cpp
7GUIs Cells - Spreadsheet processor (Excel).
capacity#
- Returns
- size of whole buffer (including possibly invalid data)
data#
- Returns
- Internal buffer.
empty#
- Returns
- true if size == 0
Examples#
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
namespace {
_<AView> profilePhoto(const _<Contact>& contact) {
return Centered {
Label {} & contact->displayName.readProjected([](const AString& s) {
return s.empty() ? "?" : AString(1, s.first()).uppercase();
}) AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
} AUI_WITH_STYLE {
FixedSize { 64_dp },
BorderRadius { 32_dp },
BackgroundGradient { AColor::GRAY.lighter(0.5f), AColor::GRAY, 163_deg },
examples/7guis/cells/src/Formula.cpp
7GUIs Cells - Spreadsheet processor (Excel).
return precompile(expression)(spreadsheet);
}
formula::Precompiled formula::precompile(const AString& expression) {
if (expression.empty()) {
return [](const Spreadsheet&) { return std::nullopt; };
}
if (auto d = expression.toDouble()) {
return [d = *d](const Spreadsheet&) { return d; };
}
examples/7guis/cells/src/AST.cpp
7GUIs Cells - Spreadsheet processor (Excel).
auto putValue = [&](_unique<INode> node) {
if (temporaryValue) {
throw AException("SYNTAX");
}
if (!binaryOperators.empty()) {
if (binaryOperators.last().op->right) {
throw AException {};
}
binaryOperators.last().op->right = std::move(node);
return;
getAvailableToWrite#
- Returns
- delta between internal buffer size and payload size.
getReserved#
- Returns
- size of internal buffer. Must be greater that getSize()
getSize#
- Returns
- size of payload (valid data)
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
AView::render(context);
mShader.use();
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
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.
}
auto drawGrid = [&] {
ASmallVector<std::pair<glm::vec2, glm::vec2>, 128 * 2> points;
for (int i = 1; i < mCells->size().x; ++i) {
points << std::make_pair(glm::vec2(i * SCALE, 0.f), glm::vec2(i * SCALE, getSize().y));
}
for (int i = 1; i < mCells->size().y; ++i) {
points << std::make_pair(glm::vec2(0.f, i * SCALE), glm::vec2(getSize().x, i * SCALE));
}
ctx.render.lines(ASolidBrush { AColor::GRAY }, points);
grow#
If getReserved() - getSize()
is less than size
increases internal buffer size
enough to store size
bytes.
increaseInternalBuffer#
Increases internal buffer.
increaseSize#
- Arguments
s
new size of the payload
Forces new size of the buffer.
- Sneaky assert:
-
Assert fails when new size is greater that reserved buffer size. Use
AByteBuffer::resize
to avoid this.
reallocate#
- Arguments
s
new size of the payload
Resizes the buffer WITHOUT keeping it's contents. When reserved buffer size is differs from the new size, buffer is reallocated with new size.
reserve#
Resizes internal buffer.
Examples#
examples/ui/views/src/DemoGraphView.cpp
Views Example - All-in-one views building example.
resize#
- Arguments
s
new size of the payload
Resizes the buffer keeping it's contents. When reserved buffer size is less than the new size, buffer is reallocated with new size.
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.
examples/app/minesweeper/src/MinesweeperWindow.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
mReveal = false;
mBombsPlanted = false;
mGrid->setLayout(std::make_unique<AGridLayout>(columns, rows));
mField.clear();
mField.resize(columns * rows);
for (int i = 0; i < columns * rows; ++i) {
int x = i % columns;
int y = i / columns;
auto cell = _new<CellView>(fieldAt(x, y));
examples/7guis/cells/src/Spreadsheet.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
setSize#
- Arguments
s
new size of the payload
Forces new size of the buffer.
- Sneaky assert:
-
Assert fails when new size is greater that reserved buffer size. Use
AByteBuffer::resize
to avoid this.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
mShader.set(UNIFORM_RATIO, mAspectRatio = float(size.x) / float(size.y));
}
examples/app/fractal/src/FractalView.h
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
void onKeyRepeat(AInput::Key key) override;
void onScroll(const AScrollEvent& event) override;
void setSize(glm::ivec2 size) override;
gl::Program& getShader() { return mShader; }
const _<gl::Texture2D>& getTexture() const { return mTexture; }
size#
- Returns
- size of payload (valid data)
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
mShader.set(UNIFORM_RATIO, mAspectRatio = float(size.x) / float(size.y));
}
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.
using CellsImage = AFormattedImage<APixelFormat::RGBA_BYTE>;
class Cells : public AObject {
public:
Cells(glm::ivec2 size) {
mSize = size;
for (auto s : { &mStorage, &mNextPopulation }) {
s->resize(size.x * size.y);
}
examples/7guis/cells/src/Spreadsheet.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Functions.cpp
7GUIs Cells - Spreadsheet processor (Excel).
return double(accumulator);
} },
{ "IF",
[](Ctx ctx) {
if (ctx.args.size() != 3) {
throw AException("ARG");
}
auto condition = std::get_if<double>(&ctx.args[0]);
if (condition == nullptr) {
throw AException("ARG0");
write#
void AByteBuffer::write(IInputStream& stream, size_t size)
- Arguments
stream
size
Reads exact size
bytes from stream
.