summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-04-25 21:39:05 +1000
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-09 08:51:12 +0200
commit96b08e181cdefce24ddc25fdbf0648856cbb7b0f (patch)
treebe75ca50495ed67da4cc811b7f784dd294958b80 /include/tools
parent1bb5187a3b83bd0f1005d3f17b81c0f5bfd781d3 (diff)
tools: make MinMax functions easier to read
Change-Id: Ief624d353daf5fb321425b396b22c9e9b56806e9 Reviewed-on: https://gerrit.libreoffice.org/53452 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/helpers.hxx37
1 files changed, 29 insertions, 8 deletions
diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx
index 0a349ea62d1d..da815e13b5e9 100644
--- a/include/tools/helpers.hxx
+++ b/include/tools/helpers.hxx
@@ -22,8 +22,17 @@ typename std::enable_if<
MinMax(T nVal, long nMin, long nMax)
{
assert(nMin <= nMax);
- return nVal >= nMin
- ? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
+ if (nVal >= nMin)
+ {
+ if (nVal <= nMax)
+ return static_cast<long>(nVal);
+ else
+ return nMax;
+ }
+ else
+ {
+ return nMin;
+ }
}
template<typename T>
@@ -33,12 +42,24 @@ typename std::enable_if<
MinMax(T nVal, long nMin, long nMax)
{
assert(nMin <= nMax);
- return nMax < 0
- ? nMax
- : ((nMin < 0 || nVal >= static_cast<unsigned long>(nMin))
- ? (nVal <= static_cast<unsigned long>(nMax)
- ? static_cast<long>(nVal) : nMax)
- : nMin);
+ if (nMax < 0)
+ {
+ return nMax;
+ }
+ else
+ {
+ if (nMin < 0 || nVal >= static_cast<unsigned long>(nMin))
+ {
+ if (nVal <= static_cast<unsigned long>(nMax))
+ return static_cast<long>(nVal);
+ else
+ return nMax;
+ }
+ else
+ {
+ return nMin;
+ }
+ }
}
inline sal_uInt32 AlignedWidth4Bytes(sal_uInt32 nWidthBits)