Skip to content

Commit

Permalink
Remove unused IStream::ReadString() function and fix includes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Oct 15, 2024
1 parent 1ccef10 commit 915c0f5
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/openrct2/FileClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Diagnostic.h"
#include "core/Console.hpp"
#include "core/FileStream.h"
#include "core/Memory.hpp"
#include "core/Path.hpp"
#include "core/String.hpp"
#include "park/ParkFile.h"
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/core/Crypt.CNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# include "../platform/Platform.h"
# include "IStream.hpp"

# include <cstdint>
# include <iomanip>
# include <limits>
# include <sstream>
# include <stdexcept>
# include <string>
Expand Down
18 changes: 0 additions & 18 deletions src/openrct2/core/IStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,12 @@

#include "IStream.hpp"

#include "../object/Object.h"
#include "Memory.hpp"
#include "String.hpp"

#include <vector>

namespace OpenRCT2
{
utf8* IStream::ReadString()
{
std::vector<utf8> result;

uint8_t ch;
while ((ch = ReadValue<uint8_t>()) != 0)
{
result.push_back(ch);
}
result.push_back(0);

utf8* resultString = Memory::AllocateArray<utf8>(result.size());
std::copy(result.begin(), result.end(), resultString);
return resultString;
}

std::string IStream::ReadStdString()
{
std::string result;
Expand Down
4 changes: 1 addition & 3 deletions src/openrct2/core/IStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#pragma once

#include "../object/Object.h"
#include "Memory.hpp"
#include "StringTypes.h"

#include <istream>
#include <memory>
Expand Down Expand Up @@ -204,7 +203,6 @@ namespace OpenRCT2
Write(buffer, sizeof(T) * count);
}

utf8* ReadString();
std::string ReadStdString();
void WriteString(const utf8* str);
void WriteString(const std::string_view string);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/core/MemoryStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "IStream.hpp"

#include <cstring>
#include <vector>

namespace OpenRCT2
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/core/OrcaStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once

#include "../util/Util.h"
#include "../world/Location.hpp"
#include "Crypt.h"
#include "FileStream.h"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/core/ZipAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# include "../Diagnostic.h"
# include "../platform/Platform.h"
# include "IStream.hpp"
# include "Memory.hpp"
# include "MemoryStream.h"
# include "Zip.h"

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/drawing/Drawing.Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../PlatformEnvironment.h"
#include "../config/Config.h"
#include "../core/FileStream.h"
#include "../core/Guard.hpp"
#include "../core/MemoryStream.h"
#include "../core/Path.hpp"
#include "../platform/Platform.h"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/network/NetworkKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# include "../Diagnostic.h"
# include "../core/Crypt.h"
# include "../core/Guard.hpp"
# include "../core/IStream.hpp"
# include "../core/String.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/AudioObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../Context.h"
#include "../PlatformEnvironment.h"
#include "../audio/AudioContext.h"
#include "../core/Guard.hpp"
#include "../core/Json.hpp"
#include "../core/Path.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/BannerObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "BannerObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../drawing/Drawing.h"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/EntranceObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "EntranceObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/String.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/FootpathRailingsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "FootpathRailingsObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/FootpathSurfaceObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "FootpathSurfaceObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../drawing/Image.h"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/ImageTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../PlatformEnvironment.h"
#include "../core/File.h"
#include "../core/FileScanner.h"
#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/Path.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/PathAdditionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "PathAdditionObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../drawing/Drawing.h"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/PeepNamesObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "../Context.h"
#include "../PlatformEnvironment.h"
#include "../core/Guard.hpp"
#include "../core/Json.hpp"

using namespace OpenRCT2;
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/StationObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "StationObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/String.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/StringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "StringTable.h"

#include "../Context.h"
#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/String.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/TerrainEdgeObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "TerrainEdgeObject.h"

#include "../Context.h"
#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/String.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/object/WallObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "WallObject.h"

#include "../core/Guard.hpp"
#include "../core/IStream.hpp"
#include "../core/Json.hpp"
#include "../core/String.hpp"
Expand Down
46 changes: 19 additions & 27 deletions test/tests/IniWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ TEST_F(IniWriterTest, create_one_section)
ASSERT_LE(ms.GetPosition(), 13); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "[OpenRCT2]" PLATFORM_NEWLINE);
Memory::Free(ini);
auto ini = ms.ReadStdString();
ASSERT_STREQ(ini.c_str(), "[OpenRCT2]" PLATFORM_NEWLINE);
}

TEST_F(IniWriterTest, create_multiple_sections)
Expand All @@ -67,12 +66,11 @@ TEST_F(IniWriterTest, create_multiple_sections)
ASSERT_LE(ms.GetPosition(), 55); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
auto ini = ms.ReadStdString();
ASSERT_STREQ(
ini,
ini.c_str(),
"[OpenRCT1]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[OpenRCT2]" PLATFORM_NEWLINE PLATFORM_NEWLINE
"[OpenRCT3]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[OpenRCT4]" PLATFORM_NEWLINE);
Memory::Free(ini);
}

TEST_F(IniWriterTest, create_loose_bool_entry)
Expand All @@ -87,9 +85,8 @@ TEST_F(IniWriterTest, create_loose_bool_entry)
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "boolval = true" PLATFORM_NEWLINE);
Memory::Free(ini);
auto ini = ms.ReadStdString();
ASSERT_STREQ(ini.c_str(), "boolval = true" PLATFORM_NEWLINE);
}

TEST_F(IniWriterTest, create_loose_enum_entry)
Expand All @@ -105,9 +102,8 @@ TEST_F(IniWriterTest, create_loose_enum_entry)
ASSERT_LE(ms.GetPosition(), 37); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "by_string = stringval" PLATFORM_NEWLINE "int32_t = 0" PLATFORM_NEWLINE);
Memory::Free(ini);
auto ini = ms.ReadStdString();
ASSERT_STREQ(ini.c_str(), "by_string = stringval" PLATFORM_NEWLINE "int32_t = 0" PLATFORM_NEWLINE);
}

TEST_F(IniWriterTest, create_loose_float_entry)
Expand All @@ -122,10 +118,9 @@ TEST_F(IniWriterTest, create_loose_float_entry)
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
auto ini = ms.ReadStdString();
// This will be non-fatal due to float.
EXPECT_STREQ(ini, "one = 1.000000" PLATFORM_NEWLINE);
Memory::Free(ini);
EXPECT_STREQ(ini.c_str(), "one = 1.000000" PLATFORM_NEWLINE);
}

TEST_F(IniWriterTest, create_loose_int32_t_entry)
Expand All @@ -144,12 +139,11 @@ TEST_F(IniWriterTest, create_loose_int32_t_entry)
ASSERT_LE(ms.GetPosition(), 78); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
auto ini = ms.ReadStdString();
ASSERT_STREQ(
ini,
ini.c_str(),
"one = 1" PLATFORM_NEWLINE "zero = 0" PLATFORM_NEWLINE "minusone = -1" PLATFORM_NEWLINE
"intmin = -2147483648" PLATFORM_NEWLINE "intmax = 2147483647" PLATFORM_NEWLINE);
Memory::Free(ini);
}

TEST_F(IniWriterTest, create_loose_string_entry)
Expand All @@ -164,9 +158,9 @@ TEST_F(IniWriterTest, create_loose_string_entry)
ASSERT_LE(ms.GetPosition(), 44); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "path = \"C:'\\\\some/dir\\\\here/\xE7\xA5\x9E\xE9\xB7\xB9\xE6\x9A\xA2\xE9\x81\x8A\"" PLATFORM_NEWLINE);
Memory::Free(ini);
auto ini = ms.ReadStdString();
ASSERT_STREQ(
ini.c_str(), "path = \"C:'\\\\some/dir\\\\here/\xE7\xA5\x9E\xE9\xB7\xB9\xE6\x9A\xA2\xE9\x81\x8A\"" PLATFORM_NEWLINE);
}

TEST_F(IniWriterTest, create_multiple_section_with_values)
Expand All @@ -187,13 +181,12 @@ TEST_F(IniWriterTest, create_multiple_section_with_values)
ASSERT_LE(ms.GetPosition(), 108); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
auto ini = ms.ReadStdString();
ASSERT_STREQ(
ini,
ini.c_str(),
"[bool]" PLATFORM_NEWLINE "boolval = true" PLATFORM_NEWLINE PLATFORM_NEWLINE "[int]" PLATFORM_NEWLINE
"one = 1" PLATFORM_NEWLINE "zero = 0" PLATFORM_NEWLINE PLATFORM_NEWLINE "[string]" PLATFORM_NEWLINE "path = "
"\"C:'\\\\some/dir\\\\here/\xE7\xA5\x9E\xE9\xB7\xB9\xE6\x9A\xA2\xE9\x81\x8A\"" PLATFORM_NEWLINE);
Memory::Free(ini);
}

TEST_F(IniWriterTest, create_duplicate_sections)
Expand All @@ -210,10 +203,9 @@ TEST_F(IniWriterTest, create_duplicate_sections)
ASSERT_LE(ms.GetPosition(), 43); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
auto ini = ms.ReadStdString();
ASSERT_STREQ(
ini,
ini.c_str(),
"[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE
"[section]" PLATFORM_NEWLINE);
Memory::Free(ini);
}

0 comments on commit 915c0f5

Please sign in to comment.