mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Rename smart pointers
This commit is contained in:
parent
6762cbfded
commit
cd7267d3c3
@ -174,7 +174,7 @@ namespace Driver
|
|||||||
Driver::Driver()
|
Driver::Driver()
|
||||||
{
|
{
|
||||||
SmartCriticalSection(DriverInitLock);
|
SmartCriticalSection(DriverInitLock);
|
||||||
shared_ptr<VirtualFileSystem::File> DriverDirectory = vfs->Open(Config.DriverDirectory);
|
SharedPointer<VirtualFileSystem::File> DriverDirectory = vfs->Open(Config.DriverDirectory);
|
||||||
if (DriverDirectory->Status == VirtualFileSystem::FileStatus::OK)
|
if (DriverDirectory->Status == VirtualFileSystem::FileStatus::OK)
|
||||||
{
|
{
|
||||||
foreach (auto driver in DriverDirectory->node->Children)
|
foreach (auto driver in DriverDirectory->node->Children)
|
||||||
|
@ -111,7 +111,7 @@ namespace Execute
|
|||||||
cwk_path_get_basename(Path, &BaseName, nullptr);
|
cwk_path_get_basename(Path, &BaseName, nullptr);
|
||||||
TaskArchitecture Arch = TaskArchitecture::UnknownArchitecture;
|
TaskArchitecture Arch = TaskArchitecture::UnknownArchitecture;
|
||||||
|
|
||||||
shared_ptr<File> ExFile = vfs->Open(Path);
|
SharedPointer<File> ExFile = vfs->Open(Path);
|
||||||
|
|
||||||
if (ExFile->Status != FileStatus::OK)
|
if (ExFile->Status != FileStatus::OK)
|
||||||
{
|
{
|
||||||
|
@ -154,7 +154,7 @@ namespace Execute
|
|||||||
memcpy((void *)InterpreterPath, (uint8_t *)ElfFile + ItrPhdr.p_offset, 256);
|
memcpy((void *)InterpreterPath, (uint8_t *)ElfFile + ItrPhdr.p_offset, 256);
|
||||||
debug("Interpreter: %s", InterpreterPath);
|
debug("Interpreter: %s", InterpreterPath);
|
||||||
|
|
||||||
shared_ptr<VirtualFileSystem::File> InterpreterFile = vfs->Open(InterpreterPath);
|
SharedPointer<VirtualFileSystem::File> InterpreterFile = vfs->Open(InterpreterPath);
|
||||||
if (InterpreterFile->Status != VirtualFileSystem::FileStatus::OK)
|
if (InterpreterFile->Status != VirtualFileSystem::FileStatus::OK)
|
||||||
warn("Failed to open interpreter file: %s", InterpreterPath);
|
warn("Failed to open interpreter file: %s", InterpreterPath);
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ namespace Execute
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No need to check if it's valid, the GetBinaryType() call above does that. */
|
/* No need to check if it's valid, the GetBinaryType() call above does that. */
|
||||||
shared_ptr<VirtualFileSystem::File> File = vfs->Open(Interpreter);
|
SharedPointer<VirtualFileSystem::File> File = vfs->Open(Interpreter);
|
||||||
|
|
||||||
Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)File->node->Address;
|
Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)File->node->Address;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ namespace Execute
|
|||||||
BinaryType GetBinaryType(char *Path)
|
BinaryType GetBinaryType(char *Path)
|
||||||
{
|
{
|
||||||
BinaryType Type = BinaryType::BinTypeInvalid;
|
BinaryType Type = BinaryType::BinTypeInvalid;
|
||||||
shared_ptr<VirtualFileSystem::File> ExFile = vfs->Open(Path);
|
SharedPointer<VirtualFileSystem::File> ExFile = vfs->Open(Path);
|
||||||
|
|
||||||
if (ExFile->Status == VirtualFileSystem::FileStatus::OK)
|
if (ExFile->Status == VirtualFileSystem::FileStatus::OK)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ namespace Execute
|
|||||||
.Process = nullptr,
|
.Process = nullptr,
|
||||||
.Thread = nullptr};
|
.Thread = nullptr};
|
||||||
|
|
||||||
shared_ptr<VirtualFileSystem::File> ExFile = vfs->Open(Path);
|
SharedPointer<VirtualFileSystem::File> ExFile = vfs->Open(Path);
|
||||||
|
|
||||||
if (ExFile->Status == VirtualFileSystem::FileStatus::OK)
|
if (ExFile->Status == VirtualFileSystem::FileStatus::OK)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ NewLock(VFSLock);
|
|||||||
|
|
||||||
namespace VirtualFileSystem
|
namespace VirtualFileSystem
|
||||||
{
|
{
|
||||||
shared_ptr<char> Virtual::GetPathFromNode(Node *node)
|
SharedPointer<char> Virtual::GetPathFromNode(Node *node)
|
||||||
{
|
{
|
||||||
vfsdbg("GetPathFromNode( Node: \"%s\" )", node->Name);
|
vfsdbg("GetPathFromNode( Node: \"%s\" )", node->Name);
|
||||||
Node *Parent = node;
|
Node *Parent = node;
|
||||||
@ -73,7 +73,7 @@ namespace VirtualFileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a new string for the final path
|
// Allocate a new string for the final path
|
||||||
shared_ptr<char> FinalPath;
|
SharedPointer<char> FinalPath;
|
||||||
FinalPath.reset(new char[Size]);
|
FinalPath.reset(new char[Size]);
|
||||||
|
|
||||||
size_t Offset = 0;
|
size_t Offset = 0;
|
||||||
@ -152,9 +152,9 @@ namespace VirtualFileSystem
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<File> Virtual::ConvertNodeToFILE(Node *node)
|
SharedPointer<File> Virtual::ConvertNodeToFILE(Node *node)
|
||||||
{
|
{
|
||||||
shared_ptr<File> file = make_shared<File>();
|
SharedPointer<File> file = MakeShared<File>();
|
||||||
file->Status = FileStatus::OK;
|
file->Status = FileStatus::OK;
|
||||||
file->node = node;
|
file->node = node;
|
||||||
return file;
|
return file;
|
||||||
@ -256,17 +256,17 @@ namespace VirtualFileSystem
|
|||||||
return FileStatus::NotFound;
|
return FileStatus::NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<char> Virtual::NormalizePath(const char *Path, Node *Parent)
|
SharedPointer<char> Virtual::NormalizePath(const char *Path, Node *Parent)
|
||||||
{
|
{
|
||||||
vfsdbg("NormalizePath( Path: \"%s\" Parent: \"%s\" )", Path, Parent->Name);
|
vfsdbg("NormalizePath( Path: \"%s\" Parent: \"%s\" )", Path, Parent->Name);
|
||||||
char *NormalizedPath = new char[strlen((char *)Path) + 1];
|
char *NormalizedPath = new char[strlen((char *)Path) + 1];
|
||||||
shared_ptr<char> RelativePath;
|
SharedPointer<char> RelativePath;
|
||||||
|
|
||||||
cwk_path_normalize(Path, NormalizedPath, strlen((char *)Path) + 1);
|
cwk_path_normalize(Path, NormalizedPath, strlen((char *)Path) + 1);
|
||||||
|
|
||||||
if (cwk_path_is_relative(NormalizedPath))
|
if (cwk_path_is_relative(NormalizedPath))
|
||||||
{
|
{
|
||||||
shared_ptr<char> ParentPath = GetPathFromNode(Parent);
|
SharedPointer<char> ParentPath = GetPathFromNode(Parent);
|
||||||
size_t PathSize = cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, nullptr, 0);
|
size_t PathSize = cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, nullptr, 0);
|
||||||
RelativePath.reset(new char[PathSize + 1]);
|
RelativePath.reset(new char[PathSize + 1]);
|
||||||
cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, RelativePath.Get(), PathSize + 1);
|
cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, RelativePath.Get(), PathSize + 1);
|
||||||
@ -329,7 +329,7 @@ namespace VirtualFileSystem
|
|||||||
Node *CurrentParent = this->GetParent(Path, Parent);
|
Node *CurrentParent = this->GetParent(Path, Parent);
|
||||||
vfsdbg("Virtual::Create( Path: \"%s\" Parent: \"%s\" )", Path, Parent ? Parent->Name : CurrentParent->Name);
|
vfsdbg("Virtual::Create( Path: \"%s\" Parent: \"%s\" )", Path, Parent ? Parent->Name : CurrentParent->Name);
|
||||||
|
|
||||||
shared_ptr<char> CleanPath = this->NormalizePath(Path, CurrentParent);
|
SharedPointer<char> CleanPath = this->NormalizePath(Path, CurrentParent);
|
||||||
vfsdbg("CleanPath: \"%s\"", CleanPath.Get());
|
vfsdbg("CleanPath: \"%s\"", CleanPath.Get());
|
||||||
|
|
||||||
if (PathExists(CleanPath.Get(), CurrentParent))
|
if (PathExists(CleanPath.Get(), CurrentParent))
|
||||||
@ -392,7 +392,7 @@ namespace VirtualFileSystem
|
|||||||
if (Parent == nullptr)
|
if (Parent == nullptr)
|
||||||
Parent = FileSystemRoot;
|
Parent = FileSystemRoot;
|
||||||
|
|
||||||
shared_ptr<char> CleanPath = this->NormalizePath(Path, Parent);
|
SharedPointer<char> CleanPath = this->NormalizePath(Path, Parent);
|
||||||
vfsdbg("CleanPath: \"%s\"", CleanPath.Get());
|
vfsdbg("CleanPath: \"%s\"", CleanPath.Get());
|
||||||
|
|
||||||
if (!PathExists(CleanPath.Get(), Parent))
|
if (!PathExists(CleanPath.Get(), Parent))
|
||||||
@ -440,10 +440,10 @@ namespace VirtualFileSystem
|
|||||||
FileStatus Virtual::Delete(Node *Path, bool Recursive, Node *Parent) { return Delete(GetPathFromNode(Path).Get(), Recursive, Parent); }
|
FileStatus Virtual::Delete(Node *Path, bool Recursive, Node *Parent) { return Delete(GetPathFromNode(Path).Get(), Recursive, Parent); }
|
||||||
|
|
||||||
/* TODO: REWORK */
|
/* TODO: REWORK */
|
||||||
shared_ptr<File> Virtual::Mount(const char *Path, FileSystemOperations *Operator)
|
SharedPointer<File> Virtual::Mount(const char *Path, FileSystemOperations *Operator)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
shared_ptr<File> file = make_shared<File>();
|
SharedPointer<File> file = MakeShared<File>();
|
||||||
|
|
||||||
if (unlikely(!Operator))
|
if (unlikely(!Operator))
|
||||||
{
|
{
|
||||||
@ -467,7 +467,7 @@ namespace VirtualFileSystem
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStatus Virtual::Unmount(shared_ptr<File> File)
|
FileStatus Virtual::Unmount(SharedPointer<File> File)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(File.Get()))
|
if (unlikely(File.Get()))
|
||||||
@ -476,7 +476,7 @@ namespace VirtualFileSystem
|
|||||||
return FileStatus::OK;
|
return FileStatus::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Virtual::Read(shared_ptr<File> File, size_t Offset, uint8_t *Buffer, size_t Size)
|
size_t Virtual::Read(SharedPointer<File> File, size_t Offset, uint8_t *Buffer, size_t Size)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(!File.Get()))
|
if (unlikely(!File.Get()))
|
||||||
@ -500,7 +500,7 @@ namespace VirtualFileSystem
|
|||||||
return File->node->Operator->Read(File->node, Offset, Size, Buffer);
|
return File->node->Operator->Read(File->node, Offset, Size, Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Virtual::Write(shared_ptr<File> File, size_t Offset, uint8_t *Buffer, size_t Size)
|
size_t Virtual::Write(SharedPointer<File> File, size_t Offset, uint8_t *Buffer, size_t Size)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(!File.Get()))
|
if (unlikely(!File.Get()))
|
||||||
@ -525,7 +525,7 @@ namespace VirtualFileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: CHECK Open */
|
/* TODO: CHECK Open */
|
||||||
shared_ptr<File> Virtual::Open(const char *Path, Node *Parent)
|
SharedPointer<File> Virtual::Open(const char *Path, Node *Parent)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
vfsdbg("Opening %s with parent %s", Path, Parent ? Parent->Name : "(null)");
|
vfsdbg("Opening %s with parent %s", Path, Parent ? Parent->Name : "(null)");
|
||||||
@ -533,7 +533,7 @@ namespace VirtualFileSystem
|
|||||||
|
|
||||||
if (strcmp(Path, ".") == 0)
|
if (strcmp(Path, ".") == 0)
|
||||||
{
|
{
|
||||||
shared_ptr<File> file = make_shared<File>();
|
SharedPointer<File> file = MakeShared<File>();
|
||||||
file->node = Parent;
|
file->node = Parent;
|
||||||
if (unlikely(!file->node))
|
if (unlikely(!file->node))
|
||||||
file->Status = FileStatus::NotFound;
|
file->Status = FileStatus::NotFound;
|
||||||
@ -544,7 +544,7 @@ namespace VirtualFileSystem
|
|||||||
|
|
||||||
if (strcmp(Path, "..") == 0)
|
if (strcmp(Path, "..") == 0)
|
||||||
{
|
{
|
||||||
shared_ptr<File> file = make_shared<File>();
|
SharedPointer<File> file = MakeShared<File>();
|
||||||
|
|
||||||
if (Parent->Parent != nullptr)
|
if (Parent->Parent != nullptr)
|
||||||
file->node = Parent->Parent;
|
file->node = Parent->Parent;
|
||||||
@ -557,9 +557,9 @@ namespace VirtualFileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
Node *CurrentParent = this->GetParent(Path, Parent);
|
Node *CurrentParent = this->GetParent(Path, Parent);
|
||||||
shared_ptr<char> CleanPath = NormalizePath(Path, CurrentParent);
|
SharedPointer<char> CleanPath = NormalizePath(Path, CurrentParent);
|
||||||
|
|
||||||
shared_ptr<File> file = make_shared<File>();
|
SharedPointer<File> file = MakeShared<File>();
|
||||||
/* TODO: Check for other errors */
|
/* TODO: Check for other errors */
|
||||||
|
|
||||||
if (!PathExists(CleanPath.Get(), CurrentParent))
|
if (!PathExists(CleanPath.Get(), CurrentParent))
|
||||||
@ -601,7 +601,7 @@ namespace VirtualFileSystem
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStatus Virtual::Close(shared_ptr<File> File)
|
FileStatus Virtual::Close(SharedPointer<File> File)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(!File.Get()))
|
if (unlikely(!File.Get()))
|
||||||
|
@ -314,7 +314,7 @@ EXTERNC NIF void Main(BootInfo *Info)
|
|||||||
DevFS = vfs->Create("/system/dev", NodeFlags::DIRECTORY);
|
DevFS = vfs->Create("/system/dev", NodeFlags::DIRECTORY);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shared_ptr<File> dev = vfs->Open("/system/dev");
|
SharedPointer<File> dev = vfs->Open("/system/dev");
|
||||||
if (dev->node->Flags != NodeFlags::DIRECTORY)
|
if (dev->node->Flags != NodeFlags::DIRECTORY)
|
||||||
{
|
{
|
||||||
KPrint("\eE85230/system/dev is not a directory! Halting...");
|
KPrint("\eE85230/system/dev is not a directory! Halting...");
|
||||||
@ -328,7 +328,7 @@ EXTERNC NIF void Main(BootInfo *Info)
|
|||||||
MntFS = vfs->Create("/system/mnt", NodeFlags::DIRECTORY);
|
MntFS = vfs->Create("/system/mnt", NodeFlags::DIRECTORY);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shared_ptr<File> mnt = vfs->Open("/system/mnt");
|
SharedPointer<File> mnt = vfs->Open("/system/mnt");
|
||||||
if (mnt->node->Flags != NodeFlags::DIRECTORY)
|
if (mnt->node->Flags != NodeFlags::DIRECTORY)
|
||||||
{
|
{
|
||||||
KPrint("\eE85230/system/mnt is not a directory! Halting...");
|
KPrint("\eE85230/system/mnt is not a directory! Halting...");
|
||||||
@ -342,7 +342,7 @@ EXTERNC NIF void Main(BootInfo *Info)
|
|||||||
ProcFS = vfs->Create("/system/proc", NodeFlags::DIRECTORY);
|
ProcFS = vfs->Create("/system/proc", NodeFlags::DIRECTORY);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shared_ptr<File> proc = vfs->Open("/system/proc", nullptr);
|
SharedPointer<File> proc = vfs->Open("/system/proc", nullptr);
|
||||||
if (proc->node->Flags != NodeFlags::DIRECTORY)
|
if (proc->node->Flags != NodeFlags::DIRECTORY)
|
||||||
{
|
{
|
||||||
KPrint("\eE85230/system/proc is not a directory! Halting...");
|
KPrint("\eE85230/system/proc is not a directory! Halting...");
|
||||||
|
@ -52,7 +52,7 @@ namespace Recovery
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<VirtualFileSystem::File> pcm = vfs->Open(AudioFile);
|
SharedPointer<VirtualFileSystem::File> pcm = vfs->Open(AudioFile);
|
||||||
|
|
||||||
if (pcm->Status != FileStatus::OK)
|
if (pcm->Status != FileStatus::OK)
|
||||||
{
|
{
|
||||||
|
@ -121,9 +121,9 @@ namespace VirtualFileSystem
|
|||||||
Node *FileSystemRoot = nullptr;
|
Node *FileSystemRoot = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<char> GetPathFromNode(Node *node);
|
SharedPointer<char> GetPathFromNode(Node *node);
|
||||||
Node *GetNodeFromPath(const char *Path, Node *Parent = nullptr);
|
Node *GetNodeFromPath(const char *Path, Node *Parent = nullptr);
|
||||||
shared_ptr<File> ConvertNodeToFILE(Node *node);
|
SharedPointer<File> ConvertNodeToFILE(Node *node);
|
||||||
|
|
||||||
Node *GetParent(const char *Path, Node *Parent);
|
Node *GetParent(const char *Path, Node *Parent);
|
||||||
Node *GetRootNode() { return FileSystemRoot; }
|
Node *GetRootNode() { return FileSystemRoot; }
|
||||||
@ -132,7 +132,7 @@ namespace VirtualFileSystem
|
|||||||
Node *GetChild(const char *Name, Node *Parent);
|
Node *GetChild(const char *Name, Node *Parent);
|
||||||
FileStatus RemoveChild(const char *Name, Node *Parent);
|
FileStatus RemoveChild(const char *Name, Node *Parent);
|
||||||
|
|
||||||
shared_ptr<char> NormalizePath(const char *Path, Node *Parent = nullptr);
|
SharedPointer<char> NormalizePath(const char *Path, Node *Parent = nullptr);
|
||||||
bool PathExists(const char *Path, Node *Parent = nullptr);
|
bool PathExists(const char *Path, Node *Parent = nullptr);
|
||||||
Node *CreateRoot(const char *RootName, FileSystemOperations *Operator);
|
Node *CreateRoot(const char *RootName, FileSystemOperations *Operator);
|
||||||
Node *Create(const char *Path, NodeFlags Flag, Node *Parent = nullptr);
|
Node *Create(const char *Path, NodeFlags Flag, Node *Parent = nullptr);
|
||||||
@ -140,14 +140,14 @@ namespace VirtualFileSystem
|
|||||||
FileStatus Delete(const char *Path, bool Recursive = false, Node *Parent = nullptr);
|
FileStatus Delete(const char *Path, bool Recursive = false, Node *Parent = nullptr);
|
||||||
FileStatus Delete(Node *Path, bool Recursive = false, Node *Parent = nullptr);
|
FileStatus Delete(Node *Path, bool Recursive = false, Node *Parent = nullptr);
|
||||||
|
|
||||||
shared_ptr<File> Mount(const char *Path, FileSystemOperations *Operator);
|
SharedPointer<File> Mount(const char *Path, FileSystemOperations *Operator);
|
||||||
FileStatus Unmount(shared_ptr<File> File);
|
FileStatus Unmount(SharedPointer<File> File);
|
||||||
|
|
||||||
size_t Read(shared_ptr<File> File, size_t Offset, uint8_t *Buffer, size_t Size);
|
size_t Read(SharedPointer<File> File, size_t Offset, uint8_t *Buffer, size_t Size);
|
||||||
size_t Write(shared_ptr<File> File, size_t Offset, uint8_t *Buffer, size_t Size);
|
size_t Write(SharedPointer<File> File, size_t Offset, uint8_t *Buffer, size_t Size);
|
||||||
|
|
||||||
shared_ptr<File> Open(const char *Path, Node *Parent = nullptr);
|
SharedPointer<File> Open(const char *Path, Node *Parent = nullptr);
|
||||||
FileStatus Close(shared_ptr<File> File);
|
FileStatus Close(SharedPointer<File> File);
|
||||||
|
|
||||||
Virtual();
|
Virtual();
|
||||||
~Virtual();
|
~Virtual();
|
||||||
|
@ -22,23 +22,23 @@
|
|||||||
* the object is removed, the object is deleted.
|
* the object is removed, the object is deleted.
|
||||||
*
|
*
|
||||||
* Basic Usage:
|
* Basic Usage:
|
||||||
* smart_ptr<char> pointer(new char());
|
* SmartPointer<char> pointer(new char());
|
||||||
* *pointer = 'a';
|
* *pointer = 'a';
|
||||||
* printf("%c", *pointer); // Prints "a"
|
* printf("%c", *pointer); // Prints "a"
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
class smart_ptr
|
class SmartPointer
|
||||||
{
|
{
|
||||||
T *m_RealPointer;
|
T *m_RealPointer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit smart_ptr(T *Pointer = nullptr)
|
explicit SmartPointer(T *Pointer = nullptr)
|
||||||
{
|
{
|
||||||
spdbg("Smart pointer created (%#lx)", m_RealPointer);
|
spdbg("Smart pointer created (%#lx)", m_RealPointer);
|
||||||
m_RealPointer = Pointer;
|
m_RealPointer = Pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
~smart_ptr()
|
~SmartPointer()
|
||||||
{
|
{
|
||||||
spdbg("Smart pointer deleted (%#lx)", m_RealPointer);
|
spdbg("Smart pointer deleted (%#lx)", m_RealPointer);
|
||||||
delete m_RealPointer, m_RealPointer = nullptr;
|
delete m_RealPointer, m_RealPointer = nullptr;
|
||||||
@ -58,22 +58,22 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class auto_ptr
|
class AutoPointer
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class unique_ptr
|
class UniquePointer
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class weak_ptr
|
class WeakPointer
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class shared_ptr
|
class SharedPointer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Counter
|
class Counter
|
||||||
@ -127,7 +127,7 @@ private:
|
|||||||
T *m_RealPointer;
|
T *m_RealPointer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit shared_ptr(T *Pointer = nullptr)
|
explicit SharedPointer(T *Pointer = nullptr)
|
||||||
{
|
{
|
||||||
m_RealPointer = Pointer;
|
m_RealPointer = Pointer;
|
||||||
m_ReferenceCounter = new Counter();
|
m_ReferenceCounter = new Counter();
|
||||||
@ -136,7 +136,7 @@ public:
|
|||||||
(*m_ReferenceCounter)++;
|
(*m_ReferenceCounter)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr(shared_ptr<T> &SPtr)
|
SharedPointer(SharedPointer<T> &SPtr)
|
||||||
{
|
{
|
||||||
spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.m_RealPointer, SPtr.m_ReferenceCounter);
|
spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.m_RealPointer, SPtr.m_ReferenceCounter);
|
||||||
m_RealPointer = SPtr.m_RealPointer;
|
m_RealPointer = SPtr.m_RealPointer;
|
||||||
@ -144,7 +144,7 @@ public:
|
|||||||
(*m_ReferenceCounter)++;
|
(*m_ReferenceCounter)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~shared_ptr()
|
~SharedPointer()
|
||||||
{
|
{
|
||||||
spdbg("[%#lx] Shared pointer destructor called", this);
|
spdbg("[%#lx] Shared pointer destructor called", this);
|
||||||
(*m_ReferenceCounter)--;
|
(*m_ReferenceCounter)--;
|
||||||
@ -211,7 +211,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(shared_ptr<T> &Other)
|
void swap(SharedPointer<T> &Other)
|
||||||
{
|
{
|
||||||
spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)",
|
spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)",
|
||||||
this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter);
|
this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter);
|
||||||
@ -225,42 +225,42 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct remove_reference
|
struct RemoveReference
|
||||||
{
|
{
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct remove_reference<T &>
|
struct RemoveReference<T &>
|
||||||
{
|
{
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct remove_reference<T &&>
|
struct RemoveReference<T &&>
|
||||||
{
|
{
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using remove_reference_t = typename remove_reference<T>::type;
|
using RemoveReference_t = typename RemoveReference<T>::type;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T &&forward(remove_reference_t<T> &t)
|
T &&forward(RemoveReference_t<T> &t)
|
||||||
{
|
{
|
||||||
return static_cast<T &&>(t);
|
return static_cast<T &&>(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T &&forward(remove_reference_t<T> &&t)
|
T &&forward(RemoveReference_t<T> &&t)
|
||||||
{
|
{
|
||||||
return static_cast<T &&>(t);
|
return static_cast<T &&>(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
shared_ptr<T> make_shared(Args &&...args)
|
SharedPointer<T> MakeShared(Args &&...args)
|
||||||
{
|
{
|
||||||
return shared_ptr<T>(new T(forward<Args>(args)...));
|
return SharedPointer<T>(new T(forward<Args>(args)...));
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !__FENNIX_KERNEL_SMART_POINTER_H__
|
#endif // !__FENNIX_KERNEL_SMART_POINTER_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user