Changeset 1130 for cpp/common


Ignore:
Timestamp:
04/16/21 15:55:34 (3 years ago)
Author:
Maciej Komosinski
Message:

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

Location:
cpp/common
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/2d.h

    r1028 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#define _2D_H_
    77
    8 #include "nonstd_stl.h"
    98#include <math.h>
     9#include <algorithm>
    1010
    1111//unification of old GUIXY and Pt2D
     
    5858template<> inline bool XY<int>::operator==(const XY<int> &p) const { return (x == p.x) && (y == p.y); }
    5959
    60 template <typename T> XY<T> xymin(const XY<T> &a, const XY<T> &b) { return XY<T>(min(a.x, b.x), min(a.y, b.y)); }
    61 template <typename T> XY<T> xymax(const XY<T> &a, const XY<T> &b) { return XY<T>(max(a.x, b.x), max(a.y, b.y)); }
     60template <typename T> XY<T> xymin(const XY<T> &a, const XY<T> &b) { return XY<T>(std::min(a.x, b.x), std::min(a.y, b.y)); }
     61template <typename T> XY<T> xymax(const XY<T> &a, const XY<T> &b) { return XY<T>(std::max(a.x, b.x), std::max(a.y, b.y)); }
    6262
    6363template <typename T>
     
    7474        T vertical() const { return top + bottom; }
    7575        bool operator==(const XYMargin &other) const { return left == other.left && top == other.top && right == other.right && bottom == other.bottom; }
    76         XYMargin normalized() const { return XYMargin(max(left, T(0)), max(top, T(0)), max(right, T(0)), max(bottom, T(0))); }
     76        XYMargin normalized() const { return XYMargin(std::max(left, T(0)), std::max(top, T(0)), std::max(right, T(0)), std::max(bottom, T(0))); }
    7777};
    7878
     
    162162        }
    163163
    164         XYRect fitAspect(float aspect) ///< place a new rectangle having 'aspect' inside the rectangle
     164        XYRect fitAspect(float aspect) const ///< place a new rectangle having 'aspect' inside the rectangle
    165165        {
    166166                XYRect r;
     
    179179                XY<T> p2 = p + size;
    180180                XY<T> rp2 = r.p + r.size;
    181                 i.p.x = max(p.x, r.p.x);
    182                 i.p.y = max(p.y, r.p.y);
    183                 i.size.x = min(p2.x, rp2.x) - i.p.x;
    184                 i.size.y = min(p2.y, rp2.y) - i.p.y;
     181                i.p.x = std::max(p.x, r.p.x);
     182                i.p.y = std::max(p.y, r.p.y);
     183                i.size.x = std::min(p2.x, rp2.x) - i.p.x;
     184                i.size.y = std::min(p2.y, rp2.y) - i.p.y;
    185185                return i;
    186186        }
  • cpp/common/Convert.cpp

    r1005 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "Convert.h"
    66#include <sstream>
     7#include <algorithm>
    78
    89#if defined __ANDROID__ || defined __BORLANDC__
  • cpp/common/log.cpp

    r875 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    88#include "Convert.h"
    99#include <assert.h>
     10#include <algorithm>
    1011
    1112const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " };
     
    3637{
    3738        assert((level>=LOG_MIN) && (level<=LOG_MAX));
    38         level = min(LOG_MAX, max(LOG_MIN, level));
     39        level = std::min(LOG_MAX, std::max(LOG_MIN, level));
    3940        return LOG_LEVEL_ARRAY[level + 1];
    4041}
  • cpp/common/loggers/loggers.h

    r1100 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include <common/threads.h>
    1010#include <common/nonstd_stl.h>
     11#include <algorithm>
    1112
    1213class LoggerBase;
  • cpp/common/loggers/loggertostdout.cpp

    r875 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "loggertostdout.h"
    66#include <common/console.h>
     7#include <algorithm>
    78#include <assert.h>
    89#ifdef SHP
     
    3839        {
    3940                assert((level>=LOG_MIN) && (level<=LOG_MAX));
    40                 level = min(LOG_MAX, max(LOG_MIN, level));
     41                level = std::min(LOG_MAX, std::max(LOG_MIN, level));
    4142                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
    4243        }
  • cpp/common/nonstd_stl.h

    r1108 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#define _NONSTD_STL_H_
    77
    8 //stl jak sama nazwa glosi wcale nie jest nonstd
     8//making STL more standard
    99
    1010#include <string>
    1111using std::string;
    12 #ifndef SHP //bada nie ma wstring
     12#ifndef SHP //STL in the bada OS has no wstring
    1313using std::wstring;
    1414#endif
     
    1717using std::vector;
    1818
    19 #include <algorithm> //std::min,max,swap
    20 using std::min;
    21 using std::max;
    22 using std::swap;
    2319
     20//below: not used since 2020 (these macros are replaced by std::ssize()), may be removed...
    2421
    2522// ------------------- ARRAY_LENGTH -------------------
    2623
    27 //staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli "x"
     24//old-fashioned macro, unprotected against the use of the pointer as "x"
    2825//#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))
    2926
    30 //hakerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia
     27//hacker macro that detects some of the misuse cases
    3128//#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
    3229
    33 //szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji
     30//template function by intermediate-level devs, as a function it unfortunately does not give a constant at compile time
    3431//template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x
    3532
    36 //szablony hakerskie: tablica bajtow o dlugosci N - tak dluga jak tablica o któr¹ pytamy...
     33//hacker templates: array of bytes of length N - as long as the array we are asking for...
    3734//template <typename T, std::size_t N>
    3835//char (&array_temp(T (&a)[N]))[N];
     
    4441//char (&array_temp(const T (&a)[N]))[N];
    4542
    46 //...ktor¹ mozna potem uzyc normalnie w sizeof i dzieki temu mamy const w compile-time. tak uzyteczne jak staromodne makro ale z pelna kontrola bledow
     43//...which can then be used in sizeof and thus we have const in compile-time. This is as useful as the old-fashioned macro above, but with full error control
    4744//#define ARRAY_LENGTH(x) sizeof(array_temp(x))
    4845
    4946//final and no longer needed version ;-) (c++17)
    50 #define ARRAY_LENGTH(x) int(std::size(x))
     47//#define ARRAY_LENGTH(x) int(std::size(x))
     48//(still room for improvement because unsigned=risky, ssize() upcoming since C++20)
    5149
    5250
  • cpp/common/util-stl.h

    r1124 r1130  
    66#define _UTIL_STL_H_
    77
    8 #include "nonstd_stl.h"
    98#include <map>
     9#include <algorithm>
    1010
    1111template<typename T, std::size_t N> void push_back(vector<T>& v, T(&d)[N])
  • cpp/common/util-string.cpp

    r1036 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include <assert.h>
    1010#include <cstdlib> //malloc()
     11#include <algorithm>
    1112#ifdef USE_VIRTFILE
    1213#include <common/virtfile/virtfile.h>
Note: See TracChangeset for help on using the changeset viewer.