Set up clang format & tidy and format all the files

This commit is contained in:
2023-02-09 19:41:11 +01:00
parent 38906dafef
commit c3f200fee4
9 changed files with 127 additions and 119 deletions

View File

@@ -41,14 +41,13 @@ BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon BreakInheritanceList: BeforeColon
ColumnLimit: 80 ColumnLimit: 120
CompactNamespaces: false CompactNamespaces: false
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
Cpp11BracedListStyle: true Cpp11BracedListStyle: true
DerivePointerAlignment: false DerivePointerAlignment: false
EmptyLineBeforeAccessModifier: LogicalBlock EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true IndentCaseLabels: true
IndentPPDirectives: None IndentPPDirectives: None
IndentWidth: 4 IndentWidth: 4
@@ -80,3 +79,17 @@ SpacesInSquareBrackets: false
Standard: c++17 Standard: c++17
TabWidth: 4 TabWidth: 4
UseTab: Never UseTab: Never
QualifierAlignment: Left
SortIncludes: true
IncludeBlocks: Regroup
IncludeCategories:
# Classes own header is always priority 0
# System C/C++ headers in <> with extension.
- Regex: '<([A-Za-z0-9.\Q/-_\E])+.h.*>'
Priority: 1
# System Headers in <> without extension.
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>'
Priority: 2
# c Headers in "" with extension.
- Regex: '"([A-Za-z0-9.\Q/-_\E])+"'
Priority: 3

172
.vscode/settings.json vendored
View File

@@ -1,86 +1,88 @@
{ {
"C_Cpp.codeAnalysis.clangTidy.args":[ "clangd.arguments": ["-background-index", "-compile-commands-dir=builddir"],
"-extra-arg=-std=c++17" "C_Cpp.codeAnalysis.clangTidy.args": ["-extra-arg=-std=c++17"],
], "editor.formatOnType": false,
"files.associations": { "editor.formatOnSave": true,
"cctype": "cpp", "files.associations": {
"clocale": "cpp", "cctype": "cpp",
"cmath": "cpp", "clocale": "cpp",
"cstdarg": "cpp", "cmath": "cpp",
"cstddef": "cpp", "cstdarg": "cpp",
"cstdio": "cpp", "cstddef": "cpp",
"cstdlib": "cpp", "cstdio": "cpp",
"cstring": "cpp", "cstdlib": "cpp",
"ctime": "cpp", "cstring": "cpp",
"cwchar": "cpp", "ctime": "cpp",
"cwctype": "cpp", "cwchar": "cpp",
"array": "cpp", "cwctype": "cpp",
"atomic": "cpp", "array": "cpp",
"strstream": "cpp", "atomic": "cpp",
"bit": "cpp", "strstream": "cpp",
"*.tcc": "cpp", "bit": "cpp",
"bitset": "cpp", "*.tcc": "cpp",
"cfenv": "cpp", "bitset": "cpp",
"chrono": "cpp", "cfenv": "cpp",
"codecvt": "cpp", "chrono": "cpp",
"compare": "cpp", "codecvt": "cpp",
"complex": "cpp", "compare": "cpp",
"concepts": "cpp", "complex": "cpp",
"condition_variable": "cpp", "concepts": "cpp",
"cstdint": "cpp", "condition_variable": "cpp",
"deque": "cpp", "cstdint": "cpp",
"forward_list": "cpp", "deque": "cpp",
"list": "cpp", "forward_list": "cpp",
"map": "cpp", "list": "cpp",
"set": "cpp", "map": "cpp",
"string": "cpp", "set": "cpp",
"unordered_map": "cpp", "string": "cpp",
"unordered_set": "cpp", "unordered_map": "cpp",
"vector": "cpp", "unordered_set": "cpp",
"exception": "cpp", "vector": "cpp",
"algorithm": "cpp", "exception": "cpp",
"functional": "cpp", "algorithm": "cpp",
"iterator": "cpp", "functional": "cpp",
"memory": "cpp", "iterator": "cpp",
"memory_resource": "cpp", "memory": "cpp",
"numeric": "cpp", "memory_resource": "cpp",
"optional": "cpp", "numeric": "cpp",
"random": "cpp", "optional": "cpp",
"ratio": "cpp", "random": "cpp",
"source_location": "cpp", "ratio": "cpp",
"string_view": "cpp", "source_location": "cpp",
"system_error": "cpp", "string_view": "cpp",
"tuple": "cpp", "system_error": "cpp",
"type_traits": "cpp", "tuple": "cpp",
"utility": "cpp", "type_traits": "cpp",
"fstream": "cpp", "utility": "cpp",
"initializer_list": "cpp", "fstream": "cpp",
"iomanip": "cpp", "initializer_list": "cpp",
"iosfwd": "cpp", "iomanip": "cpp",
"iostream": "cpp", "iosfwd": "cpp",
"istream": "cpp", "iostream": "cpp",
"limits": "cpp", "istream": "cpp",
"mutex": "cpp", "limits": "cpp",
"new": "cpp", "mutex": "cpp",
"numbers": "cpp", "new": "cpp",
"ostream": "cpp", "numbers": "cpp",
"semaphore": "cpp", "ostream": "cpp",
"shared_mutex": "cpp", "semaphore": "cpp",
"sstream": "cpp", "shared_mutex": "cpp",
"stdexcept": "cpp", "sstream": "cpp",
"stop_token": "cpp", "stdexcept": "cpp",
"streambuf": "cpp", "stop_token": "cpp",
"thread": "cpp", "streambuf": "cpp",
"cinttypes": "cpp", "thread": "cpp",
"typeindex": "cpp", "cinttypes": "cpp",
"typeinfo": "cpp", "typeindex": "cpp",
"valarray": "cpp", "typeinfo": "cpp",
"variant": "cpp", "valarray": "cpp",
"csignal": "cpp", "variant": "cpp",
"any": "cpp", "csignal": "cpp",
"regex": "cpp", "any": "cpp",
"future": "cpp", "regex": "cpp",
"charconv": "cpp", "future": "cpp",
"*.ipp": "cpp" "charconv": "cpp",
} "*.ipp": "cpp"
} },
"clang-tidy.buildPath": "builddir/"
}

View File

@@ -1,9 +1,9 @@
#include "PrinterTypes.hpp"
#include <memory> #include <memory>
#include <string_view>
#include "Bitmap.hpp" #include "Bitmap.hpp"
#include "PrinterTypes.hpp"
#pragma once #pragma once

View File

@@ -1,8 +1,8 @@
#include "UsbTypes.hpp"
#include <optional> #include <optional>
#include <vector> #include <vector>
#include "UsbTypes.hpp"
#pragma once #pragma once
namespace ptprnt::driver { namespace ptprnt::driver {

View File

@@ -1,8 +1,7 @@
#include "IDriver.hpp"
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include "IDriver.hpp"
#include "Usb.hpp" #include "Usb.hpp"
#pragma once #pragma once
@@ -11,8 +10,7 @@ namespace ptprnt::driver {
class P700Driver : public IDriver { class P700Driver : public IDriver {
public: public:
P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor = 0x04f9, P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor = 0x04f9, uint16_t usbDevId = 0x2061);
uint16_t usbDevId = 0x2061);
~P700Driver() override; ~P700Driver() override;
driver::info getInfo() override; driver::info getInfo() override;

View File

@@ -1,7 +1,6 @@
#include "IPrinter.hpp"
#include <memory> #include <memory>
#include "IPrinter.hpp"
#include "P700Driver.hpp" #include "P700Driver.hpp"
#pragma once #pragma once

View File

@@ -1,14 +1,13 @@
#include "P700Driver.hpp" #include "P700Driver.hpp"
#include <spdlog/spdlog.h>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include <spdlog/spdlog.h>
namespace ptprnt::driver { namespace ptprnt::driver {
P700Driver::P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor, P700Driver::P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor, uint16_t usbProductId)
uint16_t usbProductId)
: mUsbDriver{std::move(usbDriver)}, : mUsbDriver{std::move(usbDriver)},
mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId} mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId}
@@ -31,7 +30,7 @@ driver::info P700Driver::getInfo() {
bool P700Driver::open() { bool P700Driver::open() {
auto maybeUsbDev = mUsbDriver->open(mUsbDev); auto maybeUsbDev = mUsbDriver->open(mUsbDev);
if(!maybeUsbDev.has_value()) { if (!maybeUsbDev.has_value()) {
spdlog::error("Can't open P700 printer"); spdlog::error("Can't open P700 printer");
return false; return false;
} }
@@ -40,7 +39,7 @@ bool P700Driver::open() {
} }
bool P700Driver::close() { bool P700Driver::close() {
if(!mUsbDriver->close(mUsbDev)) { if (!mUsbDriver->close(mUsbDev)) {
return false; return false;
} }
return true; return true;
@@ -60,15 +59,12 @@ bool P700Driver::init() {
// TODO: There is the possibility, that two printers with the same ID are connected // TODO: There is the possibility, that two printers with the same ID are connected
// We have to take that into account // We have to take that into account
auto devIt = auto devIt = std::find_if(devs.value().begin(), devs.value().end(), [=](auto dev) {
std::find_if(devs.value().begin(), devs.value().end(), [=](auto dev) { return mUsbDev.vendorId == dev.vendorId && mUsbDev.productId == dev.productId;
return mUsbDev.vendorId == dev.vendorId && });
mUsbDev.productId == dev.productId;
});
if (devIt == devs.value().end()) { if (devIt == devs.value().end()) {
spdlog::error("No device with {0:04X}:{1:04X}", mUsbDev.vendorId, spdlog::error("No device with {0:04X}:{1:04X}", mUsbDev.vendorId, mUsbDev.productId);
mUsbDev.productId);
return false; return false;
} }

View File

@@ -1,6 +1,7 @@
#include "Usb.hpp" #include "Usb.hpp"
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
@@ -27,8 +28,7 @@ std::optional<std::vector<UsbDevice>> Usb::getDevices() {
mDevices.clear(); mDevices.clear();
if (0 == (ret = libusb_get_device_list(NULL, &libUsbDevs))) { if (0 == (ret = libusb_get_device_list(NULL, &libUsbDevs))) {
spdlog::error("Could not find any USB devices: {}", spdlog::error("Could not find any USB devices: {}", libusb_error_name(ret));
libusb_error_name(ret));
return std::nullopt; return std::nullopt;
} }
@@ -44,8 +44,7 @@ std::optional<std::vector<UsbDevice>> Usb::getDevices() {
newDev.vendorId = libUsbDesc.idVendor; newDev.vendorId = libUsbDesc.idVendor;
newDev.productId = libUsbDesc.idProduct; newDev.productId = libUsbDesc.idProduct;
newDev.device = libUsbDev; newDev.device = libUsbDev;
newDev.hndl = newDev.hndl = nullptr; // handle is only available after we opened the dev
nullptr; // handle is only available after we opened the dev
mDevices.push_back(newDev); mDevices.push_back(newDev);
} }
@@ -58,8 +57,8 @@ std::optional<UsbDevice> Usb::open(UsbDevice dev) {
int ret = 0; int ret = 0;
if ((ret = libusb_open(dev.device, &libUsbHandle) != 0)) { if ((ret = libusb_open(dev.device, &libUsbHandle) != 0)) {
spdlog::error("Could not open device {0:04X}:{1:04X}: {2}", spdlog::error("Could not open device {0:04X}:{1:04X}: {2}", dev.vendorId, dev.productId,
dev.vendorId, dev.productId, libusb_error_name(ret)); libusb_error_name(ret));
return std::nullopt; return std::nullopt;
} }
@@ -89,13 +88,14 @@ std::optional<UsbDevice> Usb::open(UsbDevice dev) {
bool Usb::close(UsbDevice dev) { bool Usb::close(UsbDevice dev) {
int ret = 0; int ret = 0;
if(0 != (ret = libusb_release_interface(dev.hndl, 0))) { if (0 != (ret = libusb_release_interface(dev.hndl, 0))) {
spdlog::error( spdlog::error(
"Could not close USB device {0:04X}:{1:04X}: " "Could not close USB device {0:04X}:{1:04X}: "
"{2}", "{2}",
dev.vendorId, dev.productId, libusb_error_name(ret)); dev.vendorId, dev.productId, libusb_error_name(ret));
} }
std::cout << "test" << std::endl;
libusb_close(dev.hndl); libusb_close(dev.hndl);
return true; return true;
} }

View File

@@ -1,12 +1,12 @@
#include <spdlog/spdlog.h>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include "IPrinter.hpp" #include "IPrinter.hpp"
#include "P700Printer.hpp" #include "P700Printer.hpp"
#include "Usb.hpp" #include "Usb.hpp"
#include <libusb-1.0/libusb.h> #include <libusb-1.0/libusb.h>
#include <spdlog/spdlog.h>
using namespace ptprnt; using namespace ptprnt;