Codechange: rename smallvec_type to container_func and use only when needed

This commit is contained in:
Rubidium 2023-05-18 11:20:35 +02:00 committed by rubidium42
parent 80d8c01814
commit 3323402aaa
46 changed files with 45 additions and 43 deletions

View File

@ -8,7 +8,7 @@
/** @file animated_tile.cpp Everything related to animated tiles. */
#include "stdafx.h"
#include "core/smallvec_type.hpp"
#include "core/container_func.hpp"
#include "tile_cmd.h"
#include "viewport_func.h"
#include "framerate_type.h"

View File

@ -23,7 +23,7 @@ add_files(
random_func.cpp
random_func.hpp
smallstack_type.hpp
smallvec_type.hpp
container_func.hpp
span_type.hpp
strong_typedef_type.hpp
)

View File

@ -5,46 +5,45 @@
* 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 smallvec_type.hpp Simple vector class that allows allocating an item without the need to copy this->data needlessly. */
/** @file container_func.hpp Some simple functions to help with accessing containers. */
#ifndef SMALLVEC_TYPE_HPP
#define SMALLVEC_TYPE_HPP
#include "mem_func.hpp"
#ifndef CONTAINER_FUNC_HPP
#define CONTAINER_FUNC_HPP
/**
* Helper function to append an item to a vector if it is not already contained
* Consider using std::set, std::unordered_set or std::flat_set in new code
* Helper function to append an item to a container if it is not already contained.
* The container must have a \c emplace_back function.
* Consider using std::set, std::unordered_set or std::flat_set in new code.
*
* @param vec A reference to the vector to be extended
* @param container A reference to the container to be extended
* @param item Reference to the item to be copy-constructed if not found
*
* @return Whether the item was already present
*/
template <typename T>
inline bool include(std::vector<T>& vec, const T &item)
template <typename Container>
inline bool include(Container &container, typename Container::const_reference &item)
{
const bool is_member = std::find(vec.begin(), vec.end(), item) != vec.end();
if (!is_member) vec.emplace_back(item);
const bool is_member = std::find(container.begin(), container.end(), item) != container.end();
if (!is_member) container.emplace_back(item);
return is_member;
}
/**
* Helper function to get the index of an item
* Consider using std::set, std::unordered_set or std::flat_set in new code
* Consider using std::set, std::unordered_set or std::flat_set in new code.
*
* @param vec A reference to the vector to be extended
* @param container A reference to the container to be searched.
* @param item Reference to the item to be search for
*
* @return Index of element if found, otherwise -1
*/
template <typename T>
int find_index(std::vector<T> const& vec, T const& item)
template <typename Container>
int find_index(Container const &container, typename Container::const_reference item)
{
auto const it = std::find(vec.begin(), vec.end(), item);
if (it != vec.end()) return it - vec.begin();
auto const it = std::find(container.begin(), container.end(), item);
if (it != container.end()) return std::distance(container.begin(), it);
return -1;
}
#endif /* SMALLVEC_TYPE_HPP */
#endif /* CONTAINER_FUNC_HPP */

View File

@ -10,7 +10,6 @@
#ifndef POOL_TYPE_HPP
#define POOL_TYPE_HPP
#include "smallvec_type.hpp"
#include "enum_type.hpp"
/** Various types of a pool. */

View File

@ -10,7 +10,6 @@
#ifndef SMALLSTACK_TYPE_HPP
#define SMALLSTACK_TYPE_HPP
#include "smallvec_type.hpp"
#include <mutex>
/**

View File

@ -41,6 +41,7 @@
#include "economy_base.h"
#include "core/pool_func.hpp"
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "cargo_type.h"
#include "water.h"
#include "game/game.hpp"

View File

@ -8,6 +8,7 @@
/** @file error_gui.cpp GUI related to errors. */
#include "stdafx.h"
#include "core/mem_func.hpp"
#include "landscape.h"
#include "newgrf_text.h"
#include "error.h"

View File

@ -10,8 +10,6 @@
#ifndef GAME_TEXT_HPP
#define GAME_TEXT_HPP
#include "../core/smallvec_type.hpp"
struct StringParam {
enum ParamType {
RAW_STRING,

View File

@ -22,6 +22,7 @@
#include "newgrf_debug.h"
#include "thread.h"
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "viewport_func.h"
#include "table/palettes.h"

View File

@ -8,6 +8,7 @@
/** @file gfx_layout.cpp Handling of laying out text. */
#include "stdafx.h"
#include "core/math_func.hpp"
#include "gfx_layout.h"
#include "string_func.h"
#include "debug.h"

View File

@ -22,6 +22,7 @@
#include "tilehighlight_func.h"
#include "vehicle_gui_base.h"
#include "core/geometry_func.hpp"
#include "core/container_func.hpp"
#include "company_base.h"
#include "company_gui.h"
#include "gui.h"

View File

@ -10,7 +10,6 @@
#ifndef LANGUAGE_H
#define LANGUAGE_H
#include "core/smallvec_type.hpp"
#ifdef WITH_ICU_I18N
#include <unicode/coll.h>
#endif /* WITH_ICU_I18N */

View File

@ -12,6 +12,7 @@
#include "../fileio_type.h"
#include "../string_func.h"
#include "../core/endian_func.hpp"
#include "../core/mem_func.hpp"
#include "../base_media_base.h"
#include "midi.h"

View File

@ -11,7 +11,6 @@
#define MUSIC_MIDIFILE_HPP
#include "../stdafx.h"
#include "../core/smallvec_type.hpp"
#include "midi.h"
struct MusicSongInfo;

View File

@ -17,6 +17,7 @@
#include "midifile.hpp"
#include "midi.h"
#include "../base_media_base.h"
#include "../core/mem_func.hpp"
#include <mutex>
#include "../safeguards.h"

View File

@ -18,6 +18,7 @@
#include "gfx_func.h"
#include "zoom_func.h"
#include "core/random_func.hpp"
#include "core/mem_func.hpp"
#include "error.h"
#include "core/geometry_func.hpp"
#include "string_func.h"

View File

@ -13,6 +13,7 @@
#include "core/tcp_content.h"
#include "core/http.h"
#include <unordered_map>
#include "../core/container_func.hpp"
/** Vector with content info */
typedef std::vector<ContentInfo *> ContentVector;

View File

@ -9,6 +9,7 @@
#include "stdafx.h"
#include "core/container_func.hpp"
#include "debug.h"
#include "fileio_func.h"
#include "engine_func.h"

View File

@ -16,7 +16,7 @@
#include "fileio_type.h"
#include "core/bitmath_func.hpp"
#include "core/alloc_type.hpp"
#include "core/smallvec_type.hpp"
#include "core/mem_func.hpp"
/**
* List of different canal 'features'.

View File

@ -15,7 +15,6 @@
#include "sprite.h"
#include "core/alloc_type.hpp"
#include "core/smallvec_type.hpp"
#include "command_type.h"
#include "direction_type.h"
#include "company_type.h"

View File

@ -11,7 +11,6 @@
#define NEWGRF_DEBUG_H
#include "newgrf.h"
#include "core/smallvec_type.hpp"
#include "tile_type.h"
#include "vehicle_type.h"

View File

@ -17,6 +17,7 @@
#include "timer/timer_game_calendar.h"
#include "vehicle_func.h"
#include "core/random_func.hpp"
#include "core/container_func.hpp"
#include "aircraft.h"
#include "station_base.h"
#include "company_base.h"

View File

@ -8,6 +8,7 @@
/** @file newgrf_railtype.cpp NewGRF handling of rail types. */
#include "stdafx.h"
#include "core/container_func.hpp"
#include "debug.h"
#include "newgrf_railtype.h"
#include "timer/timer_game_calendar.h"

View File

@ -8,6 +8,7 @@
/** @file newgrf_roadtype.cpp NewGRF handling of road types. */
#include "stdafx.h"
#include "core/container_func.hpp"
#include "debug.h"
#include "newgrf_roadtype.h"
#include "timer/timer_game_calendar.h"

View File

@ -12,7 +12,6 @@
#include "string_type.h"
#include "strings_type.h"
#include "core/smallvec_type.hpp"
#include "table/control_codes.h"
#include <utility>

View File

@ -26,6 +26,7 @@
#include "pbs.h"
#include "company_base.h"
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "timer/timer_game_calendar.h"
#include "strings_func.h"
#include "company_gui.h"

View File

@ -30,6 +30,7 @@
#include "town.h"
#include "company_base.h"
#include "core/random_func.hpp"
#include "core/container_func.hpp"
#include "newgrf_debug.h"
#include "newgrf_railtype.h"
#include "newgrf_roadtype.h"

View File

@ -13,7 +13,6 @@
#include "compat/animated_tile_sl_compat.h"
#include "../tile_type.h"
#include "../core/smallvec_type.hpp"
#include "../safeguards.h"

View File

@ -27,7 +27,6 @@
#include "../engine_func.h"
#include "../company_base.h"
#include "../disaster_vehicle.h"
#include "../core/smallvec_type.hpp"
#include "../timer/timer.h"
#include "../timer/timer_game_tick.h"
#include "../timer/timer_game_calendar.h"

View File

@ -10,7 +10,6 @@
#ifndef SETTINGS_FUNC_H
#define SETTINGS_FUNC_H
#include "core/smallvec_type.hpp"
#include "company_type.h"
#include "string_type.h"

View File

@ -12,7 +12,7 @@
#include "../strings_type.h"
#include "../misc/getoptdata.h"
#include "../ini_type.h"
#include "../core/smallvec_type.hpp"
#include "../core/mem_func.hpp"
#include "../error_func.h"
#if !defined(_WIN32) || defined(__CYGWIN__)

View File

@ -12,7 +12,7 @@
#include "core/enum_type.hpp"
#include "core/bitmath_func.hpp"
#include "core/smallvec_type.hpp"
#include "core/mem_func.hpp"
#include "date_type.h"
/** Flags of the sort list. */

View File

@ -45,6 +45,7 @@
#include "pbs.h"
#include "debug.h"
#include "core/random_func.hpp"
#include "core/container_func.hpp"
#include "company_base.h"
#include "table/airporttile_ids.h"
#include "newgrf_airporttiles.h"

View File

@ -9,6 +9,7 @@
#include "../stdafx.h"
#include "../core/endian_func.hpp"
#include "../core/mem_func.hpp"
#include "../error_func.h"
#include "../string_func.h"
#include "../strings_type.h"

View File

@ -10,6 +10,7 @@
#include "../stdafx.h"
#include "../core/alloc_func.hpp"
#include "../core/endian_func.hpp"
#include "../core/mem_func.hpp"
#include "../error_func.h"
#include "../string_func.h"
#include "../table/control_codes.h"

View File

@ -10,7 +10,6 @@
#ifndef STRINGFILTER_TYPE_H
#define STRINGFILTER_TYPE_H
#include "core/smallvec_type.hpp"
#include "strings_type.h"
/**

View File

@ -20,6 +20,7 @@
#include "subsidy_func.h"
#include "core/pool_func.hpp"
#include "core/random_func.hpp"
#include "core/container_func.hpp"
#include "game/game.hpp"
#include "command_func.h"
#include "string_func.h"

View File

@ -11,7 +11,6 @@
#include "texteff.hpp"
#include "transparency.h"
#include "strings_func.h"
#include "core/smallvec_type.hpp"
#include "viewport_func.h"
#include "settings_type.h"
#include "command_type.h"

View File

@ -38,6 +38,7 @@
#include "roadstop_base.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "order_backup.h"
#include "sound_func.h"
#include "effectvehicle_func.h"

View File

@ -23,6 +23,7 @@
#include "network/network.h"
#include "saveload/saveload.h"
#include "timer/timer_game_calendar.h"
#include "core/mem_func.hpp"
const uint TILE_AXIAL_DISTANCE = 192; // Logical length of the tile in any DiagDirection used in vehicle movement.
const uint TILE_CORNER_DISTANCE = 128; // Logical length of the tile corner crossing in any non-diagonal direction used in vehicle movement.

View File

@ -31,6 +31,7 @@
#include "articulated_vehicles.h"
#include "spritecache.h"
#include "core/geometry_func.hpp"
#include "core/container_func.hpp"
#include "company_base.h"
#include "engine_func.h"
#include "station_base.h"

View File

@ -10,7 +10,6 @@
#ifndef VEHICLE_GUI_BASE_H
#define VEHICLE_GUI_BASE_H
#include "core/smallvec_type.hpp"
#include "cargo_type.h"
#include "timer/timer_game_calendar.h"
#include "economy_type.h"

View File

@ -10,7 +10,6 @@
#ifndef VEHICLELIST_H
#define VEHICLELIST_H
#include "core/smallvec_type.hpp"
#include "vehicle_type.h"
#include "company_type.h"
#include "tile_type.h"

View File

@ -8,7 +8,6 @@
/** @file viewport_sprite_sorter.h Types related to sprite sorting. */
#include "stdafx.h"
#include "core/smallvec_type.hpp"
#include "gfx_type.h"
#ifndef VIEWPORT_SPRITE_SORTER_H

View File

@ -12,7 +12,6 @@
#include "../window_type.h"
#include "../gfx_func.h"
#include "../core/smallvec_type.hpp"
#include "table/strings.h"
/**

View File

@ -16,7 +16,6 @@
#include "company_type.h"
#include "tile_type.h"
#include "widget_type.h"
#include "core/smallvec_type.hpp"
#include "string_type.h"
/**