summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-01-14 01:13:55 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-01-14 01:13:55 +0000
commit4eb6fa4b66ec4698843b950812833785da1aed2e (patch)
treeeddf54e77ca13f38547488f534ea468bb2b3b837 /Common/interface
parentFixed bug in File2Include utility not handling lines without \n at the end (diff)
downloadDiligentCore-4eb6fa4b66ec4698843b950812833785da1aed2e.tar.gz
DiligentCore-4eb6fa4b66ec4698843b950812833785da1aed2e.zip
Added MemoryFileStream
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/BasicFileStream.h14
-rw-r--r--Common/interface/MemoryFileStream.h67
-rw-r--r--Common/interface/StringDataBlobImpl.h5
3 files changed, 77 insertions, 9 deletions
diff --git a/Common/interface/BasicFileStream.h b/Common/interface/BasicFileStream.h
index 66823214..0835c83c 100644
--- a/Common/interface/BasicFileStream.h
+++ b/Common/interface/BasicFileStream.h
@@ -41,20 +41,20 @@ class BasicFileStream : public ObjectBase<IFileStream>
public:
typedef ObjectBase<IFileStream> TBase;
- BasicFileStream(IReferenceCounters *pRefCounters,
- const Char *Path,
- EFileAccessMode Access = EFileAccessMode::Read);
+ BasicFileStream(IReferenceCounters* pRefCounters,
+ const Char* Path,
+ EFileAccessMode Access = EFileAccessMode::Read);
- virtual void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override;
/// Reads data from the stream
- virtual void Read( IDataBlob *pData )override;
+ virtual void Read( IDataBlob* pData )override;
/// Reads data from the stream
- virtual bool Read( void *Data, size_t BufferSize )override;
+ virtual bool Read( void* Data, size_t Size )override;
/// Writes data to the stream
- virtual bool Write( const void *Data, size_t Size )override;
+ virtual bool Write( const void* Data, size_t Size )override;
virtual size_t GetSize()override;
diff --git a/Common/interface/MemoryFileStream.h b/Common/interface/MemoryFileStream.h
new file mode 100644
index 00000000..6896801a
--- /dev/null
+++ b/Common/interface/MemoryFileStream.h
@@ -0,0 +1,67 @@
+/* Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of the MemoryFileStream class
+
+#include "../../Primitives/interface/FileStream.h"
+#include "../../Primitives/interface/DataBlob.h"
+#include "ObjectBase.h"
+#include "RefCountedObjectImpl.h"
+#include "RefCntAutoPtr.h"
+
+namespace Diligent
+{
+
+/// Memory file stream implementation
+class MemoryFileStream : public ObjectBase<IFileStream>
+{
+public:
+ typedef ObjectBase<IFileStream> TBase;
+
+ MemoryFileStream(IReferenceCounters* pRefCounters,
+ IDataBlob* pData);
+
+ virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override;
+
+ /// Reads data from the stream
+ virtual void Read( IDataBlob* pData )override;
+
+ /// Reads data from the stream
+ virtual bool Read( void* Data, size_t Size )override;
+
+ /// Writes data to the stream
+ virtual bool Write( const void* Data, size_t Size )override;
+
+ virtual size_t GetSize()override;
+
+ virtual bool IsValid()override;
+
+private:
+ RefCntAutoPtr<IDataBlob> m_DataBlob;
+ size_t m_CurrentOffset = 0;
+};
+
+}
diff --git a/Common/interface/StringDataBlobImpl.h b/Common/interface/StringDataBlobImpl.h
index b8dc2690..fba29185 100644
--- a/Common/interface/StringDataBlobImpl.h
+++ b/Common/interface/StringDataBlobImpl.h
@@ -40,8 +40,9 @@ class StringDataBlobImpl : public Diligent::ObjectBase<IDataBlob>
public:
typedef Diligent::ObjectBase<IDataBlob> TBase;
- StringDataBlobImpl( IReferenceCounters* pRefCounters, const String &str ) : TBase(pRefCounters), m_String(str) {}
- StringDataBlobImpl( IReferenceCounters* pRefCounters, String &&str ) : TBase(pRefCounters), m_String( std::move(str) ) {}
+ StringDataBlobImpl( IReferenceCounters* pRefCounters, const char* str ) : TBase(pRefCounters), m_String(str) {}
+ StringDataBlobImpl( IReferenceCounters* pRefCounters, const String& str ) : TBase(pRefCounters), m_String(str) {}
+ StringDataBlobImpl( IReferenceCounters* pRefCounters, String&& str ) : TBase(pRefCounters), m_String( std::move(str) ) {}
IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DataBlob, TBase )