From e87f6ec1d313b6613dc474eec8437eb0efada6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Pr=C3=A4ntare?= Date: Wed, 6 Apr 2022 18:54:28 +0200 Subject: [PATCH] Apply formatting --- src/libprojectM/Common.hpp | 156 +++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 75 deletions(-) diff --git a/src/libprojectM/Common.hpp b/src/libprojectM/Common.hpp index 4527d25be..ac3a79ec3 100755 --- a/src/libprojectM/Common.hpp +++ b/src/libprojectM/Common.hpp @@ -26,22 +26,22 @@ #ifndef COMMON_HPP #define COMMON_HPP -#include -#include -#include #include +#include #include +#include +#include #ifdef _MSC_VER #define strcasecmp(s, t) _strcmpi(s, t) #endif -#if defined(_MSC_VER ) && !defined(EYETUNE_WINRT) - #pragma warning( disable : 4244 4305 4996; once : 4018 ) - #define WIN32_LEAN_AND_MEAN - #define NOMINMAX - #include - typedef unsigned int uint; +#if defined(_MSC_VER) && !defined(EYETUNE_WINRT) +#pragma warning(disable : 4244 4305 4996; once : 4018) +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +typedef unsigned int uint; #endif #ifdef DEBUG @@ -50,14 +50,14 @@ #ifdef __APPLE__ #include -extern FILE *fmemopen(void *buf, size_t len, const char *pMode); +extern FILE* fmemopen(void* buf, size_t len, const char* pMode); #endif /** MACOS */ #define DEFAULT_FONT_PATH "/home/carm/fonts/courier1.glf" #define MAX_TOKEN_SIZE 512 #define MAX_PATH_SIZE 4096 -#define STRING_BUFFER_SIZE 1024*150 +#define STRING_BUFFER_SIZE 1024 * 150 #define STRING_LINE_SIZE 1024 @@ -66,11 +66,11 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #endif #ifdef WIN32 -#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y)) +#define projectM_fmax(x, y) ((x) >= (y) ? (x) : (y)) #endif #ifdef __APPLE__ -#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y)) +#define projectM_fmax(x, y) ((x) >= (y) ? (x) : (y)) #endif #ifdef __unix__ @@ -78,11 +78,11 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #endif #ifdef WIN32 -#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y)) +#define projectM_fmin(x, y) ((x) <= (y) ? (x) : (y)) #endif #ifdef __APPLE__ -#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y)) +#define projectM_fmin(x, y) ((x) <= (y) ? (x) : (y)) #endif #ifndef TRUE @@ -94,10 +94,10 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #endif -#define MAX_DOUBLE_SIZE 10000000.0 +#define MAX_DOUBLE_SIZE 10000000.0 #define MIN_DOUBLE_SIZE -10000000.0 -#define MAX_INT_SIZE 10000000 +#define MAX_INT_SIZE 10000000 #define MIN_INT_SIZE -10000000 /* default float initial value */ @@ -117,124 +117,130 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #else #define PATH_SEPARATOR UNIX_PATH_SEPARATOR #endif /** WIN32 */ -#include #include +#include const unsigned int NUM_Q_VARIABLES(32); const std::string PROJECTM_FILE_EXTENSION("prjm"); const std::string MILKDROP_FILE_EXTENSION("milk"); const std::string PROJECTM_MODULE_EXTENSION("so"); - template - void traverse(Container & container) - { +template +void traverse(Container& container) +{ TraverseFunctor functor; for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos) { - assert(pos->second); - functor(pos->second); + assert(pos->second); + functor(pos->second); } - - } +} - template - void traverseVector(Container & container) - { +template +void traverseVector(Container& container) +{ TraverseFunctor functor; for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos) { - assert(*pos); - functor(*pos); + assert(*pos); + functor(*pos); } +} - } - - template - void traverse(Container & container, TraverseFunctor & functor) - { +template +void traverse(Container& container, TraverseFunctor& functor) +{ for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos) { - assert(pos->second); - functor(pos->second); + assert(pos->second); + functor(pos->second); } +} - } +namespace TraverseFunctors { +template +class Delete +{ - namespace TraverseFunctors - { - template - class Delete +public: + void operator()(Data* data) { - - public: - - void operator() (Data * data) - { assert(data); - delete(data); - } - - }; - } + delete (data); + } +}; +}// namespace TraverseFunctors -inline std::string parseExtension(const std::string & filename) { +inline std::string parseExtension(const std::string& filename) +{ const std::size_t start = filename.find_last_of('.'); - if (start == std::string::npos || start >= (filename.length()-1)) + if (start == std::string::npos || start >= (filename.length() - 1)) return ""; - std::string ext = filename.substr(start+1, filename.length()); + std::string ext = filename.substr(start + 1, filename.length()); std::transform(ext.begin(), ext.end(), ext.begin(), tolower); return ext; } -inline std::string parseFilename(const std::string & filename) { +inline std::string parseFilename(const std::string& filename) +{ const std::size_t start = filename.find_last_of('/'); - if (start == std::string::npos || start >= (filename.length()-1)) + if (start == std::string::npos || start >= (filename.length() - 1)) return ""; else - return filename.substr(start+1, filename.length()); + return filename.substr(start + 1, filename.length()); } -inline double meanSquaredError(const double & x, const double & y) { - return (x-y)*(x-y); +inline double meanSquaredError(const double& x, const double& y) +{ + return (x - y) * (x - y); } -template +template struct caseInsensitiveEqual { - caseInsensitiveEqual(const std::locale &loc) : loc_(loc) {} - bool operator()(charT ch1, charT ch2) { return std::toupper(ch1, loc_) == std::toupper(ch2, loc_); } + caseInsensitiveEqual(const std::locale& loc) + : loc_(loc) + { + } + bool operator()(charT ch1, charT ch2) + { + return std::toupper(ch1, loc_) == std::toupper(ch2, loc_); + } private: - const std::locale &loc_; + const std::locale& loc_; }; -template -int caseInsensitiveSubstringFind(const T &haystack, const T &needle, const std::locale &loc = std::locale()) { +template +int caseInsensitiveSubstringFind(const T& haystack, const T& needle, const std::locale& loc = std::locale()) +{ typename T::const_iterator it = std::search( - haystack.begin(), haystack.end(), - needle.begin(), needle.end(), + haystack.begin(), haystack.end(), + needle.begin(), needle.end(), caseInsensitiveEqual(loc)); - if (it != haystack.end()) return it - haystack.begin(); + if (it != haystack.end()) + return it - haystack.begin(); return std::string::npos; } -enum PresetRatingType { - FIRST_RATING_TYPE = 0, - HARD_CUT_RATING_TYPE = FIRST_RATING_TYPE, - SOFT_CUT_RATING_TYPE, - LAST_RATING_TYPE = SOFT_CUT_RATING_TYPE, - TOTAL_RATING_TYPES = SOFT_CUT_RATING_TYPE+1 +enum PresetRatingType +{ + FIRST_RATING_TYPE = 0, + HARD_CUT_RATING_TYPE = FIRST_RATING_TYPE, + SOFT_CUT_RATING_TYPE, + LAST_RATING_TYPE = SOFT_CUT_RATING_TYPE, + TOTAL_RATING_TYPES = SOFT_CUT_RATING_TYPE + 1 };