Started work on database handling.
This commit is contained in:
@@ -101,29 +101,73 @@ namespace ehs
|
||||
return from * 57.295779513082320876798154814105;
|
||||
}
|
||||
|
||||
template <typename T = float>
|
||||
static T Exp(const T x)
|
||||
{
|
||||
T sum = 1;
|
||||
T term = 1;
|
||||
|
||||
for (int n = 1; n <= 20; ++n)
|
||||
{
|
||||
term *= x / n;
|
||||
sum += term;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
template <typename T = float>
|
||||
static T Ln(T x)
|
||||
{
|
||||
if (x <= 0)
|
||||
return -1;
|
||||
|
||||
T result = 0;
|
||||
|
||||
x = (x - 1) / (x + 1);
|
||||
|
||||
for (int i = 1; i <= 19; i += 2)
|
||||
result += (1 / i) * Exp<T>(x * i);
|
||||
|
||||
return 2 * result;
|
||||
}
|
||||
|
||||
/// A method for use of exponents.
|
||||
/// @tparam T The data type to return;
|
||||
/// @tparam I The data type to use as the exponent.
|
||||
/// @param [in] from The value to use the exponent on.
|
||||
/// @param [in] of The exponent.
|
||||
/// @returns The result.
|
||||
template<typename T = float, typename I = UInt_64>
|
||||
static T Pow(const T from, const I of)
|
||||
template<typename T = float, typename I = float>
|
||||
static T Pow(const T base, const I exponent)
|
||||
{
|
||||
if (of < 0)
|
||||
{
|
||||
if (from == 0)
|
||||
return -0;
|
||||
if (base == 0)
|
||||
return 0;
|
||||
|
||||
return 1 / (from * Pow<T>(from, (-of) - 1));
|
||||
}
|
||||
if (exponent == 0)
|
||||
return 1;
|
||||
|
||||
if (of == 0)
|
||||
return 1;
|
||||
else if (of == 1)
|
||||
return from;
|
||||
UInt_32 exponentIsInteger = exponent == (UInt_32)exponent;
|
||||
UInt_32 baseIsNegative = base < 0;
|
||||
|
||||
return from * Pow<T>(from, of - 1);
|
||||
if (baseIsNegative && exponentIsInteger)
|
||||
{
|
||||
T result = Exp<T>(exponent * Ln<T>(-base));
|
||||
if (Mod((float)exponent, 2.0f) != 0)
|
||||
result = -result;
|
||||
|
||||
return result;
|
||||
}
|
||||
else if (!baseIsNegative)
|
||||
return Exp<T>(exponent * Ln<T>(base));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T = float>
|
||||
static T Log10(const T x)
|
||||
{
|
||||
return Ln<T>(x) / Ln<T>(10);
|
||||
}
|
||||
|
||||
static float Near(const float from);
|
||||
|
@@ -1078,8 +1078,8 @@ namespace ehs
|
||||
bool sizeKnown = size;
|
||||
|
||||
if (!sizeKnown)
|
||||
while (&data[offset + sizeof(T) * size])
|
||||
size++;
|
||||
while (((T*)&data[offset])[size])
|
||||
++size;
|
||||
|
||||
Str<T, O> result(size);
|
||||
|
||||
@@ -1090,14 +1090,14 @@ namespace ehs
|
||||
else
|
||||
for (N i = 0; i < size; ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b];
|
||||
((Byte*)&result[i])[b] = data[offset + sizeof(T) * i + b];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endianness == Endianness::LE)
|
||||
for (N i = 0; i < size; ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b];
|
||||
((Byte*)&result[i])[b] = data[offset + sizeof(T) * i + b];
|
||||
else
|
||||
Util::Copy(&result[0], &data[offset], result.Size(true));
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/OS.h"
|
||||
#include "ehs/system/Architecture.h"
|
||||
|
||||
#define EHS_MAX_PATH 0x104
|
||||
#define EHS_UINT_8_MAX 0xFF
|
||||
@@ -25,6 +26,12 @@
|
||||
#define EHS_LDOUBLE_MAX 1.79769e+308
|
||||
#define EHS_LDOUBLE_MIN 2.22507e-308
|
||||
|
||||
#if defined(EHS_64_BIT)
|
||||
#define EHS_SIZE_MAX 0xFFFFFFFFFFFFFFFF
|
||||
#elif defined(EHS_32_BIT)
|
||||
#define EHS_SIZE_MAX 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
#define EHS_INFINITE EHS_UINT_32_MAX
|
||||
|
||||
namespace ehs
|
||||
@@ -52,4 +59,10 @@ namespace ehs
|
||||
typedef signed long SInt_64;
|
||||
typedef long Int_64;
|
||||
#endif
|
||||
|
||||
#if defined(EHS_64_BIT)
|
||||
typedef UInt_64 Size;
|
||||
#elif defined(EHS_32_BIT)
|
||||
typedef UInt_32 Size;
|
||||
#endif
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class DType : UInt_8
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class DVar : public BaseObj
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
};
|
||||
}
|
36
include/ehs/db/Database.h
Normal file
36
include/ehs/db/Database.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "DbTable.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Database
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Array<DbTable> tables;
|
||||
|
||||
public:
|
||||
Database();
|
||||
|
||||
Database(const Str_8& filePath);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
bool HasTable(UInt_64 hashId) const;
|
||||
|
||||
bool HasTable(Str_8& id) const;
|
||||
|
||||
bool CreateTable(Str_8 id);
|
||||
|
||||
DbTable* GetTable(UInt_64 hashId) const;
|
||||
|
||||
DbTable* GetTable(Str_8& id) const;
|
||||
|
||||
void Save();
|
||||
};
|
||||
}
|
47
include/ehs/db/DbObject.h
Normal file
47
include/ehs/db/DbObject.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "DbVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbTable;
|
||||
|
||||
class DbObject
|
||||
{
|
||||
private:
|
||||
friend class DbTable;
|
||||
|
||||
UInt_64 id;
|
||||
Array<DbVar> vars;
|
||||
bool loaded;
|
||||
DbTable* parent;
|
||||
|
||||
public:
|
||||
DbObject();
|
||||
|
||||
DbObject(DbObject&& obj) noexcept;
|
||||
|
||||
DbObject(const DbObject& obj);
|
||||
|
||||
DbObject& operator=(DbObject&& obj) noexcept;
|
||||
|
||||
DbObject& operator=(const DbObject& obj);
|
||||
|
||||
UInt_64 GetId();
|
||||
|
||||
bool HasVariable(UInt_64 hashId);
|
||||
|
||||
DbVar* GetVariable(UInt_64 hashId) const;
|
||||
|
||||
void Save();
|
||||
|
||||
void Load();
|
||||
|
||||
bool IsLoaded() const;
|
||||
|
||||
void Free();
|
||||
|
||||
DbTable* GetParent() const;
|
||||
};
|
||||
}
|
36
include/ehs/db/DbTable.h
Normal file
36
include/ehs/db/DbTable.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Version.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "DbVarTmpl.h"
|
||||
#include "DbObject.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbTable
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Version version;
|
||||
Array<DbVarTmpl> varTmpls;
|
||||
Array<DbObject> objects;
|
||||
|
||||
public:
|
||||
DbTable();
|
||||
|
||||
DbTable();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
Version GetVersion() const;
|
||||
|
||||
bool CreateVariable(Str_8 id, DbType type);
|
||||
|
||||
bool CreateVariable(Str_8 id, DbType type, UInt_64 size);
|
||||
|
||||
void Save();
|
||||
};
|
||||
}
|
26
include/ehs/db/DbType.h
Normal file
26
include/ehs/db/DbType.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class DbType : UInt_8
|
||||
{
|
||||
SINT_64,
|
||||
UINT_64,
|
||||
SINT_32,
|
||||
UINT_32,
|
||||
SINT_16,
|
||||
UINT_16,
|
||||
SINT_8,
|
||||
UINT_8,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
BOOLEAN,
|
||||
CHAR_32,
|
||||
CHAR_16,
|
||||
CHAR_8
|
||||
};
|
||||
|
||||
constexpr UInt_8 DbTypeToSize(DbType type);
|
||||
}
|
37
include/ehs/db/DbVar.h
Normal file
37
include/ehs/db/DbVar.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbVar
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
UInt_64 size;
|
||||
Byte* data;
|
||||
|
||||
public:
|
||||
~DbVar();
|
||||
|
||||
DbVar();
|
||||
|
||||
DbVar(UInt_64 hashId, UInt_64 size, Byte* data);
|
||||
|
||||
DbVar(DbVar&& var) noexcept;
|
||||
|
||||
DbVar(const DbVar& var);
|
||||
|
||||
DbVar& operator=(DbVar&& var) noexcept;
|
||||
|
||||
DbVar& operator=(const DbVar& var);
|
||||
|
||||
explicit operator Byte*() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
Byte* GetData() const;
|
||||
};
|
||||
}
|
45
include/ehs/db/DbVarTmpl.h
Normal file
45
include/ehs/db/DbVarTmpl.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "DbType.h"
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbVarTmpl : public BaseObj
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
DbType type;
|
||||
bool array;
|
||||
|
||||
public:
|
||||
DbVarTmpl();
|
||||
|
||||
DbVarTmpl(Str_8 id, DbType type, bool array);
|
||||
|
||||
DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;
|
||||
|
||||
DbVarTmpl(const DbVarTmpl& varTmpl);
|
||||
|
||||
DbVarTmpl& operator=(DbVarTmpl&& varTmpl) noexcept;
|
||||
|
||||
DbVarTmpl& operator=(const DbVarTmpl& varTmpl);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void SetType(DbType newType);
|
||||
|
||||
DbType GetType() const;
|
||||
|
||||
void SetIsArray(bool value);
|
||||
|
||||
bool IsArray() const;
|
||||
};
|
||||
}
|
48
include/ehs/io/UsbBase.h
Normal file
48
include/ehs/io/UsbBase.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class UsbBase
|
||||
{
|
||||
private:
|
||||
UInt_32 bus;
|
||||
UInt_32 address;
|
||||
|
||||
public:
|
||||
virtual ~UsbBase() = default;
|
||||
|
||||
UsbBase();
|
||||
|
||||
UsbBase(UInt_32 bus, UInt_32 address);
|
||||
|
||||
UsbBase(UsbBase&& usb) noexcept;
|
||||
|
||||
UsbBase(const UsbBase& usb);
|
||||
|
||||
UsbBase& operator=(UsbBase&& usb) noexcept;
|
||||
|
||||
UsbBase& operator=(const UsbBase& usb);
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual bool IsInitialized() const = 0;
|
||||
|
||||
virtual Size Send(const Byte* data, Size size) = 0;
|
||||
|
||||
void BulkSend(const Byte* data, Size size);
|
||||
|
||||
virtual Size Receive(Byte* data, Size size) = 0;
|
||||
|
||||
void BulkReceive(Byte** data, Size* size);
|
||||
|
||||
UInt_32 GetBus() const;
|
||||
|
||||
UInt_32 GetAddress() const;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
34
include/ehs/io/Usb_LNX.h
Normal file
34
include/ehs/io/Usb_LNX.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "UsbBase.h"
|
||||
#include "File.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Usb final : public UsbBase
|
||||
{
|
||||
private:
|
||||
int hdl;
|
||||
|
||||
public:
|
||||
~Usb() override;
|
||||
|
||||
Usb();
|
||||
|
||||
Usb(UInt_32 bus, UInt_32 address);
|
||||
|
||||
Usb(Usb&& usb) noexcept;
|
||||
|
||||
Usb(const Usb& usb);
|
||||
|
||||
Usb& operator=(Usb&& usb) noexcept;
|
||||
|
||||
Usb& operator=(const Usb& usb);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
bool IsInitialized() const override;
|
||||
};
|
||||
}
|
@@ -3,9 +3,11 @@
|
||||
#if defined(_M_AMD64) || defined(_M_X64) || defined(__x86_64__)
|
||||
#define EHS_LITTLE_ENDIAN
|
||||
#define EHS_ARCH_X64
|
||||
#define EHS_64_BIT
|
||||
#elif defined(_M_ARM64) || defined(__aarch64__)
|
||||
#define EHS_LITTLE_ENDIAN
|
||||
#define EHS_LITTLE_ENDIAN
|
||||
#define EHS_ARCH_ARM64
|
||||
#define EHS_64_BIT
|
||||
#else
|
||||
#error Unsupported architecture.
|
||||
#endif
|
Reference in New Issue
Block a user