YAPF: Move ValueStr(EndSegmentReasonBits) out of header, remove stringstream

This commit is contained in:
Jonathan G Rennison 2024-09-01 22:56:12 +01:00
parent 2a3a41e2a6
commit 406afedfd3
3 changed files with 29 additions and 17 deletions

View File

@ -4,6 +4,7 @@ add_files(
yapf.hpp
yapf_base.hpp
yapf_cache.h
yapf_common.cpp
yapf_common.hpp
yapf_costbase.hpp
yapf_costcache.hpp

View File

@ -0,0 +1,27 @@
/*
* 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 yapf_common.cpp Pathfinding common functions. */
#include "../../stdafx.h"
#include "yapf.hpp"
#include "../../string_func.h"
#include "../../safeguards.h"
std::string ValueStr(EndSegmentReasonBits bits)
{
static const char * const end_segment_reason_names[] = {
"DEAD_END", "DEAD_END_EOL", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
"DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
"PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED",
"REVERSE"
};
return stdstr_fmt("0x%04X (%s)", bits, ComposeNameT(bits, end_segment_reason_names, "UNK", ESRB_NONE, "NONE").c_str());
}

View File

@ -10,9 +10,6 @@
#ifndef YAPF_TYPE_HPP
#define YAPF_TYPE_HPP
#include <iomanip>
#include <sstream>
/* Enum used in PfCalcCost() to see why was the segment closed. */
enum EndSegmentReason {
/* The following reasons can be saved into cached segment */
@ -76,19 +73,6 @@ enum EndSegmentReasonBits {
DECLARE_ENUM_AS_BIT_SET(EndSegmentReasonBits)
inline std::string ValueStr(EndSegmentReasonBits bits)
{
static const char * const end_segment_reason_names[] = {
"DEAD_END", "DEAD_END_EOL", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
"DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
"PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED",
"REVERSE"
};
std::stringstream ss;
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << bits; // 0x%04X
ss << " (" << ComposeNameT(bits, end_segment_reason_names, "UNK", ESRB_NONE, "NONE") << ")";
return ss.str();
}
std::string ValueStr(EndSegmentReasonBits bits);
#endif /* YAPF_TYPE_HPP */