Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/Platform.Memory/ArrayMemory.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Platform::Memory
{
template <typename ...> class ArrayMemory;
template <typename TElement> class ArrayMemory<TElement> : public IArrayMemory<TElement>
template <typename TElement> class ArrayMemory<TElement> : public Polymorph<ArrayMemory<TElement>, IArrayMemory<TElement>>
{
private: std::vector<TElement> _array{};

Expand Down
6 changes: 3 additions & 3 deletions cpp/Platform.Memory/DirectMemoryAsArrayMemoryAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
template <typename ...> class DirectMemoryAsArrayMemoryAdapter;
template <typename TElement> class DirectMemoryAsArrayMemoryAdapter<TElement> :
public IArrayMemory<TElement>, public IDirectMemory
public Polymorph<DirectMemoryAsArrayMemoryAdapter<TElement>, IArrayMemory<TElement>, IDirectMemory>
{
using Self = DirectMemoryAsArrayMemoryAdapter<TElement>;
using IDirectMemory::pointer_t;
Expand All @@ -14,12 +14,12 @@
return _memory.Size();
}

public: pointer_t& Pointer()
public: IDirectMemory::pointer_t& Pointer()
{
return _memory.Pointer();
}

public: const pointer_t& Pointer() const
public: const IDirectMemory::pointer_t& Pointer() const
{
return _memory.Pointer();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/Platform.Memory/FileArrayMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
};

template <typename ...> class FileArrayMemory;
template <typename TElement> class FileArrayMemory<TElement> final : public IArrayMemory<TElement>
template <typename TElement> class FileArrayMemory<TElement> final : public Polymorph<FileArrayMemory<TElement>, IArrayMemory<TElement>>
//where TElement : struct
{
using Self = FileArrayMemory<TElement>;
Expand Down
2 changes: 1 addition & 1 deletion cpp/Platform.Memory/FileMappedResizableDirectMemory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Platform::Memory
{
class FileMappedResizableDirectMemory final : public ResizableDirectMemoryBase
class FileMappedResizableDirectMemory final : public Polymorph<FileMappedResizableDirectMemory, ResizableDirectMemoryBase>
{
using base = ResizableDirectMemoryBase;
protected: using base::capacity_t;
Expand Down
2 changes: 1 addition & 1 deletion cpp/Platform.Memory/HeapResizableDirectMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
}

class HeapResizableDirectMemory final : public ResizableDirectMemoryBase
class HeapResizableDirectMemory final : public Polymorph<HeapResizableDirectMemory, ResizableDirectMemoryBase>
{
using ResizableDirectMemoryBase::capacity_t;
//protected: override std::string ObjectName
Expand Down
1 change: 1 addition & 0 deletions cpp/Platform.Memory/Platform.Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "memory_mapped_file.hpp"
#include "memory_mapped_file.cpp"

#include "Polymorph.h"
#include "IMemory.h"
#include "IDirectMemory.h"
#include "IArrayMemory.h"
Expand Down
18 changes: 18 additions & 0 deletions cpp/Platform.Memory/Polymorph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Platform::Memory
{
template <typename TSelf, typename... TBase>
class Polymorph : public TBase...
{
public:
// Optional static polymorphism - allows getting the derived type
TSelf& self() { return static_cast<TSelf&>(*this); }
const TSelf& self() const { return static_cast<const TSelf&>(*this); }

// Enable perfect forwarding to derived class methods
template<typename T = TSelf>
T& as() { return static_cast<T&>(*this); }

template<typename T = TSelf>
const T& as() const { return static_cast<const T&>(*this); }
};
}
4 changes: 3 additions & 1 deletion cpp/Platform.Memory/ResizableDirectMemoryBase.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Platform::Memory
#include <type_traits>

namespace Platform::Memory
{
namespace Internal
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Platform::Memory
{
class TemporaryFileMappedResizableDirectMemory final : public ResizableDirectMemoryBase
class TemporaryFileMappedResizableDirectMemory final : public Polymorph<TemporaryFileMappedResizableDirectMemory, ResizableDirectMemoryBase>
{
using base_t = FileMappedResizableDirectMemory;
base_t base;
Expand Down
Loading