Changeset 1130 for cpp/common
- Timestamp:
- 04/16/21 15:55:34 (4 years ago)
- Location:
- cpp/common
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/2d.h
r1028 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 6 6 #define _2D_H_ 7 7 8 #include "nonstd_stl.h"9 8 #include <math.h> 9 #include <algorithm> 10 10 11 11 //unification of old GUIXY and Pt2D … … 58 58 template<> inline bool XY<int>::operator==(const XY<int> &p) const { return (x == p.x) && (y == p.y); } 59 59 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)); }60 template <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)); } 61 template <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)); } 62 62 63 63 template <typename T> … … 74 74 T vertical() const { return top + bottom; } 75 75 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))); } 77 77 }; 78 78 … … 162 162 } 163 163 164 XYRect fitAspect(float aspect) ///< place a new rectangle having 'aspect' inside the rectangle164 XYRect fitAspect(float aspect) const ///< place a new rectangle having 'aspect' inside the rectangle 165 165 { 166 166 XYRect r; … … 179 179 XY<T> p2 = p + size; 180 180 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; 185 185 return i; 186 186 } -
cpp/common/Convert.cpp
r1005 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 5 5 #include "Convert.h" 6 6 #include <sstream> 7 #include <algorithm> 7 8 8 9 #if defined __ANDROID__ || defined __BORLANDC__ -
cpp/common/log.cpp
r875 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #include "Convert.h" 9 9 #include <assert.h> 10 #include <algorithm> 10 11 11 12 const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " }; … … 36 37 { 37 38 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)); 39 40 return LOG_LEVEL_ARRAY[level + 1]; 40 41 } -
cpp/common/loggers/loggers.h
r1100 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #include <common/threads.h> 10 10 #include <common/nonstd_stl.h> 11 #include <algorithm> 11 12 12 13 class LoggerBase; -
cpp/common/loggers/loggertostdout.cpp
r875 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 5 5 #include "loggertostdout.h" 6 6 #include <common/console.h> 7 #include <algorithm> 7 8 #include <assert.h> 8 9 #ifdef SHP … … 38 39 { 39 40 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)); 41 42 printf(log_format, log_level[level + 1], obj, method, msg, "\n"); 42 43 } -
cpp/common/nonstd_stl.h
r1108 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 6 6 #define _NONSTD_STL_H_ 7 7 8 // stl jak sama nazwa glosi wcale nie jest nonstd8 //making STL more standard 9 9 10 10 #include <string> 11 11 using std::string; 12 #ifndef SHP // bada nie mawstring12 #ifndef SHP //STL in the bada OS has no wstring 13 13 using std::wstring; 14 14 #endif … … 17 17 using std::vector; 18 18 19 #include <algorithm> //std::min,max,swap20 using std::min;21 using std::max;22 using std::swap;23 19 20 //below: not used since 2020 (these macros are replaced by std::ssize()), may be removed... 24 21 25 22 // ------------------- ARRAY_LENGTH ------------------- 26 23 27 // staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli"x"24 //old-fashioned macro, unprotected against the use of the pointer as "x" 28 25 //#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) 29 26 30 //ha kerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia27 //hacker macro that detects some of the misuse cases 31 28 //#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 32 29 33 // szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji30 //template function by intermediate-level devs, as a function it unfortunately does not give a constant at compile time 34 31 //template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x 35 32 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... 37 34 //template <typename T, std::size_t N> 38 35 //char (&array_temp(T (&a)[N]))[N]; … … 44 41 //char (&array_temp(const T (&a)[N]))[N]; 45 42 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 bledow43 //...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 47 44 //#define ARRAY_LENGTH(x) sizeof(array_temp(x)) 48 45 49 46 //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) 51 49 52 50 -
cpp/common/util-stl.h
r1124 r1130 6 6 #define _UTIL_STL_H_ 7 7 8 #include "nonstd_stl.h"9 8 #include <map> 9 #include <algorithm> 10 10 11 11 template<typename T, std::size_t N> void push_back(vector<T>& v, T(&d)[N]) -
cpp/common/util-string.cpp
r1036 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #include <assert.h> 10 10 #include <cstdlib> //malloc() 11 #include <algorithm> 11 12 #ifdef USE_VIRTFILE 12 13 #include <common/virtfile/virtfile.h>
Note: See TracChangeset
for help on using the changeset viewer.