/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/byte_widths.cpp
137 строк
3 KB
pimenov-and
Перенос функциональности из старого проекта, в основном это описания узлов
19 июл 2026, 20:13
19 июл 2026, 20:13
cb3c51b
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Ширина в байтах //////////////////////////////////////////////////////////////// #include "byte_widths.h" #include "stl_helper.h" //============================================================== using std::array; //============================================================== // Конвертация ширины в байтах в строку //============================================================== QString byteWidthToStr(ByteWidths width) { switch (width) { case ByteWidths::Width8: { return "Width8"; } case ByteWidths::Width16: { return "Width16"; } default: { return "Unknown"; } } } //============================================================== // Конвертация строки в ширину в байтах //============================================================== ByteWidths strToWidthByte(const QString &str) { if (str == "Width8") { return ByteWidths::Width8; } else if (str == "Width16") { return ByteWidths::Width16; } else { return ByteWidths::Unknown; } } //============================================================== // Конвертация числа в ширину в байтах //============================================================== ByteWidths intToByteWidth(qint32 value) noexcept { switch (value) { case 8: { return ByteWidths::Width8; } case 16: { return ByteWidths::Width16; } default: { return ByteWidths::Unknown; } } } //============================================================== // Конвертация ширины в байтах в индекс //============================================================== qint32 byteWidthToIndex(ByteWidths width) noexcept { switch (width) { case ByteWidths::Width8: { return 0; } case ByteWidths::Width16: { return 1; } default: { return -1; } } } //============================================================== // Конвертация индекса в ширину в байтах //============================================================== ByteWidths indexToByteWidth(qint32 index) noexcept { switch (index) { case 0: { return ByteWidths::Width8; } case 1: { return ByteWidths::Width16; } default: { return ByteWidths::Unknown; } } } //============================================================== // Получение значений ширины в байтах //============================================================== array<ByteWidths, 3> getByteWidthValues() { return array<ByteWidths, 3> { ByteWidths::Unknown, ByteWidths::Width8, ByteWidths::Width16 }; } //============================================================== // Проверка корректности значения ByteWidths //============================================================== bool isCorrect(ByteWidths width) { return contains(getByteWidthValues(), width); }