diff --git a/src/zm_analysis_thread.cpp b/src/zm_analysis_thread.cpp index 1bc4170917..13a2c3f33f 100644 --- a/src/zm_analysis_thread.cpp +++ b/src/zm_analysis_thread.cpp @@ -4,14 +4,11 @@ #include "zm_signal.h" #include "zm_time.h" -AnalysisThread::AnalysisThread(Monitor *monitor) : - monitor_(monitor), terminate_(false) { +AnalysisThread::AnalysisThread(Monitor *monitor) : monitor_(monitor), terminate_(false) { thread_ = std::thread(&AnalysisThread::Run, this); } -AnalysisThread::~AnalysisThread() { - Stop(); -} +AnalysisThread::~AnalysisThread() { Stop(); } void AnalysisThread::Start() { if (thread_.joinable()) thread_.join(); @@ -30,8 +27,10 @@ void AnalysisThread::Run() { // Some periodic updates are required for variable capturing framerate if (!monitor_->Analyse()) { if (!(terminate_ or zm_terminate)) { - // We only sleep when Analyse returns false because it is an error condition and we will spin like mad if it persists. - Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE); + // We only sleep when Analyse returns false because it is an error condition and we will + // spin like mad if it persists. + Microseconds sleep_for = + monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE); Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count())); std::this_thread::sleep_for(sleep_for); } diff --git a/src/zm_box.h b/src/zm_box.h index 12e44cb949..f8d0116b0d 100644 --- a/src/zm_box.h +++ b/src/zm_box.h @@ -1,27 +1,28 @@ // // ZoneMinder Box Class Interfaces, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_BOX_H #define ZM_BOX_H #include "zm_line.h" #include "zm_vector2.h" + #include #include @@ -49,9 +50,7 @@ class Box { } // Get vertices of the box in a counter-clockwise order - std::vector Vertices() const { - return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}}; - } + std::vector Vertices() const { return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}}; } // Get edges of the box in a counter-clockwise order std::vector Edges() const { @@ -77,4 +76,4 @@ class Box { Vector2 size_; }; -#endif // ZM_BOX_H +#endif // ZM_BOX_H diff --git a/src/zm_crypt.h b/src/zm_crypt.h index 4ddc073f7e..f47f038899 100644 --- a/src/zm_crypt.h +++ b/src/zm_crypt.h @@ -1,21 +1,21 @@ // // ZoneMinder General Utility Functions, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_CRYPT_H #define ZM_CRYPT_H @@ -24,6 +24,7 @@ #include "zm_crypto_gnutls.h" #include "zm_crypto_openssl.h" #include "zm_define.h" + #include bool verifyPassword(const char *username, const char *input_password, const char *db_password_hash); @@ -35,21 +36,21 @@ namespace crypto { namespace impl { #if defined(HAVE_LIBGNUTLS) -template +template using Hash = gnutls::GenericHashImpl; #elif defined(HAVE_LIBOPENSSL) -template +template using Hash = openssl::GenericHashImpl; #endif -} -} -} +} // namespace impl +} // namespace crypto +} // namespace zm namespace zm { namespace crypto { using MD5 = impl::Hash; using SHA1 = impl::Hash; -} -} +} // namespace crypto +} // namespace zm -#endif // ZM_CRYPT_H +#endif // ZM_CRYPT_H diff --git a/src/zm_crypto_generics.h b/src/zm_crypto_generics.h index 9661d4b614..e9e4ed444c 100644 --- a/src/zm_crypto_generics.h +++ b/src/zm_crypto_generics.h @@ -20,6 +20,7 @@ #include "zm_define.h" #include "zm_utils.h" + #include #include @@ -27,25 +28,22 @@ namespace zm { namespace crypto { namespace impl { -enum class HashAlgorithms { - kMD5, - kSHA1 -}; +enum class HashAlgorithms { kMD5, kSHA1 }; -template +template struct HashAlgorithm; -template<> +template <> struct HashAlgorithm { static constexpr size_t digest_length = 16; }; -template<> +template <> struct HashAlgorithm { static constexpr size_t digest_length = 20; }; -template +template class GenericHash { public: static constexpr size_t DIGEST_LENGTH = HashAlgorithm::digest_length; @@ -58,8 +56,8 @@ class GenericHash { return hash.GetDigest(); } - template - static Digest GetDigestOf(Ts &&... pack) { + template + static Digest GetDigestOf(Ts &&...pack) { Impl hash; UpdateData(hash, std::forward(pack)...); hash.Finalize(); @@ -75,14 +73,12 @@ class GenericHash { void UpdateData(const char *str) { UpdateData(reinterpret_cast(str), strlen(str)); } - template + template void UpdateData(Container const &c) { UpdateData(zm::data(c), zm::size(c)); } - void Finalize() { - static_cast(*this).DoFinalize(); - } + void Finalize() { static_cast(*this).DoFinalize(); } const Digest &GetDigest() const { return digest_; } @@ -90,19 +86,19 @@ class GenericHash { Digest digest_ = {}; private: - template + template static void UpdateData(Impl &hash, T const &data) { hash.UpdateData(data); } - template - static void UpdateData(Impl &hash, T const &data, TRest &&... rest) { + template + static void UpdateData(Impl &hash, T const &data, TRest &&...rest) { hash.UpdateData(data); UpdateData(hash, std::forward(rest)...); } }; -} -} -} +} // namespace impl +} // namespace crypto +} // namespace zm -#endif //ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_ +#endif // ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_ diff --git a/src/zm_crypto_gnutls.h b/src/zm_crypto_gnutls.h index d2c51f35d7..a47b5e6f52 100644 --- a/src/zm_crypto_gnutls.h +++ b/src/zm_crypto_gnutls.h @@ -22,6 +22,7 @@ #include "zm_crypto_generics.h" #include "zm_utils.h" + #include namespace zm { @@ -29,20 +30,20 @@ namespace crypto { namespace impl { namespace gnutls { -template +template struct HashAlgorithmMapper; -template<> +template <> struct HashAlgorithmMapper { static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_MD5; }; -template<> +template <> struct HashAlgorithmMapper { static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_SHA1; }; -template +template class GenericHashImpl : public GenericHash, Algorithm> { public: GenericHashImpl() { @@ -55,9 +56,7 @@ class GenericHashImpl : public GenericHash, Algorithm ASSERT(res == 0); } - void DoFinalize() { - gnutls_hash_deinit(handle_, digest_.data()); - } + void DoFinalize() { gnutls_hash_deinit(handle_, digest_.data()); } private: gnutls_hash_hd_t handle_ = {}; @@ -65,11 +64,11 @@ class GenericHashImpl : public GenericHash, Algorithm using Base = GenericHash, Algorithm>; using Base::digest_; }; -} -} -} -} +} // namespace gnutls +} // namespace impl +} // namespace crypto +} // namespace zm -#endif // HAVE_LIBGNUTLS +#endif // HAVE_LIBGNUTLS -#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_ +#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_ diff --git a/src/zm_crypto_openssl.h b/src/zm_crypto_openssl.h index 667142531e..aa26f88576 100644 --- a/src/zm_crypto_openssl.h +++ b/src/zm_crypto_openssl.h @@ -22,6 +22,7 @@ #include "zm_crypto_generics.h" #include "zm_utils.h" + #include namespace zm { @@ -31,10 +32,10 @@ namespace openssl { typedef EVP_MD const *(*HashCreator)(); -template +template struct HashAlgorithmMapper; -template<> +template <> struct HashAlgorithmMapper { // TODO: Remove conditional once Jessie and CentOS 7 are deprecated // This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199) @@ -48,7 +49,7 @@ struct HashAlgorithmMapper { #endif }; -template<> +template <> struct HashAlgorithmMapper { // TODO: Remove conditional once Jessie and CentOS 7 are deprecated // This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199) @@ -62,7 +63,7 @@ struct HashAlgorithmMapper { #endif }; -template +template class GenericHashImpl : public GenericHash, Algorithm> { public: GenericHashImpl() { @@ -98,11 +99,11 @@ class GenericHashImpl : public GenericHash, Algorithm using Base = GenericHash, Algorithm>; using Base::digest_; }; -} -} -} -} +} // namespace openssl +} // namespace impl +} // namespace crypto +} // namespace zm -#endif // HAVE_LIBOPENSSL +#endif // HAVE_LIBOPENSSL -#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_ +#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_ diff --git a/src/zm_decoder_thread.cpp b/src/zm_decoder_thread.cpp index 5c10339852..5f5cca5b01 100644 --- a/src/zm_decoder_thread.cpp +++ b/src/zm_decoder_thread.cpp @@ -3,14 +3,11 @@ #include "zm_monitor.h" #include "zm_signal.h" -DecoderThread::DecoderThread(Monitor *monitor) : - monitor_(monitor), terminate_(false) { +DecoderThread::DecoderThread(Monitor *monitor) : monitor_(monitor), terminate_(false) { thread_ = std::thread(&DecoderThread::Run, this); } -DecoderThread::~DecoderThread() { - Stop(); -} +DecoderThread::~DecoderThread() { Stop(); } void DecoderThread::Start() { if (thread_.joinable()) thread_.join(); @@ -29,8 +26,10 @@ void DecoderThread::Run() { while (!(terminate_ or zm_terminate)) { if (!monitor_->Decode()) { if (!(terminate_ or zm_terminate)) { - // We only sleep when Decode returns false because it is an error condition and we will spin like mad if it persists. - Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE); + // We only sleep when Decode returns false because it is an error condition and we will spin + // like mad if it persists. + Microseconds sleep_for = + monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE); Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count())); std::this_thread::sleep_for(sleep_for); } diff --git a/src/zm_define.h b/src/zm_define.h index 2c23ab3b9e..d7c40193b1 100644 --- a/src/zm_define.h +++ b/src/zm_define.h @@ -14,18 +14,19 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ + */ #ifndef ZONEMINDER_SRC_ZM_DEFINE_H_ #define ZONEMINDER_SRC_ZM_DEFINE_H_ // These macros have not been adopted by the C++11 standard. -// However glibc 2.17 (CentOS 7) still depends on them to provide the macros which are guarded by these defines. +// However glibc 2.17 (CentOS 7) still depends on them to provide the macros which are guarded by +// these defines. #if !defined(__STDC_FORMAT_MACROS) -# define __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS #endif #if !defined(__STDC_CONSTANT_MACROS) -# define __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS #endif #include @@ -50,4 +51,4 @@ typedef std::uint8_t uint8; #endif #endif -#endif // ZONEMINDER_SRC_ZM_DEFINE_H_ +#endif // ZONEMINDER_SRC_ZM_DEFINE_H_ diff --git a/src/zm_font.cpp b/src/zm_font.cpp index 7ecaaa6b1c..5f618ba042 100644 --- a/src/zm_font.cpp +++ b/src/zm_font.cpp @@ -26,10 +26,15 @@ constexpr uint8 FontVariant::kMaxNumCodePoints; constexpr uint8 FontVariant::kMaxCharHeight; constexpr uint8 FontVariant::kMaxCharWidth; -FontVariant::FontVariant() : char_height_(0), char_width_(0), char_padding_(0), codepoint_count_(0) {} - -FontVariant::FontVariant(uint16 char_height, uint16 char_width, uint8 char_padding, std::vector bitmap) - : char_height_(char_height), char_width_(char_width), char_padding_(char_padding), bitmap_(std::move(bitmap)) { +FontVariant::FontVariant() + : char_height_(0), char_width_(0), char_padding_(0), codepoint_count_(0) {} + +FontVariant::FontVariant(uint16 char_height, uint16 char_width, uint8 char_padding, + std::vector bitmap) + : char_height_(char_height), + char_width_(char_width), + char_padding_(char_padding), + bitmap_(std::move(bitmap)) { if (char_height_ > kMaxCharHeight) { throw std::invalid_argument("char_height > kMaxCharHeight"); } @@ -66,8 +71,7 @@ std::ifstream &operator>>(std::ifstream &stream, FontFileHeader &header) { stream.read(reinterpret_cast(&header.version), sizeof(header.version)); stream.seekg(sizeof(header.pad), std::ifstream::cur); - for (FontBitmapHeader &bm_header : header.bitmap_header) - stream >> bm_header; + for (FontBitmapHeader &bm_header : header.bitmap_header) stream >> bm_header; return stream; } @@ -94,9 +98,9 @@ FontLoadError ZmFont::LoadFontFile(const std::string &loc) { for (int i = 0; i < kNumFontSizes; i++) { FontBitmapHeader bitmap_header = file_header.bitmap_header[i]; - if (bitmap_header.char_width > FontVariant::kMaxCharWidth - || bitmap_header.char_height > FontVariant::kMaxCharHeight - || bitmap_header.number_of_code_points > FontVariant::kMaxNumCodePoints) { + if (bitmap_header.char_width > FontVariant::kMaxCharWidth || + bitmap_header.char_height > FontVariant::kMaxCharHeight || + bitmap_header.number_of_code_points > FontVariant::kMaxNumCodePoints) { return FontLoadError::kInvalidFile; } @@ -104,10 +108,11 @@ FontLoadError ZmFont::LoadFontFile(const std::string &loc) { bitmap.resize(bitmap_header.number_of_code_points * bitmap_header.char_height); std::size_t bitmap_bytes = bitmap.size() * sizeof(uint64); - font_file.read(reinterpret_cast(bitmap.data()), static_cast(bitmap_bytes)); + font_file.read(reinterpret_cast(bitmap.data()), + static_cast(bitmap_bytes)); - variants_[i] = - {bitmap_header.char_height, bitmap_header.char_width, bitmap_header.char_padding, std::move(bitmap)}; + variants_[i] = {bitmap_header.char_height, bitmap_header.char_width, bitmap_header.char_padding, + std::move(bitmap)}; } if (font_file.fail()) { @@ -117,6 +122,4 @@ FontLoadError ZmFont::LoadFontFile(const std::string &loc) { return FontLoadError::kOk; } -const FontVariant &ZmFont::GetFontVariant(uint8 idx) const { - return variants_.at(idx); -} +const FontVariant &ZmFont::GetFontVariant(uint8 idx) const { return variants_.at(idx); } diff --git a/src/zm_font.h b/src/zm_font.h index e1f03d7d1d..99cce080a1 100644 --- a/src/zm_font.h +++ b/src/zm_font.h @@ -19,33 +19,30 @@ #define ZM_FONT_H #include "zm_define.h" -#include + #include "span.hpp" +#include #include #include constexpr uint8 kNumFontSizes = 4; -enum class FontLoadError { - kOk, - kFileNotFound, - kInvalidFile -}; +enum class FontLoadError { kOk, kFileNotFound, kInvalidFile }; #pragma pack(push, 1) struct FontBitmapHeader { - uint16 char_height; // height of every character - uint16 char_width; // width of every character - uint32 number_of_code_points; // number of codepoints; max. 255 for now - uint32 idx; // offset in data where data for the bitmap starts; not used - uint8 char_padding; // padding around characters - uint8 pad[3]; // struct padding + uint16 char_height; // height of every character + uint16 char_width; // width of every character + uint32 number_of_code_points; // number of codepoints; max. 255 for now + uint32 idx; // offset in data where data for the bitmap starts; not used + uint8 char_padding; // padding around characters + uint8 pad[3]; // struct padding }; #pragma pack(pop) #pragma pack(push, 1) struct FontFileHeader { - char magic[6]; // "ZMFNT\0" + char magic[6]; // "ZMFNT\0" uint8 version; uint8 pad; std::array bitmap_header; @@ -61,7 +58,8 @@ class FontVariant { static constexpr uint8 kMaxCharWidth = 64; FontVariant(); - FontVariant(uint16 char_height, uint16 char_width, uint8 char_padding, std::vector bitmap); + FontVariant(uint16 char_height, uint16 char_width, uint8 char_padding, + std::vector bitmap); uint16 GetCharHeight() const { return char_height_; } uint16 GetCharWidth() const { return char_width_; } diff --git a/src/zm_frame.cpp b/src/zm_frame.cpp index aadd20f8d5..ab431650d1 100644 --- a/src/zm_frame.cpp +++ b/src/zm_frame.cpp @@ -1,12 +1,7 @@ #include "zm_frame.h" -Frame::Frame(event_id_t p_event_id, - int p_frame_id, - FrameType p_type, - SystemTimePoint p_timestamp, - Microseconds p_delta, - int p_score, - std::vector p_stats) +Frame::Frame(event_id_t p_event_id, int p_frame_id, FrameType p_type, SystemTimePoint p_timestamp, + Microseconds p_delta, int p_score, std::vector p_stats) : event_id(p_event_id), frame_id(p_frame_id), type(p_type), diff --git a/src/zm_frame.h b/src/zm_frame.h index 77c7a03983..86fd75e26b 100644 --- a/src/zm_frame.h +++ b/src/zm_frame.h @@ -1,21 +1,21 @@ // // ZoneMinder Frame Class Interfaces, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_FRAME_H #define ZM_FRAME_H @@ -23,27 +23,18 @@ #include "zm_event.h" #include "zm_time.h" #include "zm_zone.h" + #include -enum FrameType { - NORMAL = 0, - BULK, - ALARM -}; +enum FrameType { NORMAL = 0, BULK, ALARM }; // // This describes a frame record // class Frame { public: - Frame(event_id_t p_event_id, - int p_frame_id, - FrameType p_type, - SystemTimePoint p_timestamp, - Microseconds p_delta, - int p_score, - std::vector p_stats - ); + Frame(event_id_t p_event_id, int p_frame_id, FrameType p_type, SystemTimePoint p_timestamp, + Microseconds p_delta, int p_score, std::vector p_stats); event_id_t event_id; int frame_id; @@ -54,4 +45,4 @@ class Frame { std::vector zone_stats; }; -#endif // ZM_FRAME_H +#endif // ZM_FRAME_H diff --git a/src/zm_line.h b/src/zm_line.h index ec09fc48ee..e50eac2ab3 100644 --- a/src/zm_line.h +++ b/src/zm_line.h @@ -34,7 +34,7 @@ class LineSegment { class Line { public: Line(Vector2 p1, Vector2 p2) : position_(p1), direction_(p2 - p1) {} - explicit Line(LineSegment segment) : Line(segment.start_, segment.end_) {}; + explicit Line(LineSegment segment) : Line(segment.start_, segment.end_){}; bool IsPointLeftOfOrColinear(Vector2 p) const { int32 det = direction_.Determinant(p - position_); @@ -61,4 +61,4 @@ class Line { Vector2 direction_; }; -#endif //ZONEMINDER_SRC_ZM_LINE_H_ +#endif // ZONEMINDER_SRC_ZM_LINE_H_ diff --git a/src/zm_poll_thread.cpp b/src/zm_poll_thread.cpp index ee46dbfe5b..9787a3193d 100644 --- a/src/zm_poll_thread.cpp +++ b/src/zm_poll_thread.cpp @@ -4,14 +4,11 @@ #include "zm_signal.h" #include "zm_time.h" -PollThread::PollThread(Monitor *monitor) : - monitor_(monitor), terminate_(false) { +PollThread::PollThread(Monitor *monitor) : monitor_(monitor), terminate_(false) { thread_ = std::thread(&PollThread::Run, this); } -PollThread::~PollThread() { - Stop(); -} +PollThread::~PollThread() { Stop(); } void PollThread::Start() { if (thread_.joinable()) thread_.join(); diff --git a/src/zm_poly.cpp b/src/zm_poly.cpp index 6485bc1923..e79e479bef 100644 --- a/src/zm_poly.cpp +++ b/src/zm_poly.cpp @@ -1,25 +1,26 @@ // // ZoneMinder Polygon Class Implementation, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #include "zm_poly.h" #include "zm_line.h" + #include Polygon::Polygon(std::vector vertices) : vertices_(std::move(vertices)), area(0) { @@ -29,8 +30,7 @@ Polygon::Polygon(std::vector vertices) : vertices_(std::move(vertices)) } void Polygon::UpdateExtent() { - if (vertices_.empty()) - return; + if (vertices_.empty()) return; int min_x = vertices_[0].x_; int max_x = 0; @@ -49,7 +49,8 @@ void Polygon::UpdateExtent() { void Polygon::UpdateArea() { double float_area = 0.0; for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) { - double trap_area = ((vertices_[i].x_ - vertices_[j].x_) * ((vertices_[i].y_ + vertices_[j].y_))) / 2.0; + double trap_area = + ((vertices_[i].x_ - vertices_[j].x_) * ((vertices_[i].y_ + vertices_[j].y_))) / 2.0; float_area += trap_area; } @@ -57,28 +58,33 @@ void Polygon::UpdateArea() { } void Polygon::UpdateCentre() { - if (!area && !vertices_.empty()) - UpdateArea(); + if (!area && !vertices_.empty()) UpdateArea(); double float_x = 0.0; double float_y = 0.0; for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) { - float_x += ((vertices_[i].y_ - vertices_[j].y_) - * ((vertices_[i].x_ * 2) + (vertices_[i].x_ * vertices_[j].x_) + (vertices_[j].x_ * 2))); - float_y += ((vertices_[j].x_ - vertices_[i].x_) - * ((vertices_[i].y_ * 2) + (vertices_[i].y_ * vertices_[j].y_) + (vertices_[j].y_ * 2))); + float_x += + ((vertices_[i].y_ - vertices_[j].y_) * + ((vertices_[i].x_ * 2) + (vertices_[i].x_ * vertices_[j].x_) + (vertices_[j].x_ * 2))); + float_y += + ((vertices_[j].x_ - vertices_[i].x_) * + ((vertices_[i].y_ * 2) + (vertices_[i].y_ * vertices_[j].y_) + (vertices_[j].y_ * 2))); } float_x /= (6 * area); float_y /= (6 * area); - centre = Vector2(static_cast(std::lround(float_x)), static_cast(std::lround(float_y))); + centre = + Vector2(static_cast(std::lround(float_x)), static_cast(std::lround(float_y))); } bool Polygon::Contains(const Vector2 &coord) const { bool inside = false; for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) { - if ((((vertices_[i].y_ <= coord.y_) && (coord.y_ < vertices_[j].y_)) || ((vertices_[j].y_ <= coord.y_) && (coord.y_ < vertices_[i].y_))) - && (coord.x_ < (vertices_[j].x_ - vertices_[i].x_) * (coord.y_ - vertices_[i].y_) / (vertices_[j].y_ - vertices_[i].y_) + vertices_[i].x_)) { + if ((((vertices_[i].y_ <= coord.y_) && (coord.y_ < vertices_[j].y_)) || + ((vertices_[j].y_ <= coord.y_) && (coord.y_ < vertices_[i].y_))) && + (coord.x_ < (vertices_[j].x_ - vertices_[i].x_) * (coord.y_ - vertices_[i].y_) / + (vertices_[j].y_ - vertices_[i].y_) + + vertices_[i].x_)) { inside = !inside; } } diff --git a/src/zm_poly.h b/src/zm_poly.h index c25033262f..785360cd76 100644 --- a/src/zm_poly.h +++ b/src/zm_poly.h @@ -1,26 +1,27 @@ // // ZoneMinder Polygon Class Interfaces, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_POLY_H #define ZM_POLY_H #include "zm_box.h" + #include // This class represents convex or concave non-self-intersecting polygons. @@ -29,9 +30,7 @@ class Polygon { Polygon() : area(0) {} explicit Polygon(std::vector vertices); - const std::vector &GetVertices() const { - return vertices_; - } + const std::vector &GetVertices() const { return vertices_; } const Box &Extent() const { return extent; } int32 Area() const { return area; } @@ -53,4 +52,4 @@ class Polygon { Vector2 centre; }; -#endif // ZM_POLY_H +#endif // ZM_POLY_H diff --git a/src/zm_time.cpp b/src/zm_time.cpp index 828e7b0f39..3060560a13 100644 --- a/src/zm_time.cpp +++ b/src/zm_time.cpp @@ -1,21 +1,21 @@ // // ZoneMinder Time Functions & Definitions, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #include "zm_time.h" @@ -31,14 +31,15 @@ std::string SystemTimePointToString(SystemTimePoint tp) { char *timePtr = &*(timeString.begin()); tm tp_tm = {}; timePtr += strftime(timePtr, timeString.capacity(), "%x %H:%M:%S", localtime_r(&tp_sec, &tp_tm)); - snprintf(timePtr, timeString.capacity() - (timePtr - timeString.data()), ".%06" PRIi64, static_cast(now_frac.count())); + snprintf(timePtr, timeString.capacity() - (timePtr - timeString.data()), ".%06" PRIi64, + static_cast(now_frac.count())); return timeString; } std::string TimePointToString(TimePoint tp) { - const auto tp_dur = std::chrono::duration_cast(tp - std::chrono::steady_clock::now()); - time_t tp_sec = std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now() + tp_dur); + const auto tp_dur = std::chrono::duration_cast( + tp - std::chrono::steady_clock::now()); + time_t tp_sec = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now() + tp_dur); Microseconds now_frac = std::chrono::duration_cast( tp.time_since_epoch() - std::chrono::duration_cast(tp.time_since_epoch())); @@ -48,6 +49,7 @@ std::string TimePointToString(TimePoint tp) { char *timePtr = &*(timeString.begin()); tm tp_tm = {}; timePtr += strftime(timePtr, timeString.capacity(), "%x %H:%M:%S", localtime_r(&tp_sec, &tp_tm)); - snprintf(timePtr, timeString.capacity() - (timePtr - timeString.data()), ".%06" PRIi64, static_cast(now_frac.count())); + snprintf(timePtr, timeString.capacity() - (timePtr - timeString.data()), ".%06" PRIi64, + static_cast(now_frac.count())); return timeString; } diff --git a/src/zm_time.h b/src/zm_time.h index d9d1319441..c0fa892fc1 100644 --- a/src/zm_time.h +++ b/src/zm_time.h @@ -1,28 +1,29 @@ // // ZoneMinder Time Functions & Definitions, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_TIME_H #define ZM_TIME_H +#include + #include #include -#include typedef std::chrono::microseconds Microseconds; typedef std::chrono::milliseconds Milliseconds; @@ -40,11 +41,11 @@ namespace zm { namespace chrono { namespace impl { -template +template struct posix_duration_cast; // chrono -> timeval caster -template +template struct posix_duration_cast, timeval> { static timeval cast(std::chrono::duration const &d) { timeval tv = {}; @@ -59,30 +60,29 @@ struct posix_duration_cast, timeval> { }; // timeval -> chrono caster -template +template struct posix_duration_cast> { static std::chrono::duration cast(timeval const &tv) { - return std::chrono::duration_cast>( - Seconds(tv.tv_sec) + Microseconds(tv.tv_usec) - ); + return std::chrono::duration_cast>(Seconds(tv.tv_sec) + + Microseconds(tv.tv_usec)); } }; -} +} // namespace impl // chrono -> timeval -template -auto duration_cast(std::chrono::duration const &d) --> typename std::enable_if::value, timeval>::type { +template +auto duration_cast(std::chrono::duration const &d) -> + typename std::enable_if::value, timeval>::type { return impl::posix_duration_cast, timeval>::cast(d); } // timeval -> chrono -template +template Duration duration_cast(timeval const &tv) { return impl::posix_duration_cast::cast(tv); } -} -} +} // namespace chrono +} // namespace zm // // This can be used for benchmarking. It will measure the time in between @@ -91,15 +91,10 @@ Duration duration_cast(timeval const &tv) { // class TimeSegmentAdder { public: - explicit TimeSegmentAdder(Microseconds &in_target) : - target_(in_target), - start_time_(std::chrono::steady_clock::now()), - finished_(false) { - } + explicit TimeSegmentAdder(Microseconds &in_target) + : target_(in_target), start_time_(std::chrono::steady_clock::now()), finished_(false) {} - ~TimeSegmentAdder() { - Finish(); - } + ~TimeSegmentAdder() { Finish(); } // Call this to stop the timer and add the timed duration to `target`. void Finish() { @@ -124,4 +119,4 @@ class TimeSegmentAdder { std::string SystemTimePointToString(SystemTimePoint tp); std::string TimePointToString(TimePoint tp); -#endif // ZM_TIME_H +#endif // ZM_TIME_H diff --git a/src/zm_vector2.h b/src/zm_vector2.h index c7630ad362..0f4b090b54 100644 --- a/src/zm_vector2.h +++ b/src/zm_vector2.h @@ -1,26 +1,27 @@ // // ZoneMinder Coordinate Class Interface, $Date$, $Revision$ // Copyright (C) 2001-2008 Philip Coombes -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_VECTOR2_H #define ZM_VECTOR2_H #include "zm_define.h" + #include #include @@ -33,25 +34,23 @@ class Vector2 { Vector2(int32 x, int32 y) : x_(x), y_(y) {} static Vector2 Inf() { - static const Vector2 inf = {std::numeric_limits::max(), std::numeric_limits::max()}; + static const Vector2 inf = {std::numeric_limits::max(), + std::numeric_limits::max()}; return inf; } bool operator==(const Vector2 &rhs) const { return (x_ == rhs.x_ && y_ == rhs.y_); } bool operator!=(const Vector2 &rhs) const { return (x_ != rhs.x_ || y_ != rhs.y_); } - // These operators are not idiomatic. If lexicographic comparison is needed, it should be implemented separately. + // These operators are not idiomatic. If lexicographic comparison is needed, it should be + // implemented separately. bool operator>(const Vector2 &rhs) const = delete; bool operator>=(const Vector2 &rhs) const = delete; bool operator<(const Vector2 &rhs) const = delete; bool operator<=(const Vector2 &rhs) const = delete; - Vector2 operator+(const Vector2 &rhs) const { - return {x_ + rhs.x_, y_ + rhs.y_}; - } - Vector2 operator-(const Vector2 &rhs) const { - return {x_ - rhs.x_, y_ - rhs.y_}; - } + Vector2 operator+(const Vector2 &rhs) const { return {x_ + rhs.x_, y_ + rhs.y_}; } + Vector2 operator-(const Vector2 &rhs) const { return {x_ - rhs.x_, y_ - rhs.y_}; } Vector2 operator*(double rhs) const { return {static_cast(std::lround(x_ * rhs)), static_cast(std::lround(y_ * rhs))}; } @@ -68,13 +67,11 @@ class Vector2 { } // Calculated the determinant of the 2x2 matrix as given by [[x_, y_], [v.x_y, v.y_]] - int32 Determinant(Vector2 const &v) const { - return (x_ * v.y_) - (y_ * v.x_); - } + int32 Determinant(Vector2 const &v) const { return (x_ * v.y_) - (y_ * v.x_); } public: int32 x_; int32 y_; }; -#endif // ZM_VECTOR2_H +#endif // ZM_VECTOR2_H diff --git a/src/zm_zone_stats.h b/src/zm_zone_stats.h index 6243f53b61..8ee5f44c32 100644 --- a/src/zm_zone_stats.h +++ b/src/zm_zone_stats.h @@ -1,21 +1,21 @@ // // ZoneMinder Zone Stats Class Interfaces, $Date$, $Revision$ // Copyright (C) 2021 Isaac Connor -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// +// #ifndef ZM_ZONE_STATS_H #define ZM_ZONE_STATS_H @@ -26,16 +26,16 @@ class ZoneStats { public: - explicit ZoneStats(int zone_id) : - zone_id_(zone_id), - pixel_diff_(0), - alarm_pixels_(0), - alarm_filter_pixels_(0), - alarm_blob_pixels_(0), - alarm_blobs_(0), - min_blob_size_(0), - max_blob_size_(0), - score_(0) {}; + explicit ZoneStats(int zone_id) + : zone_id_(zone_id), + pixel_diff_(0), + alarm_pixels_(0), + alarm_filter_pixels_(0), + alarm_blob_pixels_(0), + alarm_blobs_(0), + min_blob_size_(0), + max_blob_size_(0), + score_(0){}; void Reset() { pixel_diff_ = 0; @@ -52,24 +52,12 @@ class ZoneStats { void DumpToLog(const char *prefix) const { Debug(1, - "ZoneStat: %s zone_id: %d pixel_diff=%d alarm_pixels=%d alarm_filter_pixels=%d alarm_blob_pixels=%d alarm_blobs=%d min_blob_size=%d max_blob_size=%d alarm_box=(%d,%d=>%d,%d) alarm_center=(%d,%d) score=%d", - prefix, - zone_id_, - pixel_diff_, - alarm_pixels_, - alarm_filter_pixels_, - alarm_blob_pixels_, - alarm_blobs_, - min_blob_size_, - max_blob_size_, - alarm_box_.Lo().x_, - alarm_box_.Lo().y_, - alarm_box_.Hi().x_, - alarm_box_.Hi().y_, - alarm_centre_.x_, - alarm_centre_.y_, - score_ - ); + "ZoneStat: %s zone_id: %d pixel_diff=%d alarm_pixels=%d alarm_filter_pixels=%d " + "alarm_blob_pixels=%d alarm_blobs=%d min_blob_size=%d max_blob_size=%d " + "alarm_box=(%d,%d=>%d,%d) alarm_center=(%d,%d) score=%d", + prefix, zone_id_, pixel_diff_, alarm_pixels_, alarm_filter_pixels_, alarm_blob_pixels_, + alarm_blobs_, min_blob_size_, max_blob_size_, alarm_box_.Lo().x_, alarm_box_.Lo().y_, + alarm_box_.Hi().x_, alarm_box_.Hi().y_, alarm_centre_.x_, alarm_centre_.y_, score_); } public: @@ -86,4 +74,4 @@ class ZoneStats { unsigned int score_; }; -#endif // ZM_ZONE_STATS_H +#endif // ZM_ZONE_STATS_H