Use [[nodiscard]] for allocator and RAII functions (#15244)

This commit is contained in:
Hielke Morsink 2021-08-23 20:09:43 +02:00 committed by GitHub
parent bc1696ab48
commit 956e77f4c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 192 additions and 174 deletions

View File

@ -46,9 +46,9 @@ namespace OpenRCT2
virtual bool HasFilePicker() const abstract;
};
std::unique_ptr<IUiContext> CreateUiContext(const std::shared_ptr<IPlatformEnvironment>& env);
IPlatformUiContext* CreatePlatformUiContext();
[[nodiscard]] std::unique_ptr<IUiContext> CreateUiContext(const std::shared_ptr<IPlatformEnvironment>& env);
[[nodiscard]] IPlatformUiContext* CreatePlatformUiContext();
InGameConsole& GetInGameConsole();
[[nodiscard]] InGameConsole& GetInGameConsole();
} // namespace Ui
} // namespace OpenRCT2

View File

@ -79,6 +79,6 @@ namespace OpenRCT2::Audio
IAudioMixer* Create();
}
std::unique_ptr<IAudioContext> CreateAudioContext();
[[nodiscard]] std::unique_ptr<IAudioContext> CreateAudioContext();
} // namespace OpenRCT2::Audio

View File

@ -21,16 +21,18 @@ namespace OpenRCT2
struct IUiContext;
std::unique_ptr<IDrawingEngine> CreateSoftwareDrawingEngine(const std::shared_ptr<IUiContext>& uiContext);
std::unique_ptr<IDrawingEngine> CreateHardwareDisplayDrawingEngine(const std::shared_ptr<IUiContext>& uiContext);
[[nodiscard]] std::unique_ptr<IDrawingEngine> CreateSoftwareDrawingEngine(const std::shared_ptr<IUiContext>& uiContext);
[[nodiscard]] std::unique_ptr<IDrawingEngine> CreateHardwareDisplayDrawingEngine(
const std::shared_ptr<IUiContext>& uiContext);
#ifndef DISABLE_OPENGL
std::unique_ptr<IDrawingEngine> CreateOpenGLDrawingEngine(const std::shared_ptr<IUiContext>& uiContext);
[[nodiscard]] std::unique_ptr<IDrawingEngine> CreateOpenGLDrawingEngine(const std::shared_ptr<IUiContext>& uiContext);
#endif
class DrawingEngineFactory final : public IDrawingEngineFactory
{
public:
std::unique_ptr<IDrawingEngine> Create(DrawingEngine type, const std::shared_ptr<IUiContext>& uiContext) override
[[nodiscard]] std::unique_ptr<IDrawingEngine> Create(
DrawingEngine type, const std::shared_ptr<IUiContext>& uiContext) override
{
switch (type)
{

View File

@ -20,4 +20,4 @@ namespace OpenRCT2
class GameState;
}
std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(OpenRCT2::GameState& gameState);
[[nodiscard]] std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(OpenRCT2::GameState& gameState);

View File

@ -114,10 +114,10 @@ namespace OpenRCT2
{
virtual ~IContext() = default;
virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
[[nodiscard]] virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
[[nodiscard]] virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
virtual GameState* GetGameState() abstract;
virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
[[nodiscard]] virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
virtual Localisation::LocalisationService& GetLocalisationService() abstract;
virtual IObjectManager& GetObjectManager() abstract;
virtual IObjectRepository& GetObjectRepository() abstract;
@ -156,11 +156,11 @@ namespace OpenRCT2
virtual float GetTimeScale() const abstract;
};
std::unique_ptr<IContext> CreateContext();
std::unique_ptr<IContext> CreateContext(
[[nodiscard]] std::unique_ptr<IContext> CreateContext();
[[nodiscard]] std::unique_ptr<IContext> CreateContext(
const std::shared_ptr<IPlatformEnvironment>& env, const std::shared_ptr<Audio::IAudioContext>& audioContext,
const std::shared_ptr<Ui::IUiContext>& uiContext);
IContext* GetContext();
[[nodiscard]] IContext* GetContext();
} // namespace OpenRCT2
enum

View File

@ -110,4 +110,4 @@ struct IGameStateSnapshots
virtual std::string GetCompareDataText(const GameStateCompareData_t& cmpData) const = 0;
};
std::unique_ptr<IGameStateSnapshots> CreateGameStateSnapshots();
[[nodiscard]] std::unique_ptr<IGameStateSnapshots> CreateGameStateSnapshots();

View File

@ -57,9 +57,9 @@ public:
namespace ParkImporter
{
std::unique_ptr<IParkImporter> Create(const std::string& hintPath);
std::unique_ptr<IParkImporter> CreateS4();
std::unique_ptr<IParkImporter> CreateS6(IObjectRepository& objectRepository);
[[nodiscard]] std::unique_ptr<IParkImporter> Create(const std::string& hintPath);
[[nodiscard]] std::unique_ptr<IParkImporter> CreateS4();
[[nodiscard]] std::unique_ptr<IParkImporter> CreateS6(IObjectRepository& objectRepository);
bool ExtensionIsRCT1(const std::string& extension);
bool ExtensionIsScenario(const std::string& extension);

View File

@ -84,7 +84,7 @@ namespace OpenRCT2
virtual void SetBasePath(DIRBASE base, const std::string& path) abstract;
};
std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths);
std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment();
[[nodiscard]] std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths);
[[nodiscard]] std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment();
} // namespace OpenRCT2

View File

@ -65,6 +65,6 @@ namespace OpenRCT2
virtual bool NormaliseReplay(const std::string& inputFile, const std::string& outputFile) = 0;
};
std::unique_ptr<IReplayManager> CreateReplayManager();
[[nodiscard]] std::unique_ptr<IReplayManager> CreateReplayManager();
} // namespace OpenRCT2

View File

@ -28,14 +28,14 @@ public:
virtual bool Load(const utf8* path) abstract;
virtual bool LoadFromStream(OpenRCT2::IStream* stream) abstract;
virtual std::unique_ptr<TrackDesign> Import() abstract;
[[nodiscard]] virtual std::unique_ptr<TrackDesign> Import() abstract;
};
namespace TrackImporter
{
std::unique_ptr<ITrackImporter> Create(const std::string& hintPath);
std::unique_ptr<ITrackImporter> CreateTD4();
std::unique_ptr<ITrackImporter> CreateTD6();
[[nodiscard]] std::unique_ptr<ITrackImporter> Create(const std::string& hintPath);
[[nodiscard]] std::unique_ptr<ITrackImporter> CreateTD4();
[[nodiscard]] std::unique_ptr<ITrackImporter> CreateTD6();
bool ExtensionIsRCT1(const std::string& extension);
} // namespace TrackImporter

View File

@ -55,6 +55,6 @@ namespace OpenRCT2::Audio
virtual void StopVehicleSounds() abstract;
};
std::unique_ptr<IAudioContext> CreateDummyAudioContext();
[[nodiscard]] std::unique_ptr<IAudioContext> CreateDummyAudioContext();
} // namespace OpenRCT2::Audio

View File

@ -48,5 +48,5 @@ struct IIniReader
utf8* GetCString(const std::string& name, const utf8* defaultValue) const;
};
std::unique_ptr<IIniReader> CreateIniReader(OpenRCT2::IStream* stream);
std::unique_ptr<IIniReader> CreateDefaultIniReader();
[[nodiscard]] std::unique_ptr<IIniReader> CreateIniReader(OpenRCT2::IStream* stream);
[[nodiscard]] std::unique_ptr<IIniReader> CreateDefaultIniReader();

View File

@ -52,4 +52,4 @@ struct IIniWriter
void WriteString(const std::string& name, const utf8* value);
};
std::unique_ptr<IIniWriter> CreateIniWriter(OpenRCT2::IStream* stream);
[[nodiscard]] std::unique_ptr<IIniWriter> CreateIniWriter(OpenRCT2::IStream* stream);

View File

@ -50,10 +50,10 @@ namespace Crypt
using Sha256Algorithm = HashAlgorithm<32>;
// Factories
std::unique_ptr<Sha1Algorithm> CreateSHA1();
std::unique_ptr<Sha256Algorithm> CreateSHA256();
std::unique_ptr<RsaAlgorithm> CreateRSA();
std::unique_ptr<RsaKey> CreateRSAKey();
[[nodiscard]] std::unique_ptr<Sha1Algorithm> CreateSHA1();
[[nodiscard]] std::unique_ptr<Sha256Algorithm> CreateSHA256();
[[nodiscard]] std::unique_ptr<RsaAlgorithm> CreateRSA();
[[nodiscard]] std::unique_ptr<RsaKey> CreateRSAKey();
inline Sha1Algorithm::Result SHA1(const void* data, size_t dataLen)
{

View File

@ -51,7 +51,7 @@ namespace Path
* @param recurse Whether to scan sub directories or not.
* @returns A new FileScanner, this must be deleted when no longer needed.
*/
std::unique_ptr<IFileScanner> ScanDirectory(const std::string& pattern, bool recurse);
[[nodiscard]] std::unique_ptr<IFileScanner> ScanDirectory(const std::string& pattern, bool recurse);
/**
* Scans a directory and all sub directories
@ -60,5 +60,5 @@ namespace Path
*/
void QueryDirectory(QueryDirectoryResult* result, const std::string& pattern);
std::vector<std::string> GetDirectories(const std::string& path);
[[nodiscard]] std::vector<std::string> GetDirectories(const std::string& path);
} // namespace Path

View File

@ -192,7 +192,7 @@ namespace OpenRCT2
Write(&value);
}
template<typename T> std::unique_ptr<T[]> ReadArray(size_t count)
template<typename T>[[nodiscard]] std::unique_ptr<T[]> ReadArray(size_t count)
{
auto buffer = std::make_unique<T[]>(count);
Read(buffer.get(), sizeof(T) * count);

View File

@ -31,11 +31,11 @@ struct IZipArchive
{
}
virtual size_t GetNumFiles() const abstract;
virtual std::string GetFileName(size_t index) const abstract;
virtual uint64_t GetFileSize(size_t index) const abstract;
virtual std::vector<uint8_t> GetFileData(std::string_view path) const abstract;
virtual std::unique_ptr<OpenRCT2::IStream> GetFileStream(std::string_view path) const abstract;
[[nodiscard]] virtual size_t GetNumFiles() const abstract;
[[nodiscard]] virtual std::string GetFileName(size_t index) const abstract;
[[nodiscard]] virtual uint64_t GetFileSize(size_t index) const abstract;
[[nodiscard]] virtual std::vector<uint8_t> GetFileData(std::string_view path) const abstract;
[[nodiscard]] virtual std::unique_ptr<OpenRCT2::IStream> GetFileStream(std::string_view path) const abstract;
/**
* Creates or overwrites a file within the zip archive to the given data buffer.
@ -47,8 +47,8 @@ struct IZipArchive
virtual void DeleteFile(std::string_view path) abstract;
virtual void RenameFile(std::string_view path, std::string_view newPath) abstract;
std::optional<size_t> GetIndexFromPath(std::string_view path) const;
bool Exists(std::string_view path) const;
[[nodiscard]] std::optional<size_t> GetIndexFromPath(std::string_view path) const;
[[nodiscard]] bool Exists(std::string_view path) const;
};
enum class ZIP_ACCESS
@ -59,6 +59,6 @@ enum class ZIP_ACCESS
namespace Zip
{
std::unique_ptr<IZipArchive> Open(std::string_view path, ZIP_ACCESS zipAccess);
std::unique_ptr<IZipArchive> TryOpen(std::string_view path, ZIP_ACCESS zipAccess);
[[nodiscard]] std::unique_ptr<IZipArchive> Open(std::string_view path, ZIP_ACCESS zipAccess);
[[nodiscard]] std::unique_ptr<IZipArchive> TryOpen(std::string_view path, ZIP_ACCESS zipAccess);
} // namespace Zip

View File

@ -79,7 +79,7 @@ namespace OpenRCT2::Drawing
virtual ~IDrawingEngineFactory()
{
}
virtual std::unique_ptr<IDrawingEngine> Create(
[[nodiscard]] virtual std::unique_ptr<IDrawingEngine> Create(
DrawingEngine type, const std::shared_ptr<OpenRCT2::Ui::IUiContext>& uiContext) abstract;
};

View File

@ -30,4 +30,4 @@ struct INetworkServerAdvertiser
virtual void Update() abstract;
};
std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port);
[[nodiscard]] std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port);

View File

@ -60,7 +60,7 @@ public:
virtual void Listen(uint16_t port) abstract;
virtual void Listen(const std::string& address, uint16_t port) abstract;
virtual std::unique_ptr<ITcpSocket> Accept() abstract;
[[nodiscard]] virtual std::unique_ptr<ITcpSocket> Accept() abstract;
virtual void Connect(const std::string& address, uint16_t port) abstract;
virtual void ConnectAsync(const std::string& address, uint16_t port) abstract;
@ -98,9 +98,9 @@ public:
virtual void Close() abstract;
};
std::unique_ptr<ITcpSocket> CreateTcpSocket();
std::unique_ptr<IUdpSocket> CreateUdpSocket();
std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses();
[[nodiscard]] std::unique_ptr<ITcpSocket> CreateTcpSocket();
[[nodiscard]] std::unique_ptr<IUdpSocket> CreateUdpSocket();
[[nodiscard]] std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses();
namespace Convert
{

View File

@ -47,8 +47,8 @@ void network_shutdown_client();
int32_t network_begin_client(const std::string& host, int32_t port);
int32_t network_begin_server(int32_t port, const std::string& address);
int32_t network_get_mode();
int32_t network_get_status();
[[nodiscard]] int32_t network_get_mode();
[[nodiscard]] int32_t network_get_status();
bool network_is_desynchronised();
bool network_check_desynchronisation();
void network_request_gamestate_snapshot();
@ -58,46 +58,46 @@ void network_update();
void network_process_pending();
void network_flush();
NetworkAuth network_get_authstatus();
uint32_t network_get_server_tick();
uint8_t network_get_current_player_id();
int32_t network_get_num_players();
const char* network_get_player_name(uint32_t index);
uint32_t network_get_player_flags(uint32_t index);
int32_t network_get_player_ping(uint32_t index);
int32_t network_get_player_id(uint32_t index);
money32 network_get_player_money_spent(uint32_t index);
std::string network_get_player_ip_address(uint32_t id);
std::string network_get_player_public_key_hash(uint32_t id);
[[nodiscard]] NetworkAuth network_get_authstatus();
[[nodiscard]] uint32_t network_get_server_tick();
[[nodiscard]] uint8_t network_get_current_player_id();
[[nodiscard]] int32_t network_get_num_players();
[[nodiscard]] const char* network_get_player_name(uint32_t index);
[[nodiscard]] uint32_t network_get_player_flags(uint32_t index);
[[nodiscard]] int32_t network_get_player_ping(uint32_t index);
[[nodiscard]] int32_t network_get_player_id(uint32_t index);
[[nodiscard]] money32 network_get_player_money_spent(uint32_t index);
[[nodiscard]] std::string network_get_player_ip_address(uint32_t id);
[[nodiscard]] std::string network_get_player_public_key_hash(uint32_t id);
void network_add_player_money_spent(uint32_t index, money32 cost);
int32_t network_get_player_last_action(uint32_t index, int32_t time);
[[nodiscard]] int32_t network_get_player_last_action(uint32_t index, int32_t time);
void network_set_player_last_action(uint32_t index, GameCommand command);
CoordsXYZ network_get_player_last_action_coord(uint32_t index);
[[nodiscard]] CoordsXYZ network_get_player_last_action_coord(uint32_t index);
void network_set_player_last_action_coord(uint32_t index, const CoordsXYZ& coord);
uint32_t network_get_player_commands_ran(uint32_t index);
int32_t network_get_player_index(uint32_t id);
uint8_t network_get_player_group(uint32_t index);
[[nodiscard]] uint32_t network_get_player_commands_ran(uint32_t index);
[[nodiscard]] int32_t network_get_player_index(uint32_t id);
[[nodiscard]] uint8_t network_get_player_group(uint32_t index);
void network_set_player_group(uint32_t index, uint32_t groupindex);
int32_t network_get_group_index(uint8_t id);
int32_t network_get_current_player_group_index();
uint8_t network_get_group_id(uint32_t index);
int32_t network_get_num_groups();
const char* network_get_group_name(uint32_t index);
std::unique_ptr<GameActions::Result> network_set_player_group(
[[nodiscard]] int32_t network_get_group_index(uint8_t id);
[[nodiscard]] int32_t network_get_current_player_group_index();
[[nodiscard]] uint8_t network_get_group_id(uint32_t index);
[[nodiscard]] int32_t network_get_num_groups();
[[nodiscard]] const char* network_get_group_name(uint32_t index);
[[nodiscard]] std::unique_ptr<GameActions::Result> network_set_player_group(
NetworkPlayerId_t actionPlayerId, NetworkPlayerId_t playerId, uint8_t groupId, bool isExecuting);
std::unique_ptr<GameActions::Result> network_modify_groups(
[[nodiscard]] std::unique_ptr<GameActions::Result> network_modify_groups(
NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex,
PermissionState permissionState, bool isExecuting);
std::unique_ptr<GameActions::Result> network_kick_player(NetworkPlayerId_t playerId, bool isExecuting);
uint8_t network_get_default_group();
int32_t network_get_num_actions();
rct_string_id network_get_action_name_string_id(uint32_t index);
int32_t network_can_perform_action(uint32_t groupindex, NetworkPermission index);
int32_t network_can_perform_command(uint32_t groupindex, int32_t index);
[[nodiscard]] std::unique_ptr<GameActions::Result> network_kick_player(NetworkPlayerId_t playerId, bool isExecuting);
[[nodiscard]] uint8_t network_get_default_group();
[[nodiscard]] int32_t network_get_num_actions();
[[nodiscard]] rct_string_id network_get_action_name_string_id(uint32_t index);
[[nodiscard]] int32_t network_can_perform_action(uint32_t groupindex, NetworkPermission index);
[[nodiscard]] int32_t network_can_perform_command(uint32_t groupindex, int32_t index);
void network_set_pickup_peep(uint8_t playerid, Peep* peep);
Peep* network_get_pickup_peep(uint8_t playerid);
[[nodiscard]] Peep* network_get_pickup_peep(uint8_t playerid);
void network_set_pickup_peep_old_x(uint8_t playerid, int32_t x);
int32_t network_get_pickup_peep_old_x(uint8_t playerid);
[[nodiscard]] int32_t network_get_pickup_peep_old_x(uint8_t playerid);
void network_send_map();
void network_send_chat(const char* text, const std::vector<uint8_t>& playerIds = {});
@ -110,15 +110,15 @@ void network_set_password(const char* password);
void network_print_error();
void network_append_chat_log(const utf8* text);
void network_append_server_log(const utf8* text);
const utf8* network_get_server_name();
const utf8* network_get_server_description();
const utf8* network_get_server_greeting();
const utf8* network_get_server_provider_name();
const utf8* network_get_server_provider_email();
const utf8* network_get_server_provider_website();
[[nodiscard]] const utf8* network_get_server_name();
[[nodiscard]] const utf8* network_get_server_description();
[[nodiscard]] const utf8* network_get_server_greeting();
[[nodiscard]] const utf8* network_get_server_provider_name();
[[nodiscard]] const utf8* network_get_server_provider_email();
[[nodiscard]] const utf8* network_get_server_provider_website();
std::string network_get_version();
[[nodiscard]] std::string network_get_version();
NetworkStats_t network_get_stats();
NetworkServerState_t network_get_server_state();
json_t network_get_server_info_as_json();
[[nodiscard]] NetworkStats_t network_get_stats();
[[nodiscard]] NetworkServerState_t network_get_server_state();
[[nodiscard]] json_t network_get_server_info_as_json();

View File

@ -32,15 +32,17 @@ private:
* Container for a G1 image, additional information and RAII. Used by ReadJson
*/
struct RequiredImage;
static std::vector<std::unique_ptr<ImageTable::RequiredImage>> ParseImages(IReadObjectContext* context, std::string s);
[[nodiscard]] static std::vector<std::unique_ptr<ImageTable::RequiredImage>> ParseImages(
IReadObjectContext* context, std::string s);
/**
* @note root is deliberately left non-const: json_t behaviour changes when const
*/
static std::vector<std::unique_ptr<ImageTable::RequiredImage>> ParseImages(IReadObjectContext* context, json_t& el);
static std::vector<std::unique_ptr<ImageTable::RequiredImage>> LoadObjectImages(
[[nodiscard]] static std::vector<std::unique_ptr<ImageTable::RequiredImage>> ParseImages(
IReadObjectContext* context, json_t& el);
[[nodiscard]] static std::vector<std::unique_ptr<ImageTable::RequiredImage>> LoadObjectImages(
IReadObjectContext* context, const std::string& name, const std::vector<int32_t>& range);
static std::vector<int32_t> ParseRange(std::string s);
static std::string FindLegacyObject(const std::string& name);
[[nodiscard]] static std::vector<int32_t> ParseRange(std::string s);
[[nodiscard]] static std::string FindLegacyObject(const std::string& name);
public:
ImageTable() = default;

View File

@ -43,9 +43,9 @@ public:
const rct_large_scenery_tile* GetTileForSequence(uint8_t SequenceIndex) const;
private:
static std::vector<rct_large_scenery_tile> ReadTiles(OpenRCT2::IStream* stream);
static std::vector<rct_large_scenery_tile> ReadJsonTiles(json_t& jTiles);
static std::unique_ptr<LargeSceneryText> ReadJson3dFont(json_t& j3dFont);
static std::vector<CoordsXY> ReadJsonOffsets(json_t& jOffsets);
static std::vector<rct_large_scenery_text_glyph> ReadJsonGlyphs(json_t& jGlyphs);
[[nodiscard]] static std::vector<rct_large_scenery_tile> ReadTiles(OpenRCT2::IStream* stream);
[[nodiscard]] static std::vector<rct_large_scenery_tile> ReadJsonTiles(json_t& jTiles);
[[nodiscard]] static std::unique_ptr<LargeSceneryText> ReadJson3dFont(json_t& j3dFont);
[[nodiscard]] static std::vector<CoordsXY> ReadJsonOffsets(json_t& jOffsets);
[[nodiscard]] static std::vector<rct_large_scenery_text_glyph> ReadJsonGlyphs(json_t& jGlyphs);
};

View File

@ -222,9 +222,9 @@ public:
{
}
bool IsAvailable() const;
uint64_t GetSize() const;
std::unique_ptr<OpenRCT2::IStream> GetStream() const;
[[nodiscard]] bool IsAvailable() const;
[[nodiscard]] uint64_t GetSize() const;
[[nodiscard]] std::unique_ptr<OpenRCT2::IStream> GetStream() const;
};
struct IReadObjectContext

View File

@ -20,11 +20,12 @@ struct rct_object_entry;
namespace ObjectFactory
{
std::unique_ptr<Object> CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8* path);
std::unique_ptr<Object> CreateObjectFromLegacyData(
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8* path);
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromLegacyData(
IObjectRepository& objectRepository, const rct_object_entry* entry, const void* data, size_t dataSize);
std::unique_ptr<Object> CreateObjectFromZipFile(IObjectRepository& objectRepository, std::string_view path);
std::unique_ptr<Object> CreateObject(const rct_object_entry& entry);
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromZipFile(IObjectRepository& objectRepository, std::string_view path);
[[nodiscard]] std::unique_ptr<Object> CreateObject(const rct_object_entry& entry);
std::unique_ptr<Object> CreateObjectFromJsonFile(IObjectRepository& objectRepository, const std::string& path);
[[nodiscard]] std::unique_ptr<Object> CreateObjectFromJsonFile(
IObjectRepository& objectRepository, const std::string& path);
} // namespace ObjectFactory

View File

@ -43,13 +43,13 @@ struct IObjectManager
virtual const std::vector<ObjectEntryIndex>& GetAllRideEntries(uint8_t rideType) abstract;
};
std::unique_ptr<IObjectManager> CreateObjectManager(IObjectRepository& objectRepository);
[[nodiscard]] std::unique_ptr<IObjectManager> CreateObjectManager(IObjectRepository& objectRepository);
Object* object_manager_get_loaded_object_by_index(size_t index);
Object* object_manager_get_loaded_object(const ObjectEntryDescriptor& entry);
ObjectEntryIndex object_manager_get_loaded_object_entry_index(const Object* loadedObject);
ObjectEntryIndex object_manager_get_loaded_object_entry_index(const ObjectEntryDescriptor& entry);
[[nodiscard]] Object* object_manager_get_loaded_object_by_index(size_t index);
[[nodiscard]] Object* object_manager_get_loaded_object(const ObjectEntryDescriptor& entry);
[[nodiscard]] ObjectEntryIndex object_manager_get_loaded_object_entry_index(const Object* loadedObject);
[[nodiscard]] ObjectEntryIndex object_manager_get_loaded_object_entry_index(const ObjectEntryDescriptor& entry);
Object* object_manager_load_object(const rct_object_entry* entry);
void object_manager_unload_objects(const std::vector<rct_object_entry>& entries);
void object_manager_unload_all_objects();
rct_string_id object_manager_get_source_game_string(const ObjectSourceGame sourceGame);
[[nodiscard]] rct_string_id object_manager_get_source_game_string(const ObjectSourceGame sourceGame);

View File

@ -55,7 +55,7 @@ struct ObjectRepositoryItem
std::vector<ObjectEntryDescriptor> Entries;
} SceneryGroupInfo;
ObjectSourceGame GetFirstSourceGame() const
[[nodiscard]] ObjectSourceGame GetFirstSourceGame() const
{
if (Sources.empty())
return ObjectSourceGame::Custom;
@ -70,14 +70,14 @@ struct IObjectRepository
virtual void LoadOrConstruct(int32_t language) abstract;
virtual void Construct(int32_t language) abstract;
virtual size_t GetNumObjects() const abstract;
virtual const ObjectRepositoryItem* GetObjects() const abstract;
virtual const ObjectRepositoryItem* FindObjectLegacy(std::string_view legacyIdentifier) const abstract;
virtual const ObjectRepositoryItem* FindObject(std::string_view identifier) const abstract;
virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract;
virtual const ObjectRepositoryItem* FindObject(const ObjectEntryDescriptor& oed) const abstract;
[[nodiscard]] virtual size_t GetNumObjects() const abstract;
[[nodiscard]] virtual const ObjectRepositoryItem* GetObjects() const abstract;
[[nodiscard]] virtual const ObjectRepositoryItem* FindObjectLegacy(std::string_view legacyIdentifier) const abstract;
[[nodiscard]] virtual const ObjectRepositoryItem* FindObject(std::string_view identifier) const abstract;
[[nodiscard]] virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract;
[[nodiscard]] virtual const ObjectRepositoryItem* FindObject(const ObjectEntryDescriptor& oed) const abstract;
virtual std::unique_ptr<Object> LoadObject(const ObjectRepositoryItem* ori) abstract;
[[nodiscard]] virtual std::unique_ptr<Object> LoadObject(const ObjectRepositoryItem* ori) abstract;
virtual void RegisterLoadedObject(const ObjectRepositoryItem* ori, Object* object) abstract;
virtual void UnregisterLoadedObject(const ObjectRepositoryItem* ori, Object* object) abstract;
@ -88,12 +88,13 @@ struct IObjectRepository
virtual void WritePackedObjects(OpenRCT2::IStream* stream, std::vector<const ObjectRepositoryItem*>& objects) abstract;
};
std::unique_ptr<IObjectRepository> CreateObjectRepository(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
[[nodiscard]] std::unique_ptr<IObjectRepository> CreateObjectRepository(
const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
bool IsObjectCustom(const ObjectRepositoryItem* object);
[[nodiscard]] bool IsObjectCustom(const ObjectRepositoryItem* object);
size_t object_repository_get_items_count();
const ObjectRepositoryItem* object_repository_get_items();
const ObjectRepositoryItem* object_repository_find_object_by_entry(const rct_object_entry* entry);
const ObjectRepositoryItem* object_repository_find_object_by_name(const char* name);
std::unique_ptr<Object> object_repository_load_object(const rct_object_entry* objectEntry);
[[nodiscard]] size_t object_repository_get_items_count();
[[nodiscard]] const ObjectRepositoryItem* object_repository_get_items();
[[nodiscard]] const ObjectRepositoryItem* object_repository_find_object_by_entry(const rct_object_entry* entry);
[[nodiscard]] const ObjectRepositoryItem* object_repository_find_object_by_name(const char* name);
[[nodiscard]] std::unique_ptr<Object> object_repository_load_object(const rct_object_entry* objectEntry);

View File

@ -625,18 +625,18 @@ public: // Peep
void UpdateCurrentActionSpriteType();
void SwitchToSpecialSprite(uint8_t special_sprite_id);
void StateReset();
uint8_t GetNextDirection() const;
[[nodiscard]] uint8_t GetNextDirection() const;
bool GetNextIsSloped() const;
bool GetNextIsSurface() const;
void SetNextFlags(uint8_t next_direction, bool is_sloped, bool is_surface);
bool CanBePickedUp() const;
void Pickup();
void PickupAbort(int32_t old_x);
std::unique_ptr<GameActions::Result> Place(const TileCoordsXYZ& location, bool apply);
[[nodiscard]] std::unique_ptr<GameActions::Result> Place(const TileCoordsXYZ& location, bool apply);
void RemoveFromRide();
void FormatActionTo(Formatter&) const;
void FormatNameTo(Formatter&) const;
std::string GetName() const;
[[nodiscard]] std::string GetName() const;
bool SetName(std::string_view value);
bool IsActionWalking() const;
bool IsActionIdle() const;
@ -648,16 +648,16 @@ public: // Peep
void SetDestination(const CoordsXY& coords);
void SetDestination(const CoordsXY& coords, int32_t tolerance);
CoordsXY GetDestination() const;
[[nodiscard]] CoordsXY GetDestination() const;
// TODO: Make these private again when done refactoring
public: // Peep
bool CheckForPath();
[[nodiscard]] bool CheckForPath();
void PerformNextAction(uint8_t& pathing_result);
void PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result);
int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y);
[[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y);
void SwitchNextActionSpriteType();
PeepActionSpriteType GetActionSpriteType();
[[nodiscard]] PeepActionSpriteType GetActionSpriteType();
private:
void UpdateFalling();

View File

@ -57,12 +57,12 @@ public:
/**
* Reads the next chunk from the stream.
*/
std::shared_ptr<SawyerChunk> ReadChunk();
[[nodiscard]] std::shared_ptr<SawyerChunk> ReadChunk();
/**
* As above but for chunks without a header
*/
std::shared_ptr<SawyerChunk> ReadChunkTrack();
[[nodiscard]] std::shared_ptr<SawyerChunk> ReadChunkTrack();
/**
* Reads the next chunk from the stream and copies it directly to the

View File

@ -450,7 +450,7 @@ public:
static void UpdateAll();
static bool NameExists(std::string_view name, ride_id_t excludeRideId = RIDE_ID_NULL);
std::unique_ptr<TrackDesign> SaveToTrackDesign() const;
[[nodiscard]] std::unique_ptr<TrackDesign> SaveToTrackDesign() const;
uint64_t GetAvailableModes() const;
const RideTypeDescriptor& GetRideTypeDescriptor() const;

View File

@ -199,7 +199,7 @@ extern bool _trackDesignPlaceStateSceneryUnavailable;
extern bool gTrackDesignSaveMode;
extern ride_id_t gTrackDesignSaveRideIndex;
std::unique_ptr<TrackDesign> track_design_open(const utf8* path);
[[nodiscard]] std::unique_ptr<TrackDesign> track_design_open(const utf8* path);
void track_design_mirror(TrackDesign* td6);

View File

@ -31,9 +31,9 @@ struct ITrackDesignRepository
{
virtual ~ITrackDesignRepository() = default;
virtual size_t GetCount() const abstract;
virtual size_t GetCountForObjectEntry(uint8_t rideType, const std::string& entry) const abstract;
virtual std::vector<track_design_file_ref> GetItemsForObjectEntry(
[[nodiscard]] virtual size_t GetCount() const abstract;
[[nodiscard]] virtual size_t GetCountForObjectEntry(uint8_t rideType, const std::string& entry) const abstract;
[[nodiscard]] virtual std::vector<track_design_file_ref> GetItemsForObjectEntry(
uint8_t rideType, const std::string& entry) const abstract;
virtual void Scan(int32_t language) abstract;
@ -42,8 +42,9 @@ struct ITrackDesignRepository
virtual std::string Install(const std::string& path, const std::string& name) abstract;
};
std::unique_ptr<ITrackDesignRepository> CreateTrackDesignRepository(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
std::string GetNameFromTrackPath(const std::string& path);
[[nodiscard]] std::unique_ptr<ITrackDesignRepository> CreateTrackDesignRepository(
const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
[[nodiscard]] std::string GetNameFromTrackPath(const std::string& path);
void track_repository_scan();
bool track_repository_delete(const utf8* path);

View File

@ -74,11 +74,13 @@ struct IScenarioRepository
int32_t language, const utf8* scenarioFileName, money64 companyValue, const utf8* name) abstract;
};
std::unique_ptr<IScenarioRepository> CreateScenarioRepository(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
IScenarioRepository* GetScenarioRepository();
[[nodiscard]] std::unique_ptr<IScenarioRepository> CreateScenarioRepository(
const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
[[nodiscard]] IScenarioRepository* GetScenarioRepository();
void scenario_repository_scan();
size_t scenario_repository_get_count();
const scenario_index_entry* scenario_repository_get_by_index(size_t index);
bool scenario_repository_try_record_highscore(const utf8* scenarioFileName, money64 companyValue, const utf8* name);
[[nodiscard]] size_t scenario_repository_get_count();
[[nodiscard]] const scenario_index_entry* scenario_repository_get_by_index(size_t index);
[[nodiscard]] bool scenario_repository_try_record_highscore(
const utf8* scenarioFileName, money64 companyValue, const utf8* name);
void scenario_translate(scenario_index_entry* scenarioEntry);

View File

@ -220,12 +220,12 @@ namespace OpenRCT2::Scripting
void AddNetworkPlugin(std::string_view code);
std::unique_ptr<GameActions::Result> QueryOrExecuteCustomGameAction(
[[nodiscard]] std::unique_ptr<GameActions::Result> QueryOrExecuteCustomGameAction(
std::string_view id, std::string_view args, bool isExecute);
bool RegisterCustomAction(
const std::shared_ptr<Plugin>& plugin, std::string_view action, const DukValue& query, const DukValue& execute);
void RunGameActionHooks(const GameAction& action, std::unique_ptr<GameActions::Result>& result, bool isExecute);
std::unique_ptr<GameAction> CreateGameAction(const std::string& actionid, const DukValue& args);
[[nodiscard]] std::unique_ptr<GameAction> CreateGameAction(const std::string& actionid, const DukValue& args);
void SaveSharedStorage();
@ -249,8 +249,9 @@ namespace OpenRCT2::Scripting
void AutoReloadPlugins();
void ProcessREPL();
void RemoveCustomGameActions(const std::shared_ptr<Plugin>& plugin);
std::unique_ptr<GameActions::Result> DukToGameActionResult(const DukValue& d);
DukValue GameActionResultToDuk(const GameAction& action, const std::unique_ptr<GameActions::Result>& result);
[[nodiscard]] std::unique_ptr<GameActions::Result> DukToGameActionResult(const DukValue& d);
[[nodiscard]] DukValue GameActionResultToDuk(
const GameAction& action, const std::unique_ptr<GameActions::Result>& result);
static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType);
static ExpenditureType StringToExpenditureType(std::string_view expenditureType);

View File

@ -78,9 +78,9 @@ enum class TitleScript : uint8_t
constexpr const utf8* TITLE_SEQUENCE_EXTENSION = ".parkseq";
constexpr uint8_t SAVE_INDEX_INVALID = UINT8_MAX;
std::unique_ptr<TitleSequence> CreateTitleSequence();
std::unique_ptr<TitleSequence> LoadTitleSequence(const std::string& path);
std::unique_ptr<TitleSequenceParkHandle> TitleSequenceGetParkHandle(const TitleSequence& seq, size_t index);
[[nodiscard]] std::unique_ptr<TitleSequence> CreateTitleSequence();
[[nodiscard]] std::unique_ptr<TitleSequence> LoadTitleSequence(const std::string& path);
[[nodiscard]] std::unique_ptr<TitleSequenceParkHandle> TitleSequenceGetParkHandle(const TitleSequence& seq, size_t index);
bool TitleSequenceSave(const TitleSequence& seq);
bool TitleSequenceAddPark(TitleSequence& seq, const utf8* path, const utf8* name);

View File

@ -138,7 +138,7 @@ namespace OpenRCT2
virtual void SetKeysPressed(uint32_t keysym, uint8_t scancode) abstract;
// Drawing
virtual std::shared_ptr<Drawing::IDrawingEngineFactory> GetDrawingEngineFactory() abstract;
[[nodiscard]] virtual std::shared_ptr<Drawing::IDrawingEngineFactory> GetDrawingEngineFactory() abstract;
virtual void DrawWeatherAnimation(
OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, rct_drawpixelinfo* dpi,
OpenRCT2::Drawing::DrawWeatherFunc drawFunc) abstract;
@ -158,6 +158,6 @@ namespace OpenRCT2
virtual ITitleSequencePlayer* GetTitleSequencePlayer() abstract;
};
std::shared_ptr<IUiContext> CreateDummyUiContext();
[[nodiscard]] std::shared_ptr<IUiContext> CreateDummyUiContext();
} // namespace Ui
} // namespace OpenRCT2

View File

@ -242,10 +242,10 @@ using CLEAR_FUNC = int32_t (*)(TileElement** tile_element, const CoordsXY& coord
int32_t map_place_non_scenery_clear_func(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money32* price);
int32_t map_place_scenery_clear_func(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money32* price);
std::unique_ptr<GameActions::ConstructClearResult> MapCanConstructWithClearAt(
[[nodiscard]] std::unique_ptr<GameActions::ConstructClearResult> MapCanConstructWithClearAt(
const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags,
uint8_t crossingMode = CREATE_CROSSING_MODE_NONE, bool isTree = false);
std::unique_ptr<GameActions::ConstructClearResult> MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl);
[[nodiscard]] std::unique_ptr<GameActions::ConstructClearResult> MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl);
struct tile_element_iterator
{

View File

@ -118,56 +118,64 @@ TEST_F(SawyerCodingTest, invalid1)
{
OpenRCT2::MemoryStream ms(invalid1, sizeof(invalid1));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid2)
{
OpenRCT2::MemoryStream ms(invalid2, sizeof(invalid2));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid3)
{
OpenRCT2::MemoryStream ms(invalid3, sizeof(invalid3));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid4)
{
OpenRCT2::MemoryStream ms(invalid4, sizeof(invalid4));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid5)
{
OpenRCT2::MemoryStream ms(invalid5, sizeof(invalid5));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid6)
{
OpenRCT2::MemoryStream ms(invalid6, sizeof(invalid6));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, invalid7)
{
OpenRCT2::MemoryStream ms(invalid7, sizeof(invalid7));
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), SawyerChunkException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException);
}
TEST_F(SawyerCodingTest, empty)
{
OpenRCT2::MemoryStream ms(empty, 0);
SawyerChunkReader reader(&ms);
EXPECT_THROW(reader.ReadChunk(), IOException);
std::shared_ptr<SawyerChunk> ptr;
EXPECT_THROW(ptr = reader.ReadChunk(), IOException);
}
// 1024 bytes of random data