Permalink
Browse files

Lint (clang-tidy)

  • Loading branch information...
mlang committed Jul 23, 2017
1 parent 46e9146 commit 918f3ecff8397e5b020e1e55f4e3cde63aec58dd
Showing with 124 additions and 61 deletions.
  1. +50 −3 lib/brlapi.cpp
  2. +24 −32 lib/brlapi.hpp
  3. +40 −20 lib/jack.cpp
  4. +10 −6 lib/jack.hpp
View
@@ -2,6 +2,39 @@
#include <brlapi.h>
namespace BrlAPI {
bool operator==(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X == Rhs.X && Lhs.Y == Rhs.Y;
}
bool operator!=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X != Rhs.X || Lhs.Y != Rhs.Y;
}
bool operator>(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y > Rhs.X * Rhs.Y;
}
bool operator>=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y >= Rhs.X * Rhs.Y;
}
bool operator<=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y <= Rhs.X * Rhs.Y;
}
bool operator<(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y < Rhs.X * Rhs.Y;
}
std::ostream &operator<<(std::ostream &Out, DisplaySize const &Size) {
Out << Size.X << 'x' << Size.Y;
return Out;
}
} // namespace BrlAPI
class BrlAPI::Connection::Implementation {
std::unique_ptr<gsl::byte[]> HandleStorage;
public:
@@ -16,8 +49,17 @@ BrlAPI::TTY::~TTY() {
}
void BrlAPI::TTY::writeText(std::string Text) {
if (brlapi__writeText(Conn->BrlAPI->handle(), -1, Text.c_str()) == -1)
if (brlapi__writeText(Conn->BrlAPI->handle(), -1, Text.c_str()) == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
}
std::uint64_t BrlAPI::TTY::readKey() const {
brlapi_keyCode_t Key;
if (brlapi__readKey(Conn->BrlAPI->handle(), 1, &Key) == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
return Key;
}
BrlAPI::Connection::Connection() : BrlAPI(std::make_unique<Implementation>()) {
@@ -32,6 +74,9 @@ BrlAPI::Connection::~Connection() {
brlapi__closeConnection(BrlAPI->handle());
}
BrlAPI::Connection::Connection(Connection &&) noexcept = default;
BrlAPI::Connection &BrlAPI::Connection::operator=(Connection &&) noexcept = default;
std::string BrlAPI::Connection::driverName() const {
char Name[32];
brlapi__getDriverName(BrlAPI->handle(), Name, 32);
@@ -45,8 +90,10 @@ BrlAPI::DisplaySize BrlAPI::Connection::displaySize() const {
}
BrlAPI::TTY BrlAPI::Connection::tty(int TTY, bool Raw) {
auto Number = brlapi__enterTtyMode(BrlAPI->handle(), TTY, "");
if (Number == -1) throw std::system_error(brlapi_errno, std::generic_category());
auto Number = brlapi__enterTtyMode(BrlAPI->handle(), TTY, Raw? "HandyTech" : "");
if (Number == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
return { this, Number };
}
View
@@ -1,3 +1,6 @@
#if !defined(BrlCV_BrlAPI_HPP)
#define BrlCV_BrlAPI_HPP
#include <ostream>
#include <sstream>
#include <gsl/gsl>
@@ -9,34 +12,13 @@ struct DisplaySize {
unsigned int Y;
};
inline bool operator==(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X == Rhs.X && Lhs.Y == Rhs.Y;
}
inline bool operator!=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X != Rhs.X || Lhs.Y != Rhs.Y;
}
inline bool operator>(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y > Rhs.X * Rhs.Y;
}
inline bool operator>=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y >= Rhs.X * Rhs.Y;
}
inline bool operator<=(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y <= Rhs.X * Rhs.Y;
}
inline bool operator<(DisplaySize const &Lhs, DisplaySize const &Rhs) {
return Lhs.X * Lhs.Y < Rhs.X * Rhs.Y;
}
inline std::ostream &operator<<(std::ostream &Out, DisplaySize const &Size) {
Out << Size.X << 'x' << Size.Y;
return Out;
}
bool operator==(DisplaySize const &, DisplaySize const &);
bool operator!=(DisplaySize const &, DisplaySize const &);
bool operator>(DisplaySize const &, DisplaySize const &);
bool operator>=(DisplaySize const &, DisplaySize const &);
bool operator<=(DisplaySize const &, DisplaySize const &);
bool operator<(DisplaySize const &, DisplaySize const &);
std::ostream &operator<<(std::ostream &Out, DisplaySize const &);
class Connection;
@@ -51,15 +33,17 @@ class TTY {
~TTY();
TTY(TTY const &) = delete;
TTY(TTY &&) = default;
TTY(TTY &&) noexcept = default;
TTY &operator=(TTY const &) = delete;
TTY &operator=(TTY &&) = default;
TTY &operator=(TTY &&) noexcept = default;
int number() const { return Number; }
int number() const noexcept { return Number; }
void writeText(std::string);
void writeText(std::stringstream const &Stream) { writeText(Stream.str()); }
std::uint64_t readKey() const;
};
class Connection {
@@ -71,10 +55,18 @@ class Connection {
Connection();
~Connection();
Connection(Connection const &) = delete;
Connection &operator=(Connection const &) = delete;
Connection(Connection &&) noexcept;
Connection &operator=(Connection &&) noexcept;
std::string driverName() const;
DisplaySize displaySize() const;
TTY tty(int, bool);
};
}
} // namespace BrlAPI
#endif // BrlCV_BrlAPI_HPP
View
@@ -7,7 +7,7 @@
namespace std {
template<> struct is_error_code_enum<JackStatus>:true_type{};
template<> struct is_error_condition_enum<JackStatus>:true_type{};
}
} // namespace std
namespace {
@@ -17,23 +17,29 @@ struct JACKErrorCategory : std::error_category {
equivalent(int Value, const std::error_condition& Condition) const noexcept override
{
return Condition.category() == *this &&
Value & Condition.value() == Condition.value();
(Value & Condition.value()) == Condition.value();
}
std::string message(int ev) const override {
std::string msg;
if (ev & JackFailure) {
if ((ev & JackFailure) == JackFailure) {
msg += "Overall operation failed";
}
if (ev & JackInvalidOption) {
if (!msg.empty()) msg += ", ";
if ((ev & JackInvalidOption) == JackInvalidOption) {
if (!msg.empty()) {
msg += ", ";
}
msg += "The operation contained an invalid or unsupported option";
}
if (ev & JackNameNotUnique) {
if (!msg.empty()) msg += ", ";
if ((ev & JackNameNotUnique) == JackNameNotUnique) {
if (!msg.empty()) {
msg += ", ";
}
msg += "The desired client name was not unique";
}
if (ev & JackServerFailed) {
if (!msg.empty()) msg += ", ";
if ((ev & JackServerFailed) == JackServerFailed) {
if (!msg.empty()) {
msg += ", ";
}
msg += "Unable to connect to the JACK server";
}
if (msg.empty()) {
@@ -46,7 +52,7 @@ struct JACKErrorCategory : std::error_category {
const JACKErrorCategory JACKCategory {};
}
} // namespace
std::error_code make_error_code(JackStatus e) {
return { static_cast<int>(e), JACKCategory };
@@ -59,15 +65,23 @@ std::error_condition make_error_condition(JackStatus e) {
struct JACK::Client::Implementation {
jack_client_t *const Client;
Implementation(std::string Name)
explicit Implementation(std::string Name)
: Client([&] {
jack_status_t Status;
auto Handle = jack_client_open(Name.c_str(), JackNoStartServer, &Status);
if (!Handle) throw std::system_error(make_error_code(Status));
if (Handle == nullptr) {
throw std::system_error(make_error_code(Status));
}
return Handle;
}())
{}
~Implementation() { jack_client_close(Client); }
Implementation(Implementation const &) = delete;
Implementation(Implementation &&) = delete;
Implementation &operator=(Implementation const &) = delete;
Implementation &operator=(Implementation &&) = delete;
};
struct JACK::Port::Implementation {
@@ -77,7 +91,11 @@ struct JACK::Port::Implementation {
Implementation(JACK::Client *Client, std::string Name, std::string Type, JackPortFlags Flags)
: Client(Client)
, Port(jack_port_register(Client->JACK->Client, Name.c_str(), Type.c_str(), Flags, 0))
{ if (!Port) throw std::runtime_error("Failed to register port"); }
{
if (Port == nullptr) {
throw std::runtime_error("Failed to register port");
}
}
~Implementation() { jack_port_unregister(Client->JACK->Client, Port); }
};
@@ -87,8 +105,8 @@ Port::Port(Client *C, std::string N, std::string T, bool IsInput)
: JACK(std::make_unique<Implementation>(C, N, T, static_cast<JackPortFlags>(IsInput ? JackPortIsInput : JackPortIsOutput)))
{}
Port::Port(Port &&) = default;
Port &Port::operator=(Port &&) = default;
Port::Port(Port &&) noexcept = default;
Port &Port::operator=(Port &&) noexcept = default;
Port::~Port() = default;
@@ -110,7 +128,7 @@ AudioOut::AudioOut(JACK::Client *Client, std::string Name)
gsl::span<float> AudioOut::buffer(std::int32_t FrameCount) {
return {
static_cast<float *>(jack_port_get_buffer(JACK->Port, FrameCount)),
FrameCount
FrameCount
};
}
@@ -125,8 +143,8 @@ Client::Client(std::string Name)
jack_set_process_callback(JACK->Client, &JACK::process, this);
}
Client::Client(Client &&) = default;
Client &Client::operator=(Client &&) = default;
Client::Client(Client &&) noexcept = default;
Client &Client::operator=(Client &&) noexcept = default;
Client::~Client() = default;
@@ -155,7 +173,9 @@ void Client::activate() {
void Client::deactivate() {
auto Status = jack_deactivate(JACK->Client);
if (Status) throw std::system_error(Status, std::generic_category());
if (Status != 0) {
throw std::system_error(Status, std::generic_category());
}
}
}
} // namespace JACK
View
@@ -1,3 +1,6 @@
#if !defined(BrlCV_JACK_HPP)
#define BrlCV_JACK_HPP
#include <memory>
#include <string>
@@ -15,8 +18,8 @@ class Port {
public:
~Port();
Port(Port &&);
Port &operator=(Port &&);
Port(Port &&) noexcept;
Port &operator=(Port &&) noexcept;
Port(const Port &) = delete;
Port &operator=(const Port &) = delete;
};
@@ -43,9 +46,9 @@ class Client {
friend class Port;
public:
Client(std::string Name);
Client(Client &&);
Client &operator=(Client &&);
explicit Client(std::string Name);
Client(Client &&) noexcept;
Client &operator=(Client &&) noexcept;
Client(const Client &) = delete;
Client &operator=(const Client &) = delete;
virtual ~Client();
@@ -62,4 +65,5 @@ class Client {
virtual int process(std::uint32_t nframes) = 0;
};
}
} // namespace JACK
#endif // BrlCV_JACK_HPP

0 comments on commit 918f3ec

Please sign in to comment.