Add CPP api for dqn file and lock

This commit is contained in:
Doyle Thai 2017-06-24 11:00:44 +10:00
parent 45bc637773
commit 886425eaa3

50
dqn.h
View File

@ -998,6 +998,14 @@ typedef struct DqnFile
u32 permissionFlags; u32 permissionFlags;
void *handle; void *handle;
size_t size; size_t size;
#if defined(DQN_CPP_MODE)
bool Open (char const *const path, const u32 permissionFlags_, const enum DqnFileAction action);
bool OpenW(wchar_t const *const path, const u32 permissionFlags_, const enum DqnFileAction action);
size_t Write(u8 *const buffer, const size_t numBytesToWrite, const size_t fileOffset);
size_t Read (u8 *const buffer, const size_t numBytesToRead);
void Close();
#endif
} DqnFile; } DqnFile;
// NOTE: W(ide) versions of functions only work on Win32, since Unix is UTF-8 compatible. // NOTE: W(ide) versions of functions only work on Win32, since Unix is UTF-8 compatible.
@ -1055,6 +1063,13 @@ DQN_FILE_SCOPE f64 DqnTimer_NowInS ();
typedef struct DqnLock typedef struct DqnLock
{ {
CRITICAL_SECTION win32Handle; CRITICAL_SECTION win32Handle;
#if defined(DQN_CPP_MODE)
bool Init(const u32 spinCount = 16000);
void Acquire();
void Release();
void Delete();
#endif
} DqnLock; } DqnLock;
DQN_FILE_SCOPE bool DqnLock_Init (DqnLock *const lock, const u32 spinCount = 16000); DQN_FILE_SCOPE bool DqnLock_Init (DqnLock *const lock, const u32 spinCount = 16000);
@ -5490,6 +5505,33 @@ void DqnIni_PropertyValueSet(DqnIni *ini, int section, int property,
#include <dirent.h> // readdir()/opendir()/closedir() #include <dirent.h> // readdir()/opendir()/closedir()
#endif #endif
////////////////////////////////////////////////////////////////////////////////
// XPlatform > #DqnFileInternal CPP Implementation
////////////////////////////////////////////////////////////////////////////////
bool DqnFile::Open(char const *const path, const u32 permissionFlags_,
const enum DqnFileAction action)
{
return DqnFile_Open(path, this, permissionFlags, action);
}
bool DqnFile::OpenW(wchar_t const *const path, const u32 permissionFlags_,
const enum DqnFileAction action)
{
return DqnFile_OpenW(path, this, permissionFlags, action);
}
size_t DqnFile::Write(u8 *const buffer, const size_t numBytesToWrite, const size_t fileOffset)
{
return DqnFile_Write(this, buffer, numBytesToWrite, fileOffset);
}
size_t DqnFile::Read(u8 *const buffer, const size_t numBytesToRead)
{
return DqnFile_Read(*this, buffer, numBytesToRead);
}
void DqnFile::Close() { DqnFile_Close(this); }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// XPlatform > #DqnFileInternal Implementation // XPlatform > #DqnFileInternal Implementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -6055,6 +6097,14 @@ void DqnLock_Delete(DqnLock *const lock)
#endif #endif
} }
////////////////////////////////////////////////////////////////////////////////
// Win32Platform > #DqnLock CPP Implementation
////////////////////////////////////////////////////////////////////////////////
bool DqnLock::Init(const u32 spinCount) { return DqnLock_Init(this, spinCount); }
void DqnLock::Acquire() { DqnLock_Acquire(this); }
void DqnLock::Release() { DqnLock_Release(this); }
void DqnLock::Delete() { DqnLock_Delete (this); }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Win32Platform > #DqnAtomic Implementation // Win32Platform > #DqnAtomic Implementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////