Skip to content

Commit

Permalink
Fixed cppcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andir committed Jul 31, 2017
1 parent 1eb187e commit 50728c0
Show file tree
Hide file tree
Showing 36 changed files with 145 additions and 110 deletions.
118 changes: 82 additions & 36 deletions CMake/cotire.cmake

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")

include(cotire)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -O3 -march=native -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -O3 -march=native -Wall -flto")

#SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
#SET(BUILD_SHARED_LIBRARIES OFF)
Expand Down
4 changes: 2 additions & 2 deletions DevMemBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <unistd.h>
#include <numeric>

DevMemBuffer::DevMemBuffer(const std::string filename, std::vector<size_t> sizes, size_t configuration_offset,
DevMemBuffer::DevMemBuffer(const std::string& filename, const std::vector<size_t>& sizes, size_t configuration_offset,
size_t data_offset) :
sizes(sizes),
count_offset(configuration_offset),
Expand All @@ -35,7 +35,7 @@ DevMemBuffer::~DevMemBuffer() {
close();
}

void DevMemBuffer::_resize(const std::vector<size_t> sizes) {
void DevMemBuffer::_resize(const std::vector<size_t>& sizes) {
// update data buffer
buffer.release();
memmapData.close();
Expand Down
4 changes: 2 additions & 2 deletions DevMemBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class DevMemBuffer {

AllocatedBuffer<LargeRGB> buffer;

void _resize(const std::vector<size_t> sizes);
void _resize(const std::vector<size_t>& sizes);

public:
DevMemBuffer(const std::string filename = "/dev/mem", std::vector<size_t> sizes = {16000},
DevMemBuffer(const std::string& filename = "/dev/mem", const std::vector<size_t>& sizes = {16000},
size_t configuration_offset = 0x40000000, size_t data_offset = 0x1ff00000);

~DevMemBuffer();
Expand Down
2 changes: 1 addition & 1 deletion FrameScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FrameScheduler {
std::chrono::steady_clock::time_point _stop;

public:
FrameScheduler(const int rate);
explicit FrameScheduler(const int rate);

void delay(const uint64_t duration);
};
Expand Down
4 changes: 2 additions & 2 deletions SharedMemoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <fcntl.h>
#include <unistd.h>

int _shm_open(const std::string filename) {
int _shm_open(const std::string& filename) {
int fd = shm_open(filename.c_str(), O_CREAT | O_TRUNC | O_RDWR, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);

return fd;
}

SharedMemoryBuffer::SharedMemoryBuffer(const std::string filename, size_t size) :
SharedMemoryBuffer::SharedMemoryBuffer(const std::string& filename, size_t size) :
buffer(0, nullptr) {

fd = _shm_open(filename);
Expand Down
2 changes: 1 addition & 1 deletion SharedMemoryBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SharedMemoryBuffer {
void _resize(const size_t size);

public:
SharedMemoryBuffer(const std::string filename, size_t size);
SharedMemoryBuffer(const std::string& filename, size_t size);

~SharedMemoryBuffer();

Expand Down
4 changes: 2 additions & 2 deletions VariableStore/BoundConcreteValueType.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BoundConcreteValue : public ValueType {
std::shared_ptr<ConcreteValueType<EnclosedValue >> value;

public:
BoundConcreteValue(const std::string name, const std::string description, VariableStore &store,
BoundConcreteValue(const std::string& name, const std::string& description, VariableStore &store,
EnclosedValue initial_value, CallbackType cb = nullptr) :
name(name),
store(store),
Expand Down Expand Up @@ -98,4 +98,4 @@ class BoundConcreteValue : public ValueType {

return *this;
}
};
};
10 changes: 5 additions & 5 deletions VariableStore/VariableStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

VariableStore::VariableStore() : lock() {}

void VariableStore::registerVar(const std::string name, const std::string type_name, std::shared_ptr<ValueType> var) {
void VariableStore::registerVar(const std::string& name, const std::string& type_name, std::shared_ptr<ValueType> var) {
std::unique_lock<std::shared_mutex> locker(lock);
auto weak_ptr = std::weak_ptr<ValueType>(var);

Expand All @@ -19,7 +19,7 @@ void VariableStore::registerVar(const std::string name, const std::string type_n
}


void VariableStore::unregisterVar(const std::string name) {
void VariableStore::unregisterVar(const std::string& name) {
std::unique_lock<std::shared_mutex> locker(lock);
{
auto it = vars.find(name);
Expand Down Expand Up @@ -70,7 +70,7 @@ std::set<std::string> VariableStore::keys() const {
return list;
}

std::shared_ptr<ValueType> VariableStore::getVar(const std::string name) const {
std::shared_ptr<ValueType> VariableStore::getVar(const std::string& name) const {
std::shared_lock<std::shared_mutex> locker(lock);
auto it = vars.find(name);
if (it != vars.end()) {
Expand All @@ -82,11 +82,11 @@ std::shared_ptr<ValueType> VariableStore::getVar(const std::string name) const {
return nullptr;
}

std::string VariableStore::getTypeName(const std::string name) const {
std::string VariableStore::getTypeName(const std::string& name) const {
std::shared_lock<std::shared_mutex> locker(lock);
auto it = types.find(name);
if (it != types.end()) {
return (*it).second;
}
return "";
}
}
8 changes: 4 additions & 4 deletions VariableStore/VariableStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class VariableStore {

VariableStore();

void registerVar(const std::string name, const std::string type_name, std::shared_ptr<ValueType> var);
void registerVar(const std::string& name, const std::string& type_name, std::shared_ptr<ValueType> var);

void unregisterVar(const std::string name);
void unregisterVar(const std::string& name);

void cleanUp();

std::set<std::string> keys() const;

std::shared_ptr<ValueType> getVar(const std::string name) const;
std::shared_ptr<ValueType> getVar(const std::string& name) const;

std::string getTypeName(const std::string name) const;
std::string getTypeName(const std::string& name) const;

};

Expand Down
8 changes: 4 additions & 4 deletions WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Measure {
struct Measurment &measurment;
MeasureTime<std::chrono::nanoseconds> measureTime;
public:
Measure(std::string name, Timeing &t) : timeing(t), measurment(t.measurments[name]) {
Measure(const std::string& name, Timeing &t) : timeing(t), measurment(t.measurments[name]) {
}

~Measure() {
Expand Down Expand Up @@ -103,7 +103,7 @@ void WorkerThread::run() {
#endif
while (true) {
#ifdef MEASURE_TIME
Measure("frame_time", t);
Measure frame_time("frame_time", t);
#endif
if (new_config_ptr.get() != nullptr) {
break;
Expand All @@ -115,13 +115,13 @@ void WorkerThread::run() {
step->update(config.get());
if (step->isEnabled()) {
#ifdef MEASURE_TIME
Measure(step->getName(), t);
Measure step_time(step->getName(), t);
#endif
buffer = (*step)(buffer);
}
}
for (const auto &output : config->outputs) {
Measure(output.first, t);
Measure output_time(output.first, t);
(*output.second).draw(*buffer);
}
#ifdef MEASURE_TIME
Expand Down
4 changes: 2 additions & 2 deletions algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace algorithm {
}

template<typename Iterator>
void Fade(Iterator from, Iterator to) {
void Fade(Iterator& from, Iterator& to) {
using value_type = typename Iterator::value_type;
const size_t length = (from > to) ? from - to : to - from;

Expand All @@ -95,7 +95,7 @@ namespace algorithm {
const float step = 1.0f / length;
size_t i = 0;
Mask<value_type> m;
for (auto it = from; it != to; it++, i++) {
for (auto it = from; it != to; ++it, ++i) {
const float factor = step * i;
*it = m(factor, *it);
}
Expand Down
2 changes: 2 additions & 0 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ ConfigPtr parseConfig(const std::string &filename) {


Config::Config() :
fps(30),
width(100),
store(std::make_shared<VariableStore>()) {
}

Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct MqttConfig {
struct ConfigParsingException : public std::exception {
const std::string s;

ConfigParsingException(std::string s) : s(s) {}
explicit ConfigParsingException(const std::string& s) : s(s) {}

const char *what() const throw() {
return s.c_str();
Expand Down
10 changes: 5 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
width: 1000
width: 2000
fps: 20

mqtt:
Expand Down Expand Up @@ -29,9 +29,9 @@ sequence:
- gameoflife:
enabled: true

# - udpinput:
# enabled: 0
# port: 1337
- udpinput:
enabled: true
port: 1337


# - initSolidColor:
Expand Down Expand Up @@ -88,7 +88,7 @@ outputs:
# UDPOutput:
# type: udp
# params:
# host: 172.23.97.109
# host: "fd42:ccc:da:1::2"
# port: 6453

#output: Websocket1
2 changes: 1 addition & 1 deletion net/HSVUDPSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HSVUDPSink {

public:

HSVUDPSink(const int port);
explicit HSVUDPSink(const int port);

~HSVUDPSink();

Expand Down
2 changes: 1 addition & 1 deletion net/MqttConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace {
}
}

MqttConnection::MqttConnection(std::shared_ptr<VariableStore> store, const std::string broker, const std::string realm)
MqttConnection::MqttConnection(std::shared_ptr<VariableStore>& store, const std::string& broker, const std::string& realm)
:
realm(realm),
store(store),
Expand Down
4 changes: 2 additions & 2 deletions net/MqttConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

class MqttConnection {
bool thread_running;
std::string realm;
const std::string realm;
std::shared_ptr<VariableStore> store;
boost::asio::io_service io_service;
std::shared_ptr<mqtt::client<boost::asio::ip::tcp::socket, mqtt::null_strand>> mqtt_client;
std::thread worker_thread;


public:
MqttConnection(std::shared_ptr<VariableStore> store, const std::string broker, const std::string realm);
MqttConnection(std::shared_ptr<VariableStore>& store, const std::string& broker, const std::string& realm);

void stop() {
if (!io_service.stopped())
Expand Down
2 changes: 1 addition & 1 deletion net/RGBUDPSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RGBUDPSink {

public:

RGBUDPSink(const int port);
explicit RGBUDPSink(const int port);

~RGBUDPSink();

Expand Down
4 changes: 2 additions & 2 deletions operations/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class Operation {
BoundConcreteValue<float> alpha;


static inline std::string concat(const std::string a, const std::string b) {
static inline std::string concat(const std::string& a, const std::string& b) {
return a + b;
}

public:

using BufferType = std::shared_ptr<AbstractBaseBuffer<HSV> >;

Operation(const std::string name, VariableStore &store, YAML::const_iterator begin, YAML::const_iterator end) :
Operation(const std::string& name, VariableStore &store, YAML::const_iterator begin, YAML::const_iterator end) :
name(name),
enabled(concat(name, "/enabled"), Operation::BOOLEAN, store, getValueByKey<bool>("enabled", begin, end, 1)),
alpha(concat(name, "/alpha"), Operation::FLOAT, store, getValueByKey<float>("alpha", begin, end, 1)) {}
Expand Down
13 changes: 0 additions & 13 deletions operations/ShadeOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,4 @@ class ShadeOperation : public Operation {
algorithm::MaskBuffer(value, *buffer);
return buffer;
}

private:
float parse_value(YAML::const_iterator start, YAML::const_iterator end) {
for (; start != end; start++) {
const auto &v = *start;
if (v.first.as<std::string>() == "value") {
return v.second.as<float>();
}
}
return 1.0f;
}
};


2 changes: 1 addition & 1 deletion operations/lua/LuaHSVBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LuaHSVBuffer {

public:

LuaHSVBuffer(lua_State *L) : buffer(((AbstractBaseBuffer<HSV> *) (lua_touserdata(L, 1)))) {
explicit LuaHSVBuffer(lua_State *L) : buffer(static_cast<AbstractBaseBuffer<HSV>* >(lua_touserdata(L, 1))) {
}

int set(lua_State *L) {
Expand Down
2 changes: 1 addition & 1 deletion outputs/DevMemOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DevMemOutput : public Output {
DevMemBuffer devMemBuffer;

public:
DevMemOutput(const YAML::Node &params);
explicit DevMemOutput(const YAML::Node &params);

virtual ~DevMemOutput() {};

Expand Down
4 changes: 2 additions & 2 deletions outputs/HSVUDPOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


inline std::string
getValueOrDefault(const std::string name, const YAML::Node &params, const std::string default_value) {
getValueOrDefault(const std::string& name, const YAML::Node &params, const std::string& default_value) {
if (params[name]) {
return params[name].as<std::string>();
}
Expand All @@ -18,7 +18,7 @@ HSVUDPOutput::HSVUDPOutput(const YAML::Node &params)
: HSVUDPOutput(getValueOrDefault("host", params, "127.0.0.1"), getValueOrDefault("port", params, "1338")) {
}

HSVUDPOutput::HSVUDPOutput(const std::string destination, const std::string port) :
HSVUDPOutput::HSVUDPOutput(const std::string& destination, const std::string& port) :
socket(io_service, udp::endpoint(udp::v4(), 0)),
resolver(io_service) {
endpoint = *resolver.resolve({udp::v4(), destination, port});
Expand Down
4 changes: 2 additions & 2 deletions outputs/HSVUDPOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class HSVUDPOutput : public Output {
udp::endpoint endpoint;

public:
HSVUDPOutput(const YAML::Node &params);
explicit HSVUDPOutput(const YAML::Node &params);

HSVUDPOutput(const std::string destination, const std::string port);
HSVUDPOutput(const std::string& destination, const std::string& port);

void draw(const std::vector<HSV> &buffer);

Expand Down
2 changes: 1 addition & 1 deletion outputs/SharedMemoryOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SharedMemoryOutput : public Output {
SharedMemoryBuffer shmBuffer;

public:
SharedMemoryOutput(const YAML::Node &params);
explicit SharedMemoryOutput(const YAML::Node &params);

virtual ~SharedMemoryOutput() {};

Expand Down
Loading

0 comments on commit 50728c0

Please sign in to comment.