From fee8fb559c2f0e389b211c15e7c14dbc332b509b Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 3 Nov 2024 19:17:15 -0800 Subject: [PATCH] BasicFileStream: added convenience Create method --- Common/interface/BasicFileStream.hpp | 5 ++++- Common/src/BasicFileStream.cpp | 13 ++++++++++++- .../src/DefaultShaderSourceStreamFactory.cpp | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Common/interface/BasicFileStream.hpp b/Common/interface/BasicFileStream.hpp index 7eb0f199d..8899192cd 100644 --- a/Common/interface/BasicFileStream.hpp +++ b/Common/interface/BasicFileStream.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ #include "../../Primitives/interface/DataBlob.h" #include "ObjectBase.hpp" #include "FileWrapper.hpp" +#include "RefCntAutoPtr.hpp" namespace Diligent { @@ -44,6 +45,8 @@ class BasicFileStream : public ObjectBase public: typedef ObjectBase TBase; + static RefCntAutoPtr Create(const Char* Path, EFileAccessMode Access = EFileAccessMode::Read); + BasicFileStream(IReferenceCounters* pRefCounters, const Char* Path, EFileAccessMode Access = EFileAccessMode::Read); diff --git a/Common/src/BasicFileStream.cpp b/Common/src/BasicFileStream.cpp index f550ff5e9..b9958425e 100644 --- a/Common/src/BasicFileStream.cpp +++ b/Common/src/BasicFileStream.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,17 @@ namespace Diligent { +RefCntAutoPtr BasicFileStream::Create(const Char* Path, EFileAccessMode Access) +{ + if (Path == nullptr || Path[0] == '\0') + { + DEV_ERROR("Path must not be null or empty"); + return {}; + } + + return RefCntAutoPtr{MakeNewRCObj()(Path, Access)}; +} + BasicFileStream::BasicFileStream(IReferenceCounters* pRefCounters, const Char* Path, EFileAccessMode Access /* = EFileAccessMode::Read*/) : diff --git a/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp b/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp index 27a5fed2a..be1242573 100644 --- a/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp +++ b/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -83,7 +83,7 @@ void DefaultShaderSourceStreamFactory::CreateInputStream2(const Char* RefCntAutoPtr pFileStream; if (FileSystem::FileExists(Path)) { - pFileStream = MakeNewRCObj()(Path, EFileAccessMode::Read); + pFileStream = BasicFileStream::Create(Path, EFileAccessMode::Read); if (!pFileStream->IsValid()) pFileStream.Release(); }