Skip to content

Commit

Permalink
BasicFileStream: added convenience Create method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 4, 2024
1 parent 24b29cd commit fee8fb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Common/interface/BasicFileStream.hpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -34,6 +34,7 @@
#include "../../Primitives/interface/DataBlob.h"
#include "ObjectBase.hpp"
#include "FileWrapper.hpp"
#include "RefCntAutoPtr.hpp"

namespace Diligent
{
Expand All @@ -44,6 +45,8 @@ class BasicFileStream : public ObjectBase<IFileStream>
public:
typedef ObjectBase<IFileStream> TBase;

static RefCntAutoPtr<BasicFileStream> Create(const Char* Path, EFileAccessMode Access = EFileAccessMode::Read);

BasicFileStream(IReferenceCounters* pRefCounters,
const Char* Path,
EFileAccessMode Access = EFileAccessMode::Read);
Expand Down
13 changes: 12 additions & 1 deletion Common/src/BasicFileStream.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -31,6 +31,17 @@
namespace Diligent
{

RefCntAutoPtr<BasicFileStream> 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<BasicFileStream>{MakeNewRCObj<BasicFileStream>()(Path, Access)};
}

BasicFileStream::BasicFileStream(IReferenceCounters* pRefCounters,
const Char* Path,
EFileAccessMode Access /* = EFileAccessMode::Read*/) :
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -83,7 +83,7 @@ void DefaultShaderSourceStreamFactory::CreateInputStream2(const Char*
RefCntAutoPtr<BasicFileStream> pFileStream;
if (FileSystem::FileExists(Path))
{
pFileStream = MakeNewRCObj<BasicFileStream>()(Path, EFileAccessMode::Read);
pFileStream = BasicFileStream::Create(Path, EFileAccessMode::Read);
if (!pFileStream->IsValid())
pFileStream.Release();
}
Expand Down

0 comments on commit fee8fb5

Please sign in to comment.