Rename smart pointers

This commit is contained in:
Alex 2023-03-23 01:48:49 +02:00
parent 6762cbfded
commit cd7267d3c3
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
11 changed files with 59 additions and 59 deletions

View File

@ -174,7 +174,7 @@ namespace Driver
Driver::Driver()
{
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)
{
foreach (auto driver in DriverDirectory->node->Children)

View File

@ -111,7 +111,7 @@ namespace Execute
cwk_path_get_basename(Path, &BaseName, nullptr);
TaskArchitecture Arch = TaskArchitecture::UnknownArchitecture;
shared_ptr<File> ExFile = vfs->Open(Path);
SharedPointer<File> ExFile = vfs->Open(Path);
if (ExFile->Status != FileStatus::OK)
{

View File

@ -154,7 +154,7 @@ namespace Execute
memcpy((void *)InterpreterPath, (uint8_t *)ElfFile + ItrPhdr.p_offset, 256);
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)
warn("Failed to open interpreter file: %s", InterpreterPath);

View File

@ -207,7 +207,7 @@ namespace Execute
}
/* 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;

View File

@ -69,7 +69,7 @@ namespace Execute
BinaryType GetBinaryType(char *Path)
{
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)
{

View File

@ -20,7 +20,7 @@ namespace Execute
.Process = nullptr,
.Thread = nullptr};
shared_ptr<VirtualFileSystem::File> ExFile = vfs->Open(Path);
SharedPointer<VirtualFileSystem::File> ExFile = vfs->Open(Path);
if (ExFile->Status == VirtualFileSystem::FileStatus::OK)
{

View File

@ -22,7 +22,7 @@ NewLock(VFSLock);
namespace VirtualFileSystem
{
shared_ptr<char> Virtual::GetPathFromNode(Node *node)
SharedPointer<char> Virtual::GetPathFromNode(Node *node)
{
vfsdbg("GetPathFromNode( Node: \"%s\" )", node->Name);
Node *Parent = node;
@ -73,7 +73,7 @@ namespace VirtualFileSystem
}
// Allocate a new string for the final path
shared_ptr<char> FinalPath;
SharedPointer<char> FinalPath;
FinalPath.reset(new char[Size]);
size_t Offset = 0;
@ -152,9 +152,9 @@ namespace VirtualFileSystem
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->node = node;
return file;
@ -256,17 +256,17 @@ namespace VirtualFileSystem
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);
char *NormalizedPath = new char[strlen((char *)Path) + 1];
shared_ptr<char> RelativePath;
SharedPointer<char> RelativePath;
cwk_path_normalize(Path, NormalizedPath, strlen((char *)Path) + 1);
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);
RelativePath.reset(new char[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);
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());
if (PathExists(CleanPath.Get(), CurrentParent))
@ -392,7 +392,7 @@ namespace VirtualFileSystem
if (Parent == nullptr)
Parent = FileSystemRoot;
shared_ptr<char> CleanPath = this->NormalizePath(Path, Parent);
SharedPointer<char> CleanPath = this->NormalizePath(Path, Parent);
vfsdbg("CleanPath: \"%s\"", CleanPath.Get());
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); }
/* TODO: REWORK */
shared_ptr<File> Virtual::Mount(const char *Path, FileSystemOperations *Operator)
SharedPointer<File> Virtual::Mount(const char *Path, FileSystemOperations *Operator)
{
SmartLock(VFSLock);
shared_ptr<File> file = make_shared<File>();
SharedPointer<File> file = MakeShared<File>();
if (unlikely(!Operator))
{
@ -467,7 +467,7 @@ namespace VirtualFileSystem
return file;
}
FileStatus Virtual::Unmount(shared_ptr<File> File)
FileStatus Virtual::Unmount(SharedPointer<File> File)
{
SmartLock(VFSLock);
if (unlikely(File.Get()))
@ -476,7 +476,7 @@ namespace VirtualFileSystem
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);
if (unlikely(!File.Get()))
@ -500,7 +500,7 @@ namespace VirtualFileSystem
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);
if (unlikely(!File.Get()))
@ -525,7 +525,7 @@ namespace VirtualFileSystem
}
/* TODO: CHECK Open */
shared_ptr<File> Virtual::Open(const char *Path, Node *Parent)
SharedPointer<File> Virtual::Open(const char *Path, Node *Parent)
{
SmartLock(VFSLock);
vfsdbg("Opening %s with parent %s", Path, Parent ? Parent->Name : "(null)");
@ -533,7 +533,7 @@ namespace VirtualFileSystem
if (strcmp(Path, ".") == 0)
{
shared_ptr<File> file = make_shared<File>();
SharedPointer<File> file = MakeShared<File>();
file->node = Parent;
if (unlikely(!file->node))
file->Status = FileStatus::NotFound;
@ -544,7 +544,7 @@ namespace VirtualFileSystem
if (strcmp(Path, "..") == 0)
{
shared_ptr<File> file = make_shared<File>();
SharedPointer<File> file = MakeShared<File>();
if (Parent->Parent != nullptr)
file->node = Parent->Parent;
@ -557,9 +557,9 @@ namespace VirtualFileSystem
}
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 */
if (!PathExists(CleanPath.Get(), CurrentParent))
@ -601,7 +601,7 @@ namespace VirtualFileSystem
return file;
}
FileStatus Virtual::Close(shared_ptr<File> File)
FileStatus Virtual::Close(SharedPointer<File> File)
{
SmartLock(VFSLock);
if (unlikely(!File.Get()))

View File

@ -314,7 +314,7 @@ EXTERNC NIF void Main(BootInfo *Info)
DevFS = vfs->Create("/system/dev", NodeFlags::DIRECTORY);
else
{
shared_ptr<File> dev = vfs->Open("/system/dev");
SharedPointer<File> dev = vfs->Open("/system/dev");
if (dev->node->Flags != NodeFlags::DIRECTORY)
{
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);
else
{
shared_ptr<File> mnt = vfs->Open("/system/mnt");
SharedPointer<File> mnt = vfs->Open("/system/mnt");
if (mnt->node->Flags != NodeFlags::DIRECTORY)
{
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);
else
{
shared_ptr<File> proc = vfs->Open("/system/proc", nullptr);
SharedPointer<File> proc = vfs->Open("/system/proc", nullptr);
if (proc->node->Flags != NodeFlags::DIRECTORY)
{
KPrint("\eE85230/system/proc is not a directory! Halting...");

View File

@ -52,7 +52,7 @@ namespace Recovery
return;
}
shared_ptr<VirtualFileSystem::File> pcm = vfs->Open(AudioFile);
SharedPointer<VirtualFileSystem::File> pcm = vfs->Open(AudioFile);
if (pcm->Status != FileStatus::OK)
{

View File

@ -121,9 +121,9 @@ namespace VirtualFileSystem
Node *FileSystemRoot = nullptr;
public:
shared_ptr<char> GetPathFromNode(Node *node);
SharedPointer<char> GetPathFromNode(Node *node);
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 *GetRootNode() { return FileSystemRoot; }
@ -132,7 +132,7 @@ namespace VirtualFileSystem
Node *GetChild(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);
Node *CreateRoot(const char *RootName, FileSystemOperations *Operator);
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(Node *Path, bool Recursive = false, Node *Parent = nullptr);
shared_ptr<File> Mount(const char *Path, FileSystemOperations *Operator);
FileStatus Unmount(shared_ptr<File> File);
SharedPointer<File> Mount(const char *Path, FileSystemOperations *Operator);
FileStatus Unmount(SharedPointer<File> File);
size_t Read(shared_ptr<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 Read(SharedPointer<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);
FileStatus Close(shared_ptr<File> File);
SharedPointer<File> Open(const char *Path, Node *Parent = nullptr);
FileStatus Close(SharedPointer<File> File);
Virtual();
~Virtual();

View File

@ -22,23 +22,23 @@
* the object is removed, the object is deleted.
*
* Basic Usage:
* smart_ptr<char> pointer(new char());
* SmartPointer<char> pointer(new char());
* *pointer = 'a';
* printf("%c", *pointer); // Prints "a"
*/
template <class T>
class smart_ptr
class SmartPointer
{
T *m_RealPointer;
public:
explicit smart_ptr(T *Pointer = nullptr)
explicit SmartPointer(T *Pointer = nullptr)
{
spdbg("Smart pointer created (%#lx)", m_RealPointer);
m_RealPointer = Pointer;
}
~smart_ptr()
~SmartPointer()
{
spdbg("Smart pointer deleted (%#lx)", m_RealPointer);
delete m_RealPointer, m_RealPointer = nullptr;
@ -58,22 +58,22 @@ public:
};
template <class T>
class auto_ptr
class AutoPointer
{
};
template <class T>
class unique_ptr
class UniquePointer
{
};
template <class T>
class weak_ptr
class WeakPointer
{
};
template <typename T>
class shared_ptr
class SharedPointer
{
private:
class Counter
@ -127,7 +127,7 @@ private:
T *m_RealPointer;
public:
explicit shared_ptr(T *Pointer = nullptr)
explicit SharedPointer(T *Pointer = nullptr)
{
m_RealPointer = Pointer;
m_ReferenceCounter = new Counter();
@ -136,7 +136,7 @@ public:
(*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);
m_RealPointer = SPtr.m_RealPointer;
@ -144,7 +144,7 @@ public:
(*m_ReferenceCounter)++;
}
~shared_ptr()
~SharedPointer()
{
spdbg("[%#lx] Shared pointer destructor called", this);
(*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)",
this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter);
@ -225,42 +225,42 @@ public:
};
template <typename T>
struct remove_reference
struct RemoveReference
{
typedef T type;
};
template <typename T>
struct remove_reference<T &>
struct RemoveReference<T &>
{
typedef T type;
};
template <typename T>
struct remove_reference<T &&>
struct RemoveReference<T &&>
{
typedef T type;
};
template <typename T>
using remove_reference_t = typename remove_reference<T>::type;
using RemoveReference_t = typename RemoveReference<T>::type;
template <typename T>
T &&forward(remove_reference_t<T> &t)
T &&forward(RemoveReference_t<T> &t)
{
return static_cast<T &&>(t);
};
template <typename T>
T &&forward(remove_reference_t<T> &&t)
T &&forward(RemoveReference_t<T> &&t)
{
return static_cast<T &&>(t);
};
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__