Mon, 30 Jun 2014 05:52:10 +0300
- refactor
src/basics.h | file | annotate | diff | comparison | revisions | |
src/dialogs.cc | file | annotate | diff | comparison | revisions | |
src/glRenderer.cc | file | annotate | diff | comparison | revisions | |
src/miscallenous.h | file | annotate | diff | comparison | revisions | |
src/partDownloader.cc | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Sun Jun 29 17:06:21 2014 +0300 +++ b/src/basics.h Mon Jun 30 05:52:10 2014 +0300 @@ -199,3 +199,84 @@ extern const Matrix g_identity; // Identity matrix static const double pi = 3.14159265358979323846; + + +// ============================================================================= +// Plural expression +template<class T> static inline const char* plural (T n) +{ + return (n != 1) ? "s" : ""; +} + +// ============================================================================= +// Templated clamp +template<class T> static inline T clamp (T a, T min, T max) +{ + return (a > max) ? max : (a < min) ? min : a; +} + +// Templated minimum +template<class T> static inline T min (T a, T b) +{ + return (a < b) ? a : b; +} + +// Templated maximum +template<class T> static inline T max (T a, T b) +{ + return (a > b) ? a : b; +} + +// Templated absolute value +template<class T> static inline T abs (T a) +{ + return (a >= 0) ? a : -a; +} + +template<class T> inline bool isZero (T a) +{ + return abs<T> (a) < 0.0001; +} + +template<class T> inline bool isInteger (T a) +{ + return isZero (a - (int) a); +} + +template<class T> void removeDuplicates (QList<T>& a) +{ + std::sort (a.begin(), a.end()); + a.erase (std::unique (a.begin(), a.end()), a.end()); +} + +inline QString utf16 (const char16_t* a) +{ + if (Q_LIKELY (sizeof(char16_t) == sizeof(unsigned short))) + return QString::fromUtf16 (reinterpret_cast<const unsigned short*> (a)); + + QVector<unsigned short> data; + + for (const char16_t* ap = &a[0]; *ap != '\u0000'; ++ap) + data << *ap; + + data << '\u0000'; + return QString::fromUtf16 (data.constData()); +} + +// +// Returns true if first arg is equal to any of the other args +// +template<typename T, typename Arg, typename... Args> +bool eq (T const& a, Arg const& arg, Args const&... args) +{ + if (a == arg) + return true; + + return eq (a, args...); +} + +template<typename T> +bool eq (T const&) +{ + return false; +}
--- a/src/dialogs.cc Sun Jun 29 17:06:21 2014 +0300 +++ b/src/dialogs.cc Mon Jun 30 05:52:10 2014 +0300 @@ -222,7 +222,7 @@ { QString newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); - if (newpath.length() > 0 && newpath != filename()) + if (not newpath.isEmpty()) { setPath (newpath); slot_tryConfigure();
--- a/src/glRenderer.cc Sun Jun 29 17:06:21 2014 +0300 +++ b/src/glRenderer.cc Mon Jun 30 05:52:10 2014 +0300 @@ -484,7 +484,7 @@ void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type) { // Filter this through some configuration options - if (((surface == VBOSF_Quads || surface == VBOSF_Triangles) && cfg::drawSurfaces == false) || + if ((eq (surface, VBOSF_Quads, VBOSF_Triangles) && cfg::drawSurfaces == false) || (surface == VBOSF_Lines && cfg::drawEdgeLines == false) || (surface == VBOSF_CondLines && cfg::drawConditionalLines == false)) {
--- a/src/miscallenous.h Sun Jun 29 17:06:21 2014 +0300 +++ b/src/miscallenous.h Mon Jun 30 05:52:10 2014 +0300 @@ -91,65 +91,3 @@ double snap (double value, const Grid::Config type); } - -// ============================================================================= -// Plural expression -template<class T> static inline const char* plural (T n) -{ - return (n != 1) ? "s" : ""; -} - -// ============================================================================= -// Templated clamp -template<class T> static inline T clamp (T a, T min, T max) -{ - return (a > max) ? max : (a < min) ? min : a; -} - -// Templated minimum -template<class T> static inline T min (T a, T b) -{ - return (a < b) ? a : b; -} - -// Templated maximum -template<class T> static inline T max (T a, T b) -{ - return (a > b) ? a : b; -} - -// Templated absolute value -template<class T> static inline T abs (T a) -{ - return (a >= 0) ? a : -a; -} - -template<class T> inline bool isZero (T a) -{ - return abs<T> (a) < 0.0001; -} - -template<class T> inline bool isInteger (T a) -{ - return isZero (a - (int) a); -} - -template<class T> void removeDuplicates (QList<T>& a) -{ - std::sort (a.begin(), a.end()); - a.erase (std::unique (a.begin(), a.end()), a.end()); -} - -inline QString utf16 (const char16_t* a) -{ - if (Q_LIKELY (sizeof(char16_t) == sizeof(unsigned short))) - return QString::fromUtf16 (reinterpret_cast<const unsigned short*> (a)); - - QVector<unsigned short> data; - - for (const char16_t* ap = &a[0]; *ap != '\u0000'; ++ap) - data << *ap; - - data << '\u0000'; - return QString::fromUtf16 (data.constData()); -}
--- a/src/partDownloader.cc Sun Jun 29 17:06:21 2014 +0300 +++ b/src/partDownloader.cc Mon Jun 30 05:52:10 2014 +0300 @@ -140,11 +140,12 @@ // If the part starts with s\ or s/, then use parts/s/. Same goes with // 48\ and p/48/. - if (dest.left (2) == "s\\" || dest.left (2) == "s/") + if (eq (dest.left (2), "s\\", "s/")) { dest.remove (0, 2); dest.prepend ("parts/s/"); - } elif (dest.left (3) == "48\\" || dest.left (3) == "48/") + } + elif (eq (dest.left (3), "48\\", "48/")) { dest.remove (0, 3); dest.prepend ("p/48/"); @@ -173,7 +174,7 @@ dest.prepend ("parts/s/"); elif (QRegExp (partRegex).exactMatch (dest)) dest.prepend ("parts/"); - elif (dest.left (6) != "parts/" && dest.left (2) != "p/") + elif (not dest.startsWith ("parts/") && not dest.startsWith ("p/")) dest.prepend ("p/"); } @@ -518,7 +519,7 @@ // bool PartDownloadRequest::isFinished() const { - return state() == DLRQ_Finished || state() == DLRQ_Failed; + return eq (state(), DLRQ_Finished, DLRQ_Failed); } // =============================================================================