Merge branch 'master' into jgrpp

# Conflicts:
#	src/core/sort_func.hpp
#	src/rail_cmd.cpp
#	src/timetable_cmd.cpp
#	src/video/sdl_v.cpp
#	src/video/win32_v.cpp
This commit is contained in:
Jonathan G Rennison
2019-04-23 08:11:52 +01:00
44 changed files with 210 additions and 285 deletions

View File

@@ -13,17 +13,17 @@
#define ENUM_TYPE_HPP
/** Some enums need to have allowed incrementing (i.e. StationClassID) */
#define DECLARE_POSTFIX_INCREMENT(type) \
inline type operator ++(type& e, int) \
#define DECLARE_POSTFIX_INCREMENT(enum_type) \
inline enum_type operator ++(enum_type& e, int) \
{ \
type e_org = e; \
e = (type)((int)e + 1); \
enum_type e_org = e; \
e = (enum_type)((std::underlying_type<enum_type>::type)e + 1); \
return e_org; \
} \
inline type operator --(type& e, int) \
inline enum_type operator --(enum_type& e, int) \
{ \
type e_org = e; \
e = (type)((int)e - 1); \
enum_type e_org = e; \
e = (enum_type)((std::underlying_type<enum_type>::type)e - 1); \
return e_org; \
}
@@ -31,13 +31,13 @@
/** Operators to allow to work with enum as with type safe bit set in C++ */
# define DECLARE_ENUM_AS_BIT_SET(mask_t) \
inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \
inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \
inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 | m2);} \
inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 & m2);} \
inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 ^ m2);} \
inline mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
inline mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
inline mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
inline mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
inline mask_t operator ~(mask_t m) {return (mask_t)(~(std::underlying_type<mask_t>::type)m);}
/**

View File

@@ -29,6 +29,20 @@ struct Point {
struct Dimension {
uint width;
uint height;
Dimension(uint w = 0, uint h = 0) : width(w), height(h) {};
bool operator< (const Dimension &other) const
{
int x = (*this).width - other.width;
if (x != 0) return x < 0;
return (*this).height < other.height;
}
bool operator== (const Dimension &other) const
{
return (*this).width == other.width && (*this).height == other.height;
}
};
/** Specification of a rectangle with absolute coordinates of all edges */

View File

@@ -13,7 +13,6 @@
#define SMALLMAP_TYPE_HPP
#include "smallvec_type.hpp"
#include "sort_func.hpp"
/**
* Simple pair of data. Both types have to be POD ("Plain Old Data")!

View File

@@ -1,37 +0,0 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file sort_func.hpp Functions related to sorting operations. */
#ifndef SORT_FUNC_HPP
#define SORT_FUNC_HPP
#include "mem_func.hpp"
/**
* Type safe qsort()
*
* @note Use this sort for irregular sorted data.
*
* @param base Pointer to the first element of the array to be sorted.
* @param num Number of elements in the array pointed by base.
* @param comparator Function that compares two elements.
* @param desc Sort descending.
*/
template <typename T>
static inline void QSortT(T *base, size_t num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
{
if (num < 2) return;
qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator);
if (desc) MemReverseT(base, num);
}
#endif /* SORT_FUNC_HPP */