From 65cab142fb9afe505fa5de78e694aaa9c424b754 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 17 Nov 2019 21:11:27 +0100 Subject: [PATCH] Apply clang-format with adapted settings (#399) --- .clang-format | 6 + .editorconfig | 21 +- .travis.yml | 135 +-- include/ApiIF.hpp | 36 +- include/Buffer.hpp | 40 +- include/Channel.hpp | 63 +- include/Config_Options.hpp | 88 +- include/CurlSessionProvider.hpp | 64 +- include/Json.hpp | 17 +- include/Meter.hpp | 40 +- include/MeterMap.hpp | 69 +- include/Obis.hpp | 27 +- include/Options.hpp | 66 +- include/PushData.hpp | 75 +- include/Reading.hpp | 101 +-- include/VZException.hpp | 99 +-- include/api.h | 32 +- include/api/CurlCallback.hpp | 35 +- include/api/CurlIF.hpp | 42 +- include/api/CurlResponse.hpp | 63 +- include/api/InfluxDB.hpp | 70 +- include/api/MySmartGrid.hpp | 156 ++-- include/api/Null.hpp | 20 +- include/api/Volkszaehler.hpp | 100 +-- include/common.h | 19 +- include/exception.h | 7 +- include/gitSha1.h | 3 +- include/list.h | 46 +- include/local.h | 21 +- include/mqtt.hpp | 19 +- include/protocols/MeterD0.hpp | 20 +- include/protocols/MeterExec.hpp | 4 +- include/protocols/MeterFile.hpp | 6 +- include/protocols/MeterFluksoV2.hpp | 10 +- include/protocols/MeterOCR.hpp | 215 ++--- include/protocols/MeterOMS.hpp | 35 +- include/protocols/MeterRandom.hpp | 6 +- include/protocols/MeterS0.hpp | 50 +- include/protocols/MeterSML.hpp | 18 +- include/protocols/MeterW1therm.hpp | 35 +- include/protocols/Protocol.hpp | 52 +- include/shared_ptr.hpp | 14 +- include/threads.h | 4 +- include/unit.h | 148 ++-- include/vzlogger.h | 4 +- src/Buffer.cpp | 130 ++- src/Channel.cpp | 46 +- src/Config_Options.cpp | 205 ++--- src/CurlSessionProvider.cpp | 125 +-- src/Meter.cpp | 161 ++-- src/MeterMap.cpp | 50 +- src/Obis.cpp | 292 +++---- src/Options.cpp | 139 ++-- src/PushData.cpp | 304 ++++--- src/Reading.cpp | 187 ++--- src/api.cpp | 105 ++- src/api/CurlCallback.cpp | 46 +- src/api/CurlIF.cpp | 15 +- src/api/CurlResponse.cpp | 104 +-- src/api/InfluxDB.cpp | 295 +++---- src/api/MySmartGrid.cpp | 349 ++++---- src/api/Null.cpp | 34 +- src/api/Volkszaehler.cpp | 204 +++-- src/exception.cpp | 4 +- src/local.cpp | 107 +-- src/ltqnorm.cpp | 75 +- src/mqtt.cpp | 310 +++---- src/protocols/MeterD0.cpp | 1034 ++++++++++++----------- src/protocols/MeterExec.cpp | 137 +-- src/protocols/MeterFile.cpp | 123 +-- src/protocols/MeterFluksoV2.cpp | 50 +- src/protocols/MeterOCR.cpp | 1200 +++++++++++++++------------ src/protocols/MeterOCRTesseract.cpp | 260 +++--- src/protocols/MeterOMS.cpp | 507 +++++------ src/protocols/MeterRandom.cpp | 29 +- src/protocols/MeterS0.cpp | 392 ++++----- src/protocols/MeterSML.cpp | 221 ++--- src/protocols/MeterW1therm.cpp | 61 +- src/test.cpp | 15 +- src/threads.cpp | 141 ++-- src/vzlogger.cpp | 232 +++--- tests/MeterD0.cpp | 268 +++--- tests/MeterSML.cpp | 42 +- tests/example_test.cpp | 22 +- tests/main.cpp | 11 +- tests/mocks/Channel.hpp | 50 +- tests/mocks/mock_MeterOMS.cpp | 144 ++-- tests/mocks/mock_MeterS0.cpp | 97 +-- tests/mocks/mock_MeterW1therm.cpp | 67 +- tests/mocks/mock_metermap.cpp | 108 ++- tests/mocks/protocols/MeterOCR.hpp | 19 +- tests/ut_CurlSessionProvider.cpp | 54 +- tests/ut_MeterExec.cpp | 26 +- tests/ut_MeterFile.cpp | 85 +- tests/ut_MeterOCR.cpp | 219 +++-- tests/ut_MeterOCRTesseract.cpp | 100 ++- tests/ut_PushData.cpp | 180 ++-- tests/ut_api_volkszaehler.cpp | 146 ++-- tests/ut_buffer.cpp | 107 ++- tests/ut_meter.cpp | 20 +- tests/ut_obis.cpp | 20 +- 101 files changed, 5795 insertions(+), 5880 deletions(-) create mode 100644 .clang-format mode change 100755 => 100644 src/protocols/MeterD0.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..91248ad0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: LLVM +ColumnLimit: 100 +IndentWidth: 4 +TabWidth: 4 +UseTab: ForContinuationAndIndentation +AlignTrailingComments: true diff --git a/.editorconfig b/.editorconfig index b4d31cee..dc99d92a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,19 +1,16 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - +# top-most EditorConfig file root = true +# Unix-style newlines with a newline ending every file [*] +charset = utf-8 trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true -[**.cpp] -indent_style = tab -indent_size = 4 - -[**.hpp] +# Tab indentation (no size specified) +[Makefile] indent_style = tab -indent_size = 4 -[**.h] -indent_style = tab -indent_size = 4 +[*.{c,h,cpp,hpp}] +indent_size = 4 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7f6ac5c2..163e4de2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,72 +1,87 @@ sudo: required -dist: trusty +dist: xenial language: cpp -compiler: - - clang - - gcc - -env: - - CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=0 - - CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 +addons: + apt: + sources: + - llvm-toolchain-trusty + packages: + - clang-format-9 matrix: - exclude: - - compiler: clang - env: CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + include: + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + compiler: clang + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + compiler: gcc + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=0 + compiler: gcc + - env: FORMAT=1 before_install: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo apt-get update -qq -# uncomment for ubuntu precise. not needed for >=trusty - if [ "$CXX" = "g++" ]; then sudo apt-get install -y -qq g++-4.8; export CXX="g++-4.8" CC="gcc-4.8"; else echo "yes" | sudo add-apt-repository 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu precise main'; echo "yes" | sudo add-apt-repository 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.6 main'; wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -; sudo apt-get update; sudo apt-get install -qq --allow-unauthenticated llvm-3.6 llvm-3.6-dev clang-3.6 libstdc++-4.8-dev; export CXX="clang++-3.6" CC="clang-3.6"; fi - - if [ "$USE_GCC7" = "1" ]; then sudo apt-get install -y -qq g++-7; export CXX="g++-7" CC="gcc-7"; fi - - $CXX --version -# install json-c - - sudo apt-get install -y build-essential - - sudo apt-get install -y wget - - sudo apt-get install -y libtool - - git clone -b json-c-0.12 https://github.com/json-c/json-c - - cd json-c - - sh autogen.sh - - ./configure - - make - - sudo make install - - cd .. - - sudo apt-get install -y libcurl4-openssl-dev openssl libmicrohttpd-dev uuid-dev uuid-runtime libunistring-dev -# -- get libsml -- - - git clone https://github.com/volkszaehler/libsml.git # or github.com/TheCount/libsml.git # or https://github.com/dailab/libsml.git - - cd libsml - - # git checkout develop # only dev branch seems to work - - make -# -- install libsml -- - - sudo cp sml/lib/libsml.* /usr/lib/. - - sudo cp -R sml/include/* /usr/include/. - - sudo cp sml.pc /usr/lib/pkgconfig/. - - cd .. + - clang-format --version + +install: + - | + if [ -n "$BUILD" ]; then + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + sudo apt-get update -qq + if [ "$USE_GCC7" = "1" ]; then sudo apt-get install -y -qq g++-7; export CXX="g++-7" CC="gcc-7"; fi + $CXX --version + # install json-c + sudo apt-get install -y build-essential + sudo apt-get install -y wget + sudo apt-get install -y libtool + git clone -b json-c-0.12 https://github.com/json-c/json-c + cd json-c + sh autogen.sh + ./configure + make + sudo make install + cd .. + sudo apt-get install -y libcurl4-openssl-dev openssl libmicrohttpd-dev uuid-dev uuid-runtime libunistring-dev + # -- get libsml -- + git clone https://github.com/volkszaehler/libsml.git # or github.com/TheCount/libsml.git # or https://github.com/dailab/libsml.git + cd libsml + # git checkout develop # only dev branch seems to work + make + # -- install libsml -- + sudo cp sml/lib/libsml.* /usr/lib/. + sudo cp -R sml/include/* /usr/include/. + sudo cp sml.pc /usr/lib/pkgconfig/. + cd .. + + # -- install leptonica + sudo apt-get install -y libpng-dev libtiff-dev + wget http://www.leptonica.org/source/leptonica-1.71.tar.gz + tar -zxvf leptonica-1.71.tar.gz + cd leptonica-1.71 + ./configure --disable-programs + make + sudo make install + sudo ldconfig + cd .. -# -- install leptonica - - sudo apt-get install -y libpng-dev libtiff-dev - - wget http://www.leptonica.org/source/leptonica-1.71.tar.gz - - tar -zxvf leptonica-1.71.tar.gz - - cd leptonica-1.71 - - ./configure --disable-programs - - make - - sudo make install - - sudo ldconfig - - cd .. + # -- install libmbus + git clone https://github.com/rscada/libmbus + cd libmbus + ./build.sh + sudo make install + cd .. + sudo apt-get install -y lcov -# -- install libmbus - - git clone https://github.com/rscada/libmbus - - cd libmbus - - ./build.sh - - sudo make install - - cd .. - - sudo apt-get install -y lcov + # -- install libmosquitto-dev + sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y + sudo apt-get update -qq + sudo apt-get install -qq libmosquitto-dev + fi -# -- install libmosquitto-dev - - sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y - - sudo apt-get update -qq - - sudo apt-get install -qq libmosquitto-dev script: - - cmake . -DMETEREXEC_ROOTACCESS=OFF -DENABLE_OCR=ON -DSML_HOME=/usr/local/src/libsml/sml && make && make test + - if [ -n "$BUILD" ]; then cmake . -DMETEREXEC_ROOTACCESS=OFF -DENABLE_OCR=ON -DSML_HOME=/usr/local/src/libsml/sml && make && make test; fi + - | + if [ -n "$FORMAT" ]; then + clang-format -i include/**/*.{h,hpp} src/**/*.cpp tests/**/*.{cpp,hpp} + test -z "$(git status --porcelain)" || (git status; git diff; false) + fi diff --git a/include/ApiIF.hpp b/include/ApiIF.hpp index 01d4bfc8..51e175c0 100644 --- a/include/ApiIF.hpp +++ b/include/ApiIF.hpp @@ -35,30 +35,30 @@ #include -#include #include +#include namespace vz { - class ApiIF { - public: - typedef vz::shared_ptr Ptr; +class ApiIF { + public: + typedef vz::shared_ptr Ptr; - ApiIF(Channel::Ptr ch) : _ch(ch){} - virtual ~ApiIF(){}; + ApiIF(Channel::Ptr ch) : _ch(ch) {} + virtual ~ApiIF(){}; -/** - * @brief send measurement values to middleware - * to be implemented specific API. - **/ - virtual void send() = 0; - virtual void register_device() = 0; - - protected: - Channel::Ptr channel() { return _ch; } + /** + * @brief send measurement values to middleware + * to be implemented specific API. + **/ + virtual void send() = 0; + virtual void register_device() = 0; + + protected: + Channel::Ptr channel() { return _ch; } - private: - Channel::Ptr _ch; /**< pointer to channel where API belongs to */ - }; //class ApiIF + private: + Channel::Ptr _ch; /**< pointer to channel where API belongs to */ +}; // class ApiIF } // namespace vz #endif /* _ApiIF_hpp_ */ diff --git a/include/Buffer.hpp b/include/Buffer.hpp index 415a815d..2c4ed1df 100644 --- a/include/Buffer.hpp +++ b/include/Buffer.hpp @@ -28,15 +28,15 @@ #ifndef _BUFFER_H_ #define _BUFFER_H_ +#include #include #include -#include #include class Buffer { - public: + public: typedef vz::shared_ptr Ptr; typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; @@ -54,45 +54,41 @@ class Buffer { std::string dump(); inline iterator begin() { return _sent.begin(); } - inline iterator end() { return _sent.end(); } - inline size_t size() { lock(); size_t s = _sent.size(); unlock(); return s; } + inline iterator end() { return _sent.end(); } + inline size_t size() { + lock(); + size_t s = _sent.size(); + unlock(); + return s; + } inline bool newValues() const { return _newValues; } inline void clear_newValues() { _newValues = false; } - inline void lock() { pthread_mutex_lock(&_mutex); } + inline void lock() { pthread_mutex_lock(&_mutex); } inline void unlock() { pthread_mutex_unlock(&_mutex); } inline void wait(pthread_cond_t *condition) { pthread_cond_wait(condition, &_mutex); } - inline void have_newValues() { _newValues = true; } + inline void have_newValues() { _newValues = true; } - inline void set_aggmode(Buffer::aggmode m) {_aggmode=m;} + inline void set_aggmode(Buffer::aggmode m) { _aggmode = m; } inline aggmode get_aggmode() const { return _aggmode; } - private: - Buffer(const Buffer &); // don't allow copy constructor - Buffer & operator=(const Buffer &); // and no assignment op. + private: + Buffer(const Buffer &); // don't allow copy constructor + Buffer &operator=(const Buffer &); // and no assignment op. std::list _sent; bool _newValues; Buffer::aggmode _aggmode; - size_t _keep; /**< number of readings to cache for local interface */ + size_t _keep; /**< number of readings to cache for local interface */ pthread_mutex_t _mutex; - Reading *_last_avg; // keeps value and time from last reading from aggregate call for aggmode AVG + Reading + *_last_avg; // keeps value and time from last reading from aggregate call for aggmode AVG }; #endif /* _BUFFER_H_ */ - - -/* - * Local variables: - * tab-width: 2 - * c-indent-level: 2 - * c-basic-offset: 2 - * project-name: vzlogger - * End: - */ diff --git a/include/Channel.hpp b/include/Channel.hpp index 181c777c..3a2ad9b7 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -29,22 +29,23 @@ #include #include -#include "Reading.hpp" #include "Buffer.hpp" -#include +#include "Reading.hpp" #include #include +#include class Channel { - public: + public: typedef vz::shared_ptr Ptr; // This shared_ptr is set when a logging_thread for an object of this class is started. // Inside the logging_thread, a Channel::Ptr is used. Data is passed via the void* // argument of pthread_create, and thus directly passing a shared pointer will break it. Ptr _this_forthread; - Channel(const std::list