mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-15 22:57:12 +02:00
Dumped the old implementation. Started with a more simple approach.
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
#include "Library/Datetime.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Datetime(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_DATETIME_HPP_
|
||||
#define _LIBRARY_DATETIME_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_DATETIME_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/FileIO.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_FileIO(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_FILEIO_HPP_
|
||||
#define _LIBRARY_FILEIO_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_FILEIO_HPP_
|
@ -1,167 +0,0 @@
|
||||
#include "Library/Format.hpp"
|
||||
#include "Register.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <format.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const SQChar * GetTypeName(SQObjectType type_id)
|
||||
{
|
||||
switch (type_id)
|
||||
{
|
||||
case OT_INTEGER:
|
||||
return _SC("integer");
|
||||
case OT_FLOAT:
|
||||
return _SC("float");
|
||||
case OT_STRING:
|
||||
return _SC("string");
|
||||
case OT_BOOL:
|
||||
return _SC("boolean");
|
||||
case OT_USERPOINTER:
|
||||
return _SC("user pointer");
|
||||
case OT_NULL:
|
||||
return _SC("null");
|
||||
case OT_TABLE:
|
||||
return _SC("table");
|
||||
case OT_ARRAY:
|
||||
return _SC("array");
|
||||
case OT_CLOSURE:
|
||||
return _SC("closure");
|
||||
case OT_NATIVECLOSURE:
|
||||
return _SC("native closure");
|
||||
case OT_GENERATOR:
|
||||
return _SC("generator");
|
||||
case OT_USERDATA:
|
||||
return _SC("user data");
|
||||
case OT_THREAD:
|
||||
return _SC("thread");
|
||||
case OT_CLASS:
|
||||
return _SC("class");
|
||||
case OT_INSTANCE:
|
||||
return _SC("instance");
|
||||
case OT_WEAKREF:
|
||||
return _SC("weak reference");
|
||||
default:
|
||||
return _SC("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args)
|
||||
{
|
||||
if (sq_gettype(vm, arg) == OT_STRING)
|
||||
{
|
||||
const SQChar * str = 0;
|
||||
sq_getstring(vm, arg, &str);
|
||||
return GetFormatStr(vm, (str == NULL ? "" : str), ++arg, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Expecting format string but got: %s", GetTypeName(sq_gettype(vm, arg)));
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args)
|
||||
{
|
||||
using namespace fmt::internal;
|
||||
|
||||
String str;
|
||||
|
||||
if (args-arg > 15)
|
||||
{
|
||||
LogErr("Too many arguments to format");
|
||||
return str;
|
||||
}
|
||||
else if (fstr.empty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
else if (arg == args)
|
||||
{
|
||||
// Unnecessary but should throw an error when trying to format something without arguments
|
||||
try
|
||||
{
|
||||
str = fmt::format(fstr);
|
||||
}
|
||||
catch (const fmt::SystemError & e)
|
||||
{
|
||||
LogErr(e.what());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
const SQChar * sval = 0;
|
||||
SQInteger ival;
|
||||
SQFloat fval;
|
||||
SQUserPointer pval;
|
||||
|
||||
std::vector< MakeValue< SQChar > > vlist;
|
||||
vlist.reserve(args-arg);
|
||||
std::uint64_t vtype = 0x0;
|
||||
|
||||
for (unsigned sh = 0;arg <= args; arg++, sh += 4)
|
||||
{
|
||||
switch(sq_gettype(vm, arg))
|
||||
{
|
||||
case OT_INTEGER:
|
||||
sq_getinteger(vm, arg, &ival);
|
||||
vlist.emplace_back(ival);
|
||||
vtype |= (MakeValue< SQChar >::type(ival) << sh);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
sq_getfloat(vm, arg, &fval);
|
||||
vlist.emplace_back(fval);
|
||||
vtype |= (MakeValue< SQChar >::type(fval) << sh);
|
||||
break;
|
||||
case OT_STRING:
|
||||
sq_getstring(vm, arg, &sval);
|
||||
vlist.emplace_back(sval);
|
||||
vtype |= (MakeValue< SQChar >::type(sval) << sh);
|
||||
break;
|
||||
case OT_BOOL:
|
||||
sq_getinteger(vm, arg, &ival);
|
||||
vlist.emplace_back(static_cast<unsigned char>(ival));
|
||||
vtype |= (MakeValue< SQChar >::type(static_cast<unsigned char>(ival)) << sh);
|
||||
break;
|
||||
case OT_USERPOINTER:
|
||||
sq_getuserpointer(vm, arg, &pval);
|
||||
vlist.emplace_back(static_cast<void *>(pval));
|
||||
vtype |= (MakeValue< SQChar >::type(static_cast<void *>(pval)) << sh);
|
||||
break;
|
||||
default:
|
||||
LogErr("Cannot format (%s) data type", GetTypeName(sq_gettype(vm, arg)));
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
vlist.shrink_to_fit();
|
||||
|
||||
try
|
||||
{
|
||||
fmt::BasicMemoryWriter<SQChar> w;
|
||||
w.write(fstr, fmt::ArgList(vtype, vlist.data()));
|
||||
str = w.c_str();
|
||||
}
|
||||
catch (const fmt::SystemError & e)
|
||||
{
|
||||
LogErr("%s", e.what());
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Format(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_FORMAT_HPP_
|
||||
#define _LIBRARY_FORMAT_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args);
|
||||
String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_FORMAT_HPP_
|
@ -1,5 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Hashing.hpp"
|
||||
#include "Register.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqstdstring.h>
|
||||
@ -29,122 +30,74 @@ template < class T > T BaseHash< T >::Algo;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < class T > static SQInteger HashF(HSQUIRRELVM vm)
|
||||
{
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Are there any arguments on the stack?
|
||||
const Int32 top = sq_gettop(vm);
|
||||
Object ret;
|
||||
if (top <= 1)
|
||||
{
|
||||
LogErr("Attempting to <hash string> without specifying a value");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
// Is there a single string or at least something that can convert to a string on the stack?
|
||||
SqThrow("Missing the hash string");
|
||||
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
|
||||
{
|
||||
// Variable where the resulted string will be retrieved
|
||||
const SQChar * msg = 0;
|
||||
// Attempt to retrieve the specified string from the stack
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &msg)))
|
||||
{
|
||||
LogErr("Unable to <hash string> because : the string cannot be retrieved from the stack");
|
||||
// Pop any pushed values pushed to the stack
|
||||
sq_settop(vm, top);
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
CCStr str = 0;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
|
||||
SqThrow("Unable to retrieve the string");
|
||||
else
|
||||
{
|
||||
// Pop any pushed values pushed to the stack
|
||||
sq_settop(vm, top);
|
||||
// Hash the specified string
|
||||
sq_pushstring(vm, BaseHash< T >::Algo(msg).c_str(), -1);
|
||||
}
|
||||
ret = MakeObject(vm, BaseHash< T >::Algo(str));
|
||||
sq_settop(vm, top);
|
||||
}
|
||||
else if (top > 2)
|
||||
{
|
||||
// Variables containing the resulted string
|
||||
SQChar * msg = NULL;
|
||||
CStr str = NULL;
|
||||
SQInteger len = 0;
|
||||
// Attempt to call the format function with the passed arguments
|
||||
if (SQ_FAILED(sqstd_format(vm, 2, &len, &msg)))
|
||||
{
|
||||
LogErr("Unable to <hash string> because : %s", Error::Message(vm).c_str());
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
|
||||
SqThrow("Unable to generate the string [%s]", Error::Message(vm).c_str());
|
||||
else
|
||||
{
|
||||
// Pop any pushed values pushed to the stack
|
||||
sq_settop(vm, top);
|
||||
// Hash the specified string
|
||||
sq_pushstring(vm, BaseHash< T >::Algo(msg).c_str(), -1);
|
||||
}
|
||||
ret = MakeObject(vm, BaseHash< T >::Algo(str));
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Unable to <extract the log message> from the specified value");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
// At this point everything went correctly (probably)
|
||||
SqThrow("Unable to extract the hash string");
|
||||
Var< Object >::push(vm, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
template < class T > static bool RegisterWrapper(HSQUIRRELVM vm, const SQChar * cname)
|
||||
template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
|
||||
{
|
||||
// Typedef the reference type to simplify code
|
||||
typedef HashWrapper< T > Hash;
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <%s> type", cname);
|
||||
// Attempt to register the specified type
|
||||
Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Hash >(vm, cname)
|
||||
hashns.Bind(cname, Class< Hash >(hashns.GetVM(), cname)
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
/* Metamethods */
|
||||
.Func(_SC("_tostring"), &Hash::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("hash"), &Hash::GetHash)
|
||||
.Prop(_SC("Hash"), &Hash::GetHash)
|
||||
/* Functions */
|
||||
.Func(_SC("reset"), &Hash::Reset)
|
||||
.Func(_SC("compute"), &Hash::Compute)
|
||||
.Func(_SC("get_hash"), &Hash::GetHash)
|
||||
.Func(_SC("add"), &Hash::AddStr)
|
||||
.Func(_SC("add_str"), &Hash::AddStr)
|
||||
|
||||
.Func(_SC("Reset"), &Hash::Reset)
|
||||
.Func(_SC("Compute"), &Hash::Compute)
|
||||
.Func(_SC("GetHash"), &Hash::GetHash)
|
||||
.Func(_SC("Add"), &Hash::AddStr)
|
||||
.Func(_SC("AddStr"), &Hash::AddStr)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <%s> type was successful", cname);
|
||||
// Registration succeeded
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Hash(HSQUIRRELVM vm)
|
||||
// ================================================================================================
|
||||
void Register_Hash(HSQUIRRELVM vm)
|
||||
{
|
||||
// Attempt to register the hash wrapers
|
||||
if (!RegisterWrapper< CRC32 >(vm, _SC("CHashCRC32")) ||
|
||||
!RegisterWrapper< Keccak >(vm, _SC("CHashKeccak")) ||
|
||||
!RegisterWrapper< MD5 >(vm, _SC("CHashMD5")) ||
|
||||
!RegisterWrapper< SHA1 >(vm, _SC("CHashSHA1")) ||
|
||||
!RegisterWrapper< SHA256 >(vm, _SC("CHashSHA256")) ||
|
||||
!RegisterWrapper< SHA3 >(vm, _SC("CHashSHA3")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <Hashing functions> type");
|
||||
// Attempt to register the free functions
|
||||
Sqrat::RootTable(vm)
|
||||
.SquirrelFunc(_SC("HashCRC32"), &HashF< CRC32 >)
|
||||
.SquirrelFunc(_SC("HashKeccak"), &HashF< Keccak >)
|
||||
.SquirrelFunc(_SC("HashMD5"), &HashF< MD5 >)
|
||||
.SquirrelFunc(_SC("HashSHA1"), &HashF< SHA1 >)
|
||||
.SquirrelFunc(_SC("HashSHA256"), &HashF< SHA256 >)
|
||||
.SquirrelFunc(_SC("HashSHA3"), &HashF< SHA3 >);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <Hashing functions> type was successful");
|
||||
// Registration succeeded
|
||||
return true;
|
||||
Table hashns(vm);
|
||||
|
||||
RegisterWrapper< CRC32 >(hashns, _SC("CRC32"));
|
||||
RegisterWrapper< Keccak >(hashns, _SC("Keccak"));
|
||||
RegisterWrapper< MD5 >(hashns, _SC("MD5"));
|
||||
RegisterWrapper< SHA1 >(hashns, _SC("SHA1"));
|
||||
RegisterWrapper< SHA256 >(hashns, _SC("SHA256"));
|
||||
RegisterWrapper< SHA3 >(hashns, _SC("SHA3"));
|
||||
|
||||
hashns.SquirrelFunc(_SC("GetCRC32"), &HashF< CRC32 >);
|
||||
hashns.SquirrelFunc(_SC("GetKeccak"), &HashF< Keccak >);
|
||||
hashns.SquirrelFunc(_SC("GetMD5"), &HashF< MD5 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA1"), &HashF< SHA1 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA256"), &HashF< SHA256 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA3"), &HashF< SHA3 >);
|
||||
|
||||
RootTable(vm).Bind(_SC("Hash"), hashns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,88 +1,51 @@
|
||||
#ifndef _LIBRARY_CFG_HPP_
|
||||
#define _LIBRARY_CFG_HPP_
|
||||
#ifndef _LIBRARY_HASHING_HPP_
|
||||
#define _LIBRARY_HASHING_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < class T > class HashWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
HashWrapper() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
HashWrapper(const HashWrapper & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
HashWrapper(HashWrapper && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~HashWrapper() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
HashWrapper & operator = (const HashWrapper & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
HashWrapper & operator = (HashWrapper && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
String ToString()
|
||||
// --------------------------------------------------------------------------------------------
|
||||
HashWrapper()
|
||||
: m_Encoder()
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Reset()
|
||||
// --------------------------------------------------------------------------------------------
|
||||
HashWrapper(const HashWrapper & o)
|
||||
: m_Encoder(o.m_Encoder)
|
||||
{
|
||||
m_Encoder.reset();
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
String Compute(const String & str)
|
||||
// --------------------------------------------------------------------------------------------
|
||||
~HashWrapper()
|
||||
{
|
||||
return m_Encoder(str);
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
String GetHash()
|
||||
// --------------------------------------------------------------------------------------------
|
||||
HashWrapper & operator = (const HashWrapper & o)
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
m_Encoder = o.m_Encoder;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
// --------------------------------------------------------------------------------------------
|
||||
String ToString() { return m_Encoder.getHash(); }
|
||||
void Reset() { m_Encoder.reset(); }
|
||||
String Compute(const String & str) { return m_Encoder(str); }
|
||||
String GetHash() { return m_Encoder.getHash(); }
|
||||
void AddStr(const String & str)
|
||||
{
|
||||
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
|
||||
}
|
||||
{ m_Encoder.add(str.data(), str.length() * sizeof(String::value_type)); }
|
||||
|
||||
private:
|
||||
|
||||
@ -92,4 +55,4 @@ private:
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_CFG_HPP_
|
||||
#endif // _LIBRARY_HASHING_HPP_
|
||||
|
@ -1,14 +0,0 @@
|
||||
#include "Library/INI.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_INI(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_INI_HPP_
|
||||
#define _LIBRARY_INI_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_INI_HPP_
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
||||
#include "Library/JSON.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_JSON(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_JSON_HPP_
|
||||
#define _LIBRARY_JSON_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_JSON_HPP_
|
@ -1,62 +0,0 @@
|
||||
#include "Library/LongInt.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_LongInt(HSQUIRRELVM vm)
|
||||
{
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <Long integer> type");
|
||||
// Attempt to register the specified type
|
||||
Sqrat::RootTable(vm).Bind(_SC("SLongInt"), Sqrat::Class< SLongInt >(vm, _SC("SLongInt"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< SLongInt::Type >()
|
||||
.template Ctor< const SQChar *, SQInteger >()
|
||||
/* Properties */
|
||||
.Prop(_SC("str"), &SLongInt::GetCStr, &SLongInt::SetStr)
|
||||
.Prop(_SC("num"), &SLongInt::GetSNum, &SLongInt::SetNum)
|
||||
/* Metamethods */
|
||||
.Func(_SC("_tostring"), &SLongInt::ToString)
|
||||
.Func(_SC("_cmp"), &SLongInt::Cmp)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_div"), &SLongInt::operator /)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_modulo"), &SLongInt::operator %)
|
||||
.Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -)
|
||||
/* Overloads */
|
||||
.Overload< void (SLongInt::*)(void) >(_SC("random"), &SLongInt::Random)
|
||||
.Overload< void (SLongInt::*)(SLongInt::Type, SLongInt::Type) >(_SC("random"), &SLongInt::Random)
|
||||
);
|
||||
// Attempt to register the specified type
|
||||
Sqrat::RootTable(vm).Bind(_SC("ULongInt"), Sqrat::Class< ULongInt >(vm, _SC("ULongInt"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< ULongInt::Type >()
|
||||
.Ctor< const SQChar *, SQInteger >()
|
||||
/* Properties */
|
||||
.Prop(_SC("str"), &ULongInt::GetCStr, &ULongInt::SetStr)
|
||||
.Prop(_SC("num"), &ULongInt::GetSNum, &ULongInt::SetNum)
|
||||
/* Metamethods */
|
||||
.Func(_SC("_tostring"), &ULongInt::ToString)
|
||||
.Func(_SC("_cmp"), &ULongInt::Cmp)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_div"), &ULongInt::operator /)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_modulo"), &ULongInt::operator %)
|
||||
.Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -)
|
||||
/* Overloads */
|
||||
.Overload< void (ULongInt::*)(void) >(_SC("random"), &ULongInt::Random)
|
||||
.Overload< void (ULongInt::*)(ULongInt::Type, ULongInt::Type) >(_SC("random"), &ULongInt::Random)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <IRCSession> type was successful");
|
||||
// Registration succeeded
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,349 +0,0 @@
|
||||
#ifndef _LIBRARY_LONGINT_HPP_
|
||||
#define _LIBRARY_LONGINT_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <stdexcept>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < typename T > class LongInt
|
||||
{
|
||||
public:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static_assert(std::is_integral< T >::value, "LongInt type is not an integral type");
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef T Type;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt()
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
template <typename U> LongInt(U data)
|
||||
{
|
||||
*this = data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt(const SQChar * text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt(const SQChar * text, SQInteger overload)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(overload);
|
||||
*this = text;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt(const LongInt<T> & o)
|
||||
: m_Data(o.m_Data), m_Text(o.m_Text)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt(LongInt<T> && o)
|
||||
: m_Data(o.m_Data), m_Text(std::move(o.m_Text))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~LongInt()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt & operator = (const LongInt<T> & o)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
m_Text = o.m_Text;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt & operator = (LongInt<T> && o)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
m_Text = std::move(o.m_Text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
template <typename U, typename std::enable_if<std::is_integral<U>::value>::type* = nullptr>
|
||||
LongInt & operator = (U data)
|
||||
{
|
||||
m_Data = static_cast< Type >(data);
|
||||
m_Text = std::to_string(m_Data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt & operator = (const SQChar * text)
|
||||
{
|
||||
m_Text = text;
|
||||
try
|
||||
{
|
||||
m_Data = SToI< T >::Fn(text, 0, 10);
|
||||
}
|
||||
catch (const std::invalid_argument & e)
|
||||
{
|
||||
LogErr("Unable to extract number: %s", e.what());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator == (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data == o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator != (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data != o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator < (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data < o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator > (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data > o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator <= (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data <= o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool operator >= (const LongInt<T> & o) const
|
||||
{
|
||||
return (m_Data >= o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
inline operator T () const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator + (const LongInt<T> & o) const
|
||||
{
|
||||
return LongInt<T>(m_Data + o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator - (const LongInt<T> & o) const
|
||||
{
|
||||
return LongInt<T>(m_Data - o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator * (const LongInt<T> & o) const
|
||||
{
|
||||
return LongInt<T>(m_Data * o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator / (const LongInt<T> & o) const
|
||||
{
|
||||
return LongInt<T>(m_Data / o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator % (const LongInt<T> & o) const
|
||||
{
|
||||
return LongInt<T>(m_Data % o.m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
LongInt<T> operator - () const
|
||||
{
|
||||
return LongInt<T>(-m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger Cmp(const LongInt<T> & o) const
|
||||
{
|
||||
if (m_Data == o.m_Data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Data > o.m_Data)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * ToString() const
|
||||
{
|
||||
return m_Text.c_str();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void SetNum(T data)
|
||||
{
|
||||
*this = data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
T GetNum() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
{
|
||||
return static_cast< SQInteger >(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void SetStr(const SQChar * text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const String & GetStr() const
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetCStr() const
|
||||
{
|
||||
return m_Text.c_str();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Random()
|
||||
{
|
||||
m_Data = RandomVal<T>::Get();
|
||||
m_Text = std::to_string(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Random(T min, T max)
|
||||
{
|
||||
m_Data = RandomVal<T>::Get(min, max);
|
||||
m_Text = std::to_string(m_Data);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
T m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
String m_Text;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
typedef LongInt< Int64 > SLongInt;
|
||||
typedef LongInt< Uint64 > ULongInt;
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_LONGINT_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/Math.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Math(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_MATH_HPP_
|
||||
#define _LIBRARY_MATH_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_MATH_HPP_
|
@ -1,14 +1,120 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Numeric.hpp"
|
||||
#include "Register.hpp"
|
||||
#include "Library/Random.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Numeric(HSQUIRRELVM vm)
|
||||
LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text()
|
||||
{ m_Data = strtoll(text, NULL, 10); }
|
||||
LongInt< Int64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text()
|
||||
{ m_Data = strtoll(text, NULL, 10); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Int64 > & LongInt< Int64 >::operator = (CSStr text)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
m_Data = strtoll(text, NULL, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr LongInt< Int64 >::ToString()
|
||||
{
|
||||
if (snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
{
|
||||
m_Text[0] = 0;
|
||||
}
|
||||
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Int64 >::Random() { m_Data = GetRandomInt64(); }
|
||||
void LongInt< Int64 >::Random(Type n) { m_Data = GetRandomInt64(n); }
|
||||
void LongInt< Int64 >::Random(Type m, Type n) { m_Data = GetRandomInt64(m, n); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Uint64 >::LongInt(CSStr text) : m_Data(0), m_Text()
|
||||
{ m_Data = strtoll(text, NULL, 10); }
|
||||
LongInt< Uint64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text()
|
||||
{ m_Data = strtoll(text, NULL, 10); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text)
|
||||
{
|
||||
m_Data = strtoll(text, NULL, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr LongInt< Uint64 >::ToString()
|
||||
{
|
||||
if (snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
{
|
||||
m_Text[0] = 0;
|
||||
}
|
||||
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Uint64 >::Random() { m_Data = GetRandomUint64(); }
|
||||
void LongInt< Uint64 >::Random(Type n) { m_Data = GetRandomUint64(n); }
|
||||
void LongInt< Uint64 >::Random(Type m, Type n) { m_Data = GetRandomUint64(m, n); }
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Numeric(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SLongInt"), Class< SLongInt >(vm, _SC("SLongInt"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< SLongInt::Type >()
|
||||
.template Ctor< CCStr, Object & >()
|
||||
/* Properties */
|
||||
.Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr)
|
||||
.Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum)
|
||||
/* Metamethods */
|
||||
.Func(_SC("_tostring"), &SLongInt::ToString)
|
||||
.Func(_SC("_cmp"), &SLongInt::Cmp)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_div"), &SLongInt::operator /)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_modulo"), &SLongInt::operator %)
|
||||
.Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -)
|
||||
/* Overloads */
|
||||
.Overload< void (SLongInt::*)(void) >(_SC("Random"), &SLongInt::Random)
|
||||
.Overload< void (SLongInt::*)(SLongInt::Type) >(_SC("Random"), &SLongInt::Random)
|
||||
.Overload< void (SLongInt::*)(SLongInt::Type, SLongInt::Type) >(_SC("Random"), &SLongInt::Random)
|
||||
);
|
||||
|
||||
RootTable(vm).Bind(_SC("ULongInt"), Class< ULongInt >(vm, _SC("ULongInt"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< ULongInt::Type >()
|
||||
.Ctor< CCStr, Object & >()
|
||||
/* Properties */
|
||||
.Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr)
|
||||
.Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum)
|
||||
/* Metamethods */
|
||||
.Func(_SC("_tostring"), &ULongInt::ToString)
|
||||
.Func(_SC("_cmp"), &ULongInt::Cmp)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_div"), &ULongInt::operator /)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_modulo"), &ULongInt::operator %)
|
||||
.Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -)
|
||||
/* Overloads */
|
||||
.Overload< void (ULongInt::*)(void) >(_SC("Random"), &ULongInt::Random)
|
||||
.Overload< void (ULongInt::*)(ULongInt::Type) >(_SC("Random"), &ULongInt::Random)
|
||||
.Overload< void (ULongInt::*)(ULongInt::Type, ULongInt::Type) >(_SC("Random"), &ULongInt::Random)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -2,15 +2,440 @@
|
||||
#define _LIBRARY_NUMERIC_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < typename T > class LongInt;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> class LongInt< Int64 >
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Int64 Type;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt()
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
LongInt(Type n)
|
||||
: m_Data(n), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt(CSStr text);
|
||||
LongInt(CSStr text, Object & /* null */);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt(const LongInt< Type > & o)
|
||||
: m_Data(o.m_Data), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
~LongInt()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt & operator = (const LongInt< Type > & o)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > & operator = (Type data)
|
||||
{
|
||||
m_Data = data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > & operator = (CSStr text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
bool operator == (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data == o.m_Data);
|
||||
}
|
||||
|
||||
bool operator != (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data != o.m_Data);
|
||||
}
|
||||
|
||||
bool operator < (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data < o.m_Data);
|
||||
}
|
||||
|
||||
bool operator > (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data > o.m_Data);
|
||||
}
|
||||
|
||||
bool operator <= (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data <= o.m_Data);
|
||||
}
|
||||
|
||||
bool operator >= (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data >= o.m_Data);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
operator Type () const { return m_Data; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > operator + (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data + o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator - (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data - o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator * (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data * o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator / (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data / o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator % (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data % o.m_Data);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > operator - () const
|
||||
{
|
||||
return LongInt< Type >(-m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Type > & o) const
|
||||
{
|
||||
if (m_Data == o.m_Data)
|
||||
return 0;
|
||||
else if (m_Data > o.m_Data)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
CSStr ToString();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void SetNum(Type data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
Type GetNum() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
{
|
||||
return (SQInteger)(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void SetStr(CSStr text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
|
||||
CSStr GetCStr()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void Random();
|
||||
void Random(Type n);
|
||||
void Random(Type m, Type n);
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Type m_Data;
|
||||
SQChar m_Text[32];
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> class LongInt< Uint64 >
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Uint64 Type;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt()
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
LongInt(Type n)
|
||||
: m_Data(n), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt(CSStr text);
|
||||
LongInt(CSStr text, Object & /* null */);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt(const LongInt< Type > & o)
|
||||
: m_Data(o.m_Data), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
~LongInt()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt & operator = (const LongInt< Type > & o)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > & operator = (Type data)
|
||||
{
|
||||
m_Data = data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > & operator = (CSStr text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
bool operator == (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data == o.m_Data);
|
||||
}
|
||||
|
||||
bool operator != (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data != o.m_Data);
|
||||
}
|
||||
|
||||
bool operator < (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data < o.m_Data);
|
||||
}
|
||||
|
||||
bool operator > (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data > o.m_Data);
|
||||
}
|
||||
|
||||
bool operator <= (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data <= o.m_Data);
|
||||
}
|
||||
|
||||
bool operator >= (const LongInt< Type > & o) const
|
||||
{
|
||||
return (m_Data >= o.m_Data);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
operator Type () const { return m_Data; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > operator + (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data + o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator - (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data - o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator * (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data * o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator / (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data / o.m_Data);
|
||||
}
|
||||
|
||||
LongInt< Type > operator % (const LongInt< Type > & o) const
|
||||
{
|
||||
return LongInt< Type >(m_Data % o.m_Data);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt< Type > operator - () const
|
||||
{
|
||||
return LongInt< Type >(-m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Type > & o) const
|
||||
{
|
||||
if (m_Data == o.m_Data)
|
||||
return 0;
|
||||
else if (m_Data > o.m_Data)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
CSStr ToString();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void SetNum(Type data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
Type GetNum() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
{
|
||||
return (SQInteger)(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void SetStr(CSStr text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
|
||||
CSStr GetCStr()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
void Random();
|
||||
void Random(Type n);
|
||||
void Random(Type m, Type n);
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Type m_Data;
|
||||
SQChar m_Text[32];
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
typedef LongInt< Int64 > SLongInt;
|
||||
typedef LongInt< Uint64 > ULongInt;
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_NUMERIC_HPP_
|
||||
#endif // _LIBRARY_NUMERIC_HPP_
|
||||
|
381
source/Library/Random.cpp
Normal file
381
source/Library/Random.cpp
Normal file
@ -0,0 +1,381 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Random.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <RandomLib/Random.hpp>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
#include <process.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
RandomLib::Random g_RGen;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SizeT GenerateSeed()
|
||||
{
|
||||
Ulong a = clock();
|
||||
Ulong b = time(NULL);
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
Ulong c = _getpid();
|
||||
#else
|
||||
Ulong c = getpid();
|
||||
#endif
|
||||
// Mangle
|
||||
a=a-b; a=a-c; a=a^(c >> 13);
|
||||
b=b-c; b=b-a; b=b^(a << 8);
|
||||
c=c-a; c=c-b; c=c^(b >> 13);
|
||||
a=a-b; a=a-c; a=a^(c >> 12);
|
||||
b=b-c; b=b-a; b=b^(a << 16);
|
||||
c=c-a; c=c-b; c=c^(b >> 5);
|
||||
a=a-b; a=a-c; a=a^(c >> 3);
|
||||
b=b-c; b=b-a; b=b^(a << 10);
|
||||
c=c-a; c=c-b; c=c^(b >> 15);
|
||||
// Return result
|
||||
return c;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom()
|
||||
{
|
||||
g_RGen.Reseed();
|
||||
}
|
||||
|
||||
void ReseedRandom(Uint32 n)
|
||||
{
|
||||
g_RGen.Reseed(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int8 GetRandomInt8()
|
||||
{
|
||||
return g_RGen.Integer< Int8 >();
|
||||
}
|
||||
|
||||
Int8 GetRandomInt8(Int8 n)
|
||||
{
|
||||
return g_RGen.Integer< Int8 >(n);
|
||||
}
|
||||
|
||||
Int8 GetRandomInt8(Int8 m, Int8 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Int8 >(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint8 GetRandomUint8()
|
||||
{
|
||||
return g_RGen.Integer< Uint8 >();
|
||||
}
|
||||
|
||||
Uint8 GetRandomUint8(Uint8 n)
|
||||
{
|
||||
return g_RGen.Integer< Uint8 >(n);
|
||||
}
|
||||
|
||||
Uint8 GetRandomUint8(Uint8 m, Uint8 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Uint8 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int16 GetRandomInt16()
|
||||
{
|
||||
return g_RGen.Integer< Int16 >();
|
||||
}
|
||||
|
||||
Int16 GetRandomInt16(Int16 n)
|
||||
{
|
||||
return g_RGen.Integer< Int16 >(n);
|
||||
}
|
||||
|
||||
Int16 GetRandomInt16(Int16 m, Int16 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Int16 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint16 GetRandomUint16()
|
||||
{
|
||||
return g_RGen.Integer< Uint16 >();
|
||||
}
|
||||
|
||||
Uint16 GetRandomUint16(Uint16 n)
|
||||
{
|
||||
return g_RGen.Integer< Uint16 >(n);
|
||||
}
|
||||
|
||||
Uint16 GetRandomUint16(Uint16 m, Uint16 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Uint16 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetRandomInt32()
|
||||
{
|
||||
return g_RGen.Integer< Int32 >();
|
||||
}
|
||||
|
||||
Int32 GetRandomInt32(Int32 n)
|
||||
{
|
||||
return g_RGen.Integer< Int32 >(n);
|
||||
}
|
||||
|
||||
Int32 GetRandomInt32(Int32 m, Int32 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Int32 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetRandomUint32()
|
||||
{
|
||||
return g_RGen.Integer< Uint32 >();
|
||||
}
|
||||
|
||||
Uint32 GetRandomUint32(Uint32 n)
|
||||
{
|
||||
return g_RGen.Integer< Uint32 >(n);
|
||||
}
|
||||
|
||||
Uint32 GetRandomUint32(Uint32 m, Uint32 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Uint32 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 GetRandomInt64()
|
||||
{
|
||||
return g_RGen.Integer< Int64 >();
|
||||
}
|
||||
|
||||
Int64 GetRandomInt64(Int64 n)
|
||||
{
|
||||
return g_RGen.Integer< Int64 >(n);
|
||||
}
|
||||
|
||||
Int64 GetRandomInt64(Int64 m, Int64 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Int64 >(m, n);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 GetRandomUint64()
|
||||
{
|
||||
return g_RGen.Integer< Uint64 >();
|
||||
}
|
||||
|
||||
Uint64 GetRandomUint64(Uint64 n)
|
||||
{
|
||||
return g_RGen.Integer< Uint64 >(n);
|
||||
}
|
||||
|
||||
Uint64 GetRandomUint64(Uint64 m, Uint64 n)
|
||||
{
|
||||
return g_RGen.IntegerC< Uint64 >(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetRandomFloat32()
|
||||
{
|
||||
static const Float32 m = NumLimit<Int32>::Min, n = NumLimit<Int32>::Max;
|
||||
return (n - m) * (Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX)) + m;
|
||||
}
|
||||
|
||||
Float32 GetRandomFloat32(Float32 n)
|
||||
{
|
||||
return Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX/n);
|
||||
}
|
||||
|
||||
Float32 GetRandomFloat32(Float32 m, Float32 n)
|
||||
{
|
||||
return (n - m) * (Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX)) + m;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float64 GetRandomFloat64()
|
||||
{
|
||||
static const Float64 m = NumLimit<Int32>::Min, n = NumLimit<Int32>::Max;
|
||||
return (n - m) * (Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX)) + m;
|
||||
}
|
||||
|
||||
Float64 GetRandomFloat64(Float64 n)
|
||||
{
|
||||
return Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX/n);
|
||||
}
|
||||
|
||||
Float64 GetRandomFloat64(Float64 m, Float64 n)
|
||||
{
|
||||
return (n - m) * (Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX)) + m;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetRandomString(String & str, String::size_type len)
|
||||
{
|
||||
str.reserve(len+1);
|
||||
str.resize(len);
|
||||
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
|
||||
{
|
||||
*itr = g_RGen.Integer< String::value_type >();
|
||||
}
|
||||
str.push_back(0);
|
||||
}
|
||||
|
||||
void GetRandomString(String & str, String::size_type len, String::value_type n)
|
||||
{
|
||||
str.reserve(len+1);
|
||||
str.resize(len);
|
||||
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
|
||||
{
|
||||
*itr = g_RGen.Integer< String::value_type >(n);
|
||||
}
|
||||
str.push_back(0);
|
||||
}
|
||||
|
||||
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n)
|
||||
{
|
||||
str.reserve(len+1);
|
||||
str.resize(len);
|
||||
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
|
||||
{
|
||||
*itr = g_RGen.IntegerC< String::value_type >(m, n);
|
||||
}
|
||||
str.push_back(0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool GetRandomBool()
|
||||
{
|
||||
return g_RGen.Boolean();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < typename T > static T RandomValue()
|
||||
{
|
||||
return RandomVal< T >::Get();
|
||||
}
|
||||
|
||||
template < typename T > static T RandomValue(T n)
|
||||
{
|
||||
return RandomVal< T >::Get(n);
|
||||
}
|
||||
|
||||
template < typename T > static T RandomValue(T m, T n)
|
||||
{
|
||||
return RandomVal< T >::Get(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static CSStr RandomString(Int32 len)
|
||||
{
|
||||
if (len <= 0)
|
||||
{
|
||||
return _SC("");
|
||||
}
|
||||
Buffer b(len+1);
|
||||
SStr s = b.Get< SQChar >();
|
||||
for (Int32 n = 0; n <= len; ++n, ++s)
|
||||
{
|
||||
*s = g_RGen.Integer< SQChar >();
|
||||
}
|
||||
b.At< SQChar >(len) = 0;
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static CSStr RandomString(Int32 len, SQChar n)
|
||||
{
|
||||
if (len <= 0)
|
||||
{
|
||||
return _SC("");
|
||||
}
|
||||
Buffer b(len+1);
|
||||
SStr s = b.Get< SQChar >();
|
||||
for (Int32 n = 0; n <= len; ++n, ++s)
|
||||
{
|
||||
*s = g_RGen.Integer< SQChar >(n);
|
||||
}
|
||||
b.At< SQChar >(len) = 0;
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static CSStr RandomString(Int32 len, SQChar m, SQChar n)
|
||||
{
|
||||
if (len <= 0)
|
||||
{
|
||||
return _SC("");
|
||||
}
|
||||
Buffer b(len+1);
|
||||
SStr s = b.Get< SQChar >();
|
||||
for (Int32 n = 0; n <= len; ++n, ++s)
|
||||
{
|
||||
*s = g_RGen.IntegerC< SQChar >(m, n);
|
||||
}
|
||||
b.At< SQChar >(len) = 0;
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool RandomProbI(SQInteger p)
|
||||
{
|
||||
return g_RGen.Prob(p);
|
||||
}
|
||||
|
||||
static bool RandomProbI(SQInteger m, SQInteger n)
|
||||
{
|
||||
return g_RGen.Prob(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool RandomProbF(SQFloat p)
|
||||
{
|
||||
return g_RGen.Prob(p);
|
||||
}
|
||||
|
||||
static bool RandomProbF(SQFloat m, SQFloat n)
|
||||
{
|
||||
return g_RGen.Prob(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Random(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("Random"), Table(vm)
|
||||
.Func(_SC("GenSeed"), &GenerateSeed)
|
||||
.Overload< void (*)(void) >(_SC("Reseed"), &ReseedRandom)
|
||||
.Overload< void (*)(Uint32) >(_SC("Reseed"), &ReseedRandom)
|
||||
.Overload< SQInteger (*)(void) >(_SC("Integer"), &RandomValue< SQInteger >)
|
||||
.Overload< SQInteger (*)(SQInteger) >(_SC("Integer"), &RandomValue< SQInteger >)
|
||||
.Overload< SQInteger (*)(SQInteger, SQInteger) >(_SC("Integer"), &RandomValue< SQInteger >)
|
||||
.Overload< SQFloat (*)(void) >(_SC("Float"), &RandomValue< SQFloat >)
|
||||
.Overload< SQFloat (*)(SQFloat) >(_SC("Float"), &RandomValue< SQFloat >)
|
||||
.Overload< SQFloat (*)(SQFloat, SQFloat) >(_SC("Float"), &RandomValue< SQFloat >)
|
||||
.Overload< CSStr (*)(Int32) >(_SC("String"), &RandomString)
|
||||
.Overload< CSStr (*)(Int32, SQChar) >(_SC("String"), &RandomString)
|
||||
.Overload< CSStr (*)(Int32, SQChar, SQChar) >(_SC("String"), &RandomString)
|
||||
.Func(_SC("Bool"), &GetRandomBool)
|
||||
.Overload< bool (*)(SQInteger) >(_SC("ProbI"), &RandomProbI)
|
||||
.Overload< bool (*)(SQInteger, SQInteger) >(_SC("ProbI"), &RandomProbI)
|
||||
.Overload< bool (*)(SQFloat) >(_SC("ProbF"), &RandomProbF)
|
||||
.Overload< bool (*)(SQFloat, SQFloat) >(_SC("ProbF"), &RandomProbF)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
164
source/Library/Random.hpp
Normal file
164
source/Library/Random.hpp
Normal file
@ -0,0 +1,164 @@
|
||||
#ifndef _LIBRARY_RANDOM_HPP_
|
||||
#define _LIBRARY_RANDOM_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to generate a moderately unique number to be used as a seed for random numbers.
|
||||
*/
|
||||
Uint32 GenerateSeed();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom();
|
||||
void ReseedRandom(Uint32 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int8 GetRandomInt8();
|
||||
Int8 GetRandomInt8(Int8 n);
|
||||
Int8 GetRandomInt8(Int8 m, Int8 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint8 GetRandomUint8();
|
||||
Uint8 GetRandomUint8(Uint8 n);
|
||||
Uint8 GetRandomUint8(Uint8 m, Uint8 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int16 GetRandomInt16();
|
||||
Int16 GetRandomInt16(Int16 n);
|
||||
Int16 GetRandomInt16(Int16 m, Int16 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint16 GetRandomUint16();
|
||||
Uint16 GetRandomUint16(Uint16 n);
|
||||
Uint16 GetRandomUint16(Uint16 m, Uint16 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetRandomInt32();
|
||||
Int32 GetRandomInt32(Int32 n);
|
||||
Int32 GetRandomInt32(Int32 m, Int32 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetRandomUint32();
|
||||
Uint32 GetRandomUint32(Uint32 n);
|
||||
Uint32 GetRandomUint32(Uint32 m, Uint32 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 GetRandomInt64();
|
||||
Int64 GetRandomInt64(Int64 n);
|
||||
Int64 GetRandomInt64(Int64 m, Int64 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 GetRandomUint64();
|
||||
Uint64 GetRandomUint64(Uint64 n);
|
||||
Uint64 GetRandomUint64(Uint64 m, Uint64 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetRandomFloat32();
|
||||
Float32 GetRandomFloat32(Float32 n);
|
||||
Float32 GetRandomFloat32(Float32 m, Float32 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float64 GetRandomFloat64();
|
||||
Float64 GetRandomFloat64(Float64 n);
|
||||
Float64 GetRandomFloat64(Float64 m, Float64 n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetRandomString(String & str, String::size_type len);
|
||||
void GetRandomString(String & str, String::size_type len, String::value_type n);
|
||||
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool GetRandomBool();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename T> struct RandomVal
|
||||
{ /* ... */ };
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int8 >
|
||||
{
|
||||
static inline Int8 Get() { return GetRandomInt8(); }
|
||||
static inline Int8 Get(Int8 n) { return GetRandomInt8(n); }
|
||||
static inline Int8 Get(Int8 m, Int8 n) { return GetRandomInt8(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint8 >
|
||||
{
|
||||
static inline Uint8 Get() { return GetRandomUint8(); }
|
||||
static inline Uint8 Get(Uint8 n) { return GetRandomUint8(n); }
|
||||
static inline Uint8 Get(Uint8 m, Uint8 n) { return GetRandomUint8(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int16 >
|
||||
{
|
||||
static inline Int16 Get() { return GetRandomInt16(); }
|
||||
static inline Int16 Get(Int16 n) { return GetRandomInt16(n); }
|
||||
static inline Int16 Get(Int16 m, Int16 n) { return GetRandomInt16(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint16 >
|
||||
{
|
||||
static inline Uint16 Get() { return GetRandomUint16(); }
|
||||
static inline Uint16 Get(Uint16 n) { return GetRandomUint16(n); }
|
||||
static inline Uint16 Get(Uint16 m, Uint16 n) { return GetRandomUint16(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int32 >
|
||||
{
|
||||
static inline Int32 Get() { return GetRandomInt32(); }
|
||||
static inline Int32 Get(Int32 n) { return GetRandomInt32(n); }
|
||||
static inline Int32 Get(Int32 m, Int32 n) { return GetRandomInt32(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint32 >
|
||||
{
|
||||
static inline Uint32 Get() { return GetRandomUint32(); }
|
||||
static inline Uint32 Get(Uint32 n) { return GetRandomUint32(n); }
|
||||
static inline Uint32 Get(Uint32 m, Uint32 n) { return GetRandomUint32(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int64 >
|
||||
{
|
||||
static inline Int64 Get() { return GetRandomInt64(); }
|
||||
static inline Int64 Get(Int64 n) { return GetRandomInt64(n); }
|
||||
static inline Int64 Get(Int64 m, Int64 n) { return GetRandomInt64(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint64 >
|
||||
{
|
||||
static inline Uint64 Get() { return GetRandomUint64(); }
|
||||
static inline Uint64 Get(Uint64 n) { return GetRandomUint64(n); }
|
||||
static inline Uint64 Get(Uint64 m, Uint64 n) { return GetRandomUint64(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Float32 >
|
||||
{
|
||||
static inline Float32 Get() { return GetRandomFloat32(); }
|
||||
static inline Float32 Get(Float32 n) { return GetRandomFloat32(n); }
|
||||
static inline Float32 Get(Float32 m, Float32 n) { return GetRandomFloat32(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Float64 >
|
||||
{
|
||||
static inline Float64 Get() { return GetRandomFloat64(); }
|
||||
static inline Float64 Get(Float64 n) { return GetRandomFloat64(n); }
|
||||
static inline Float64 Get(Float64 m, Float64 n) { return GetRandomFloat64(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< bool >
|
||||
{
|
||||
static inline bool Get() { return GetRandomBool(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_RANDOM_HPP_
|
@ -1,961 +0,0 @@
|
||||
#include "Library/SQLite/Connection.hpp"
|
||||
#include "Library/SQLite/Statement.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqstdstring.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection()
|
||||
: m_Handle()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path)
|
||||
: Connection(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path, SQInt32 flags)
|
||||
: Connection(path, flags, NULL)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs)
|
||||
: m_Handle(path, flags, vfs)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const Handle & hnd)
|
||||
: m_Handle(hnd)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Connection::Cmp(const Connection & o) const
|
||||
{
|
||||
if (m_Handle == o.m_Handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Handle && (m_Handle->Ptr > o.m_Handle->Ptr))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::ToString() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Path.c_str();
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetGlobalTag() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Tag.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection tag> using an invalid reference");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
void Connection::SetGlobalTag(const SQChar * tag) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Tag.assign(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set connection tag> using an invalid reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SqObj & Connection::GetGlobalData() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection data> using an invalid reference");
|
||||
}
|
||||
|
||||
return NullData();
|
||||
}
|
||||
|
||||
void Connection::SetGlobalData(SqObj & data) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Data = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set connection data> using an invalid reference");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetLocalTag() const
|
||||
{
|
||||
return m_Tag.c_str();
|
||||
}
|
||||
|
||||
void Connection::SetLocalTag(const SQChar * tag)
|
||||
{
|
||||
m_Tag = tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SqObj & Connection::GetLocalData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
void Connection::SetLocalData(SqObj & data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetStatus() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Status;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection status> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetFlags() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection flags> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetPath() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Path.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection file path> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetVFS() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->VFS.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection vfs string> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetErrStr() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle.ErrStr();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection error string> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetErrMsg() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle.ErrMsg();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection error message> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::Exec(const SQChar * str)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
if ((m_Handle->Status = sqlite3_exec(m_Handle, static_cast< const char * >(str), NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <execute database query> because: %s", m_Handle.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
return sqlite3_changes(m_Handle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <execute database query> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::Queue(const SQChar * str)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Queue.emplace(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <queue database query> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::TableExists(const SQChar * name) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
// Create the statement which counts the tables with the specified name
|
||||
Statement stmt(*this, "SELECT count(*) FROM [sqlite_master] WHERE [type]='table' AND [name]=?");
|
||||
// See if the statement could be created
|
||||
if (stmt.IsValid())
|
||||
{
|
||||
// Bind the table name
|
||||
stmt.IndexBindS(1, name);
|
||||
// Attempt to step the statement
|
||||
if (stmt.Step())
|
||||
{
|
||||
LogErr("Unable to <see if table exists> because : the statement could not be stepped");
|
||||
// Return the requested information
|
||||
return (sqlite3_column_int(stmt, 0) == 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Unable to <see if table exists> because : the statement could not be created");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if table exists> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::IsReadOnly() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
const int result = sqlite3_db_readonly(m_Handle, "main");
|
||||
// Verify the result
|
||||
if(result == -1)
|
||||
{
|
||||
LogErr("Unable to <see if database is read only> because : 'main' is not the name of a database on connection");
|
||||
}
|
||||
// Return the result
|
||||
else
|
||||
{
|
||||
return (result != 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database is read only> using an invalid connection: null");
|
||||
}
|
||||
// It's invalid so at least fall-back to read-only
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetAutoCommit() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_get_autocommit(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <see if database has autocommit activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt Connection::GetLastInsertRowID() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_last_insert_rowid(m_Handle)));
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SLongInt(static_cast< SLongInt::Type >(SQMOD_UNKNOWN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetChanges() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_changes(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetTotalChanges() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_total_changes(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database total changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetErrorCode() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_errcode(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database error code> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetExtendedErrorCode() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_extended_errcode(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database extended error code> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetTracing() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Trace;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database has tracing activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetTracing(bool toggle) const
|
||||
{
|
||||
if (m_Handle && m_Handle->Trace != toggle)
|
||||
{
|
||||
if (m_Handle->Trace)
|
||||
{
|
||||
sqlite3_trace(m_Handle, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_trace(m_Handle, &Connection::TraceOutput, NULL);
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <activate database tracing> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetProfiling() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database has profiling activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetProfiling(bool toggle) const
|
||||
{
|
||||
if (m_Handle && m_Handle->Profile != toggle)
|
||||
{
|
||||
if (m_Handle->Profile)
|
||||
{
|
||||
sqlite3_profile(m_Handle, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_profile(m_Handle, &Connection::ProfileOutput, NULL);
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <activate database profiling> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetBusyTimeout(SQInteger millis) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
if ((m_Handle->Status = sqlite3_busy_timeout(m_Handle, millis)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <set database busy timeout> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set database busy timeout> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::InterruptOperation() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
sqlite3_interrupt(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <interrupt database operation> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::ReleaseMemory() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
sqlite3_db_release_memory(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <release database memory> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfCheckedOutLookasideMemorySlots() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapMemoryUsedByPagerCaches() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapMemoryUsedToStoreSchemas() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_SCHEMA_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_STMT_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetPagerCacheHitCount() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_HIT);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetPagerCacheMissCount() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_MISS);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfDirtyCacheEntries() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_WRITE);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfUnresolvedForeignKeys() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_DEFERRED_FKS);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryHitCount(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_HIT, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryMissCountDueToFullMemory(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection Connection::CopyToMemory()
|
||||
{
|
||||
if (m_Handle && !m_Handle->Memory)
|
||||
{
|
||||
// Attempt to open an in-memory database
|
||||
Handle db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
// See if the database could be opened
|
||||
if (!db)
|
||||
{
|
||||
LogErr("Unable to <open in-memory database> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Begin a transaction to replicate the schema of origin database
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "BEGIN", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <begin database schema replication> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to replicate the schema of origin database to the in-memory one
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle,
|
||||
"SELECT [sql] FROM [sqlite_master] WHERE [sql] NOT NULL AND [tbl_name] != 'sqlite_sequence'",
|
||||
&Connection::ProcessDDLRow, db, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <replicate database schema> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database schema replication
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit database schema replication> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to attach the origin database to the in-memory one
|
||||
else if ((db->Status = sqlite3_exec(db, ToStringF("ATTACH DATABASE '%s' as origin",
|
||||
m_Handle->Path.c_str()), NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <attach database origin> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Begin a transaction to replicate the data of origin database
|
||||
else if ((db->Status = sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK))
|
||||
{
|
||||
LogErr("Unable to <begin database data replication> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Attempt to replicate the data of origin database to the in-memory one
|
||||
else if ((db->Status = sqlite3_exec(db, "SELECT [name] FROM [origin.sqlite_master] WHERE [type]='table'",
|
||||
&Connection::ProcessDMLRow, db, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <replicate database data> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database data replication
|
||||
else if ((db->Status = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit database data replication> because : %s", db.ErrMsg());
|
||||
// Attempt to rollback changes from the data copy operation
|
||||
if ((db->Status = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <rollback database data replication> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Attempt to detach the disk origin from in-memory database
|
||||
else if ((db->Status = sqlite3_exec(db, "DETACH DATABASE origin", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <detach database origin> because : %s", db.ErrMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return the new in-memory database
|
||||
return db;
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <copy database to memory> using an invalid connection: null");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <copy database to memory> for a database which is already in memory");
|
||||
}
|
||||
// Fall-back to an invalid connection
|
||||
return Connection();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection Connection::CopyToDatabase(const SQChar * path)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
// See if the specified name is valid
|
||||
if (strlen(path) <= 0)
|
||||
{
|
||||
LogWrn("Attempting to <replicate database> using an invalid path: null");
|
||||
}
|
||||
// Attempt to open the specified database
|
||||
Handle db(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
// See if the database could be opened
|
||||
if (!db)
|
||||
{
|
||||
LogErr("Unable to <open the specified database> because : %s", db.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to take snapshot of the database
|
||||
TakeSnapshot(db);
|
||||
// Return the database clone
|
||||
return db;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <replicate database> using an invalid connection: null");
|
||||
}
|
||||
// Fall-back to an invalid connection
|
||||
return Connection();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::TraceOutput(void * ptr, const char * sql)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(ptr);
|
||||
LogInf("SQLite Trace: %s", sql);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(ptr);
|
||||
LogInf("SQLite profile (time: %llu): %s", time, sql);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Connection::ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(columns);
|
||||
|
||||
if(columns_count != 1)
|
||||
{
|
||||
LogErr("Error occurred during DDL: columns != 1");
|
||||
// Operation failed
|
||||
return -1;
|
||||
}
|
||||
// Execute the sql statement in values[0] in the received database connection
|
||||
if(sqlite3_exec(static_cast< sqlite3 * >(db), values[0], NULL, NULL, NULL) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Error occurred during DDL execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
|
||||
}
|
||||
// Operation succeeded
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Connection::ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(columns);
|
||||
|
||||
if(columns_count != 1)
|
||||
{
|
||||
LogErr("Error occurred during DML: columns != 1");
|
||||
// Operation failed
|
||||
return -1;
|
||||
}
|
||||
// Generate the query string with the received values
|
||||
char * sql = sqlite3_mprintf("INSERT INTO main.%q SELECT * FROM origin.%q", values[0], values[0]);
|
||||
// Attempt to execute the generated query string to the received database connection
|
||||
if(sqlite3_exec(static_cast< sqlite3 * >(db), sql, NULL, NULL, NULL) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Error occurred during DML execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
|
||||
}
|
||||
// Free the generated query string
|
||||
sqlite3_free(sql);
|
||||
// Operation succeeded
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::TakeSnapshot(Handle & destination)
|
||||
{
|
||||
// Don't even bother to continue if there's no valid connection handle
|
||||
if (m_Handle && destination)
|
||||
{
|
||||
// Attempt to initialize a backup structure
|
||||
sqlite3_backup * backup = sqlite3_backup_init(destination, "main", m_Handle, "main");
|
||||
// See if the backup structure could be created
|
||||
if(backup)
|
||||
{
|
||||
// -1 to copy the entire source database to the destination
|
||||
if((m_Handle->Status = sqlite3_backup_step(backup, -1)) != SQLITE_DONE)
|
||||
{
|
||||
LogErr("Unable to <copy database source> because: %s", sqlite3_errmsg(destination));
|
||||
}
|
||||
// clean up resources allocated by sqlite3_backup_init()
|
||||
if((m_Handle->Status = sqlite3_backup_finish(backup)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <finalize database backup> because: %s", sqlite3_errmsg(destination));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!destination)
|
||||
{
|
||||
LogWrn("Attempting to <take database snapshot> using an invalid destination: null");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <take database snapshot> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetInfo(int operation, bool highwater, bool reset) const
|
||||
{
|
||||
// Don't even bother to continue if there's no valid connection handle
|
||||
if (m_Handle)
|
||||
{
|
||||
int cur_value;
|
||||
int hiwtr_value;
|
||||
// Attempt to retrieve the specified information
|
||||
if((m_Handle->Status = sqlite3_db_status(m_Handle, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <get database runtime status information> because: %s", sqlite3_errmsg(m_Handle));
|
||||
}
|
||||
// Return what was requested
|
||||
return highwater ? hiwtr_value : cur_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database runtime status information> using an invalid connection: null");
|
||||
}
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Connection::ExecF(HSQUIRRELVM vm)
|
||||
{
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Are there any arguments on the stack?
|
||||
if (top <= 1)
|
||||
{
|
||||
LogErr("Attempting to <execute database query> without specifying a value");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
// Attempt to retrieve the connection instance
|
||||
Var< Connection & > inst(vm, 1);
|
||||
// Validate the connection instance
|
||||
if (!inst.value)
|
||||
{
|
||||
LogErr("Attempting to <execute database query> using an invalid connection: null");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
// Is there a single string or at least something that can convert to a string on the stack?
|
||||
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
|
||||
{
|
||||
// Variable where the resulted string will be retrieved
|
||||
const SQChar * str = 0;
|
||||
// Attempt to retrieve the specified message from the stack
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
|
||||
{
|
||||
LogErr("Unable to <fetch database query> because : the string cannot be retrieved from the stack");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to execute the specified query string and push the result on the stack
|
||||
sq_pushinteger(vm, inst.value.Exec(str));
|
||||
}
|
||||
// Pop any pushed values pushed to the stack
|
||||
sq_settop(vm, top);
|
||||
}
|
||||
else if (top > 2)
|
||||
{
|
||||
// Variables containing the resulted string
|
||||
SQChar * str = NULL;
|
||||
SQInteger len = 0;
|
||||
// Attempt to call the format function with the passed arguments
|
||||
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
|
||||
{
|
||||
LogErr("Unable to <generate database query> because : %s", Error::Message(vm).c_str());
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to execute the resulted query string and push the result on the stack
|
||||
sq_pushinteger(vm, inst.value.Exec(str));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Unable to <extract database query> from the specified value");
|
||||
// Push a null value on the stack
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
// At this point everything went correctly (probably)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Connection::QueueF(HSQUIRRELVM vm)
|
||||
{
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Are there any arguments on the stack?
|
||||
if (top <= 1)
|
||||
{
|
||||
LogErr("Attempting to <queue database query> without specifying a value");
|
||||
}
|
||||
// Attempt to retrieve the connection instance
|
||||
Var< Connection & > inst(vm, 1);
|
||||
// Validate the connection instance
|
||||
if (!inst.value)
|
||||
{
|
||||
LogErr("Attempting to <queue database query> using an invalid connection: null");
|
||||
}
|
||||
// Is there a single string or at least something that can convert to a string on the stack?
|
||||
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
|
||||
{
|
||||
// Variable where the resulted string will be retrieved
|
||||
const SQChar * str = 0;
|
||||
// Attempt to retrieve the specified message from the stack
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
|
||||
{
|
||||
LogErr("Unable to <fetch database query> because : the string cannot be retrieved from the stack");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to queue the specified query string
|
||||
inst.value.Queue(str);
|
||||
}
|
||||
// Pop any pushed values pushed to the stack
|
||||
sq_settop(vm, top);
|
||||
}
|
||||
else if (top > 2)
|
||||
{
|
||||
// Variables containing the resulted string
|
||||
SQChar * str = NULL;
|
||||
SQInteger len = 0;
|
||||
// Attempt to call the format function with the passed arguments
|
||||
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
|
||||
{
|
||||
LogErr("Unable to <generate database query> because : %s", Error::Message(vm).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to queue the specified query string
|
||||
inst.value.Queue(str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Unable to <extract database query> from the specified value");
|
||||
}
|
||||
// At this point everything went correctly (probably)
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
@ -1,447 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_CONNECTION_HPP_
|
||||
#define _LIBRARY_SQLITE_CONNECTION_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to manage a conenction to an SQLite database.
|
||||
*/
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The type of SQLite resource handle that this class uses.
|
||||
*/
|
||||
typedef ConnectionHandle Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
Connection();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Open a connection to a database using the specified path.
|
||||
*/
|
||||
Connection(const SQChar * path);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Open a connection to a database using the specified path and flags.
|
||||
*/
|
||||
Connection(const SQChar * path, SQInt32 flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Open a connection to a database using the specified path, flags and vfs.
|
||||
*/
|
||||
Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct and reference an existing connection.
|
||||
*/
|
||||
Connection(const Handle & hnd);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Connection(const Connection & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Connection(Connection && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Connection() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Connection & operator = (const Connection & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Connection & operator = (Connection && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a handle reference.
|
||||
*/
|
||||
operator const Handle & () const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * ()
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const Connection & o) const
|
||||
{
|
||||
return (m_Handle == o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const Connection & o) const
|
||||
{
|
||||
return (m_Handle != o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script to compare two instances of this type.
|
||||
*/
|
||||
SQInt32 Cmp(const Connection & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Convert this type to a string.
|
||||
*/
|
||||
const SQChar * ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the global tag.
|
||||
*/
|
||||
const SQChar * GetGlobalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the global tag.
|
||||
*/
|
||||
void SetGlobalTag(const SQChar * tag) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the global data.
|
||||
*/
|
||||
SqObj & GetGlobalData() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the global data.
|
||||
*/
|
||||
void SetGlobalData(SqObj & data) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local tag.
|
||||
*/
|
||||
const SQChar * GetLocalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local tag.
|
||||
*/
|
||||
void SetLocalTag(const SQChar * tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local data.
|
||||
*/
|
||||
SqObj & GetLocalData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local data.
|
||||
*/
|
||||
void SetLocalData(SqObj & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the handle reference.
|
||||
*/
|
||||
const Handle & GetHandle() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of active references to this handle.
|
||||
*/
|
||||
SQUint32 GetRefs() const
|
||||
{
|
||||
return m_Handle ? m_Handle.Count() : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the handle reference.
|
||||
*/
|
||||
void Release()
|
||||
{
|
||||
m_Handle.Release();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query.
|
||||
*/
|
||||
bool IsValid() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last received error code.
|
||||
*/
|
||||
SQInt32 GetStatus() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the flags used to create this database connection.
|
||||
*/
|
||||
SQInt32 GetFlags() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the path used to create this database connection.
|
||||
*/
|
||||
const SQChar * GetPath() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the virtual file system used to create this database connection.
|
||||
*/
|
||||
const SQChar * GetVFS() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the message of the last received error code.
|
||||
*/
|
||||
const SQChar * GetErrStr() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the last error message associated with this database connection.
|
||||
*/
|
||||
const SQChar * GetErrMsg() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query.
|
||||
*/
|
||||
SQInt32 Exec(const SQChar * str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to queue the specified query.
|
||||
*/
|
||||
void Queue(const SQChar * str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Shortcut to test if a table exists.
|
||||
*/
|
||||
bool TableExists(const SQChar * name) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the database connection was opened in read-only mode.
|
||||
*/
|
||||
bool IsReadOnly() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the database connection is or is not in autocommit mode.
|
||||
*/
|
||||
bool GetAutoCommit() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the rowid of the most recent successful INSERT into the database from the current connection.
|
||||
*/
|
||||
SLongInt GetLastInsertRowID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of database rows that were changed, inserted or deleted
|
||||
* by the most recently completed SQL statement.
|
||||
*/
|
||||
SQInt32 GetChanges() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the total number of row changes caused by INSERT, UPDATE or DELETE statements
|
||||
* since the database connection was opened.
|
||||
*/
|
||||
SQInt32 GetTotalChanges() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the extended numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetExtendedErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if this database connection has tracing enabled.
|
||||
*/
|
||||
bool GetTracing() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Activate or deactivate tracing on this database connection.
|
||||
*/
|
||||
void SetTracing(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if this database connection has profiling enabled.
|
||||
*/
|
||||
bool GetProfiling() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Activate or deactivate profiling on this database connection.
|
||||
*/
|
||||
void SetProfiling(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set a busy handler that sleeps for a specified amount of time when a table is locked.
|
||||
*/
|
||||
void SetBusyTimeout(SQInteger millis) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Causes any pending database operation to abort and return at its earliest opportunity.
|
||||
*/
|
||||
void InterruptOperation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempts to free as much heap memory as possible from the database connection.
|
||||
*/
|
||||
void ReleaseMemory() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of lookaside memory slots currently checked out.
|
||||
*/
|
||||
SQInt32 GetNumberOfCheckedOutLookasideMemorySlots() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap memory used by all pager caches.
|
||||
*/
|
||||
SQInt32 GetHeapMemoryUsedByPagerCaches() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap memory used to store the schema for
|
||||
* all databases associated with the connection - main, temp, and any ATTACH-ed databases.
|
||||
*/
|
||||
SQInt32 GetHeapMemoryUsedToStoreSchemas() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap and lookaside memory used by all
|
||||
* prepared statements associated with the database connection.
|
||||
*/
|
||||
SQInt32 GetHeapAndLookasideMemoryUsedByPreparedStatements() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of pager cache hits that have occurred.
|
||||
*/
|
||||
SQInt32 GetPagerCacheHitCount() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of pager cache misses that have occurred.
|
||||
*/
|
||||
SQInt32 GetPagerCacheMissCount() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of dirty cache entries that have been written to disk.
|
||||
*/
|
||||
SQInt32 GetNumberOfDirtyCacheEntries() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns zero if all foreign key constraints (deferred or immediate) have been resolved.
|
||||
*/
|
||||
SQInt32 GetNumberOfUnresolvedForeignKeys() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the highest number of lookaside memory slots that has been checked out.
|
||||
*/
|
||||
SQInt32 GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that were satisfied using lookaside memory.
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryHitCount(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that might have been satisfied using lookaside memory.
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that might have been satisfied using lookaside memory
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryMissCountDueToFullMemory(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the whole database into memory.
|
||||
*/
|
||||
Connection CopyToMemory();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Takes a snapshot of a database which is located in memory and saves it to a database file.
|
||||
*/
|
||||
Connection CopyToDatabase(const SQChar * path);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query.
|
||||
*/
|
||||
static SQInteger ExecF(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to queue the specified query.
|
||||
*/
|
||||
static SQInteger QueueF(HSQUIRRELVM vm);
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Callback function for ActivateTracing()
|
||||
*/
|
||||
static void TraceOutput(void * ptr, const char * sql);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Callback function for ActivateProfiling()
|
||||
*/
|
||||
static void ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build and modify the structure of tables and other objects in the memory database.
|
||||
*/
|
||||
static int ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Insert all data from the origin database into the memory database.
|
||||
*/
|
||||
static int ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Takes and saves a snapshot of the memory database in a file.
|
||||
*/
|
||||
void TakeSnapshot(Handle & destination);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns internal runtime status information associated with the current database connection.
|
||||
*/
|
||||
SQInt32 GetInfo(int operation, bool highwater = false, bool reset = false) const;
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reference to the managed SQLite connection handle.
|
||||
*/
|
||||
Handle m_Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local tag associated with this instance.
|
||||
*/
|
||||
SqTag m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local data associated with this instance.
|
||||
*/
|
||||
SqObj m_Data;
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_CONNECTION_HPP_
|
@ -1,676 +0,0 @@
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
#include "Library/SQLite/Connection.hpp"
|
||||
#include "Library/SQLite/Statement.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle()
|
||||
: Hnd(nullptr)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs)
|
||||
: Hnd(new Handle(path, flags, vfs != NULL ? vfs : _SC("")))
|
||||
{
|
||||
// See if a handle could be created
|
||||
if (!Hnd)
|
||||
{
|
||||
LogErr("Attempting to <open database connection> without a valid handle");
|
||||
Drop();
|
||||
}
|
||||
// At least the path must be valid
|
||||
else if (Hnd->Path.empty())
|
||||
{
|
||||
LogErr("Attempting to <open database connection> without a valid path");
|
||||
Drop();
|
||||
}
|
||||
// Attempt to open a connection
|
||||
else if ((Hnd->Status = sqlite3_open_v2(path, &(*Hnd).Ptr, flags, vfs)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <open database> because : %d", sqlite3_errmsg(Hnd->Ptr));
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(const ConnectionHandle & o)
|
||||
: Hnd(o.Hnd)
|
||||
{
|
||||
// Grab a reference to the new handle
|
||||
Grab();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(ConnectionHandle && o)
|
||||
: Hnd(o.Hnd)
|
||||
{
|
||||
// Prevent the other instance from releasing the stolen reference
|
||||
o.Hnd = nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::~ConnectionHandle()
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle & ConnectionHandle::operator = (const ConnectionHandle & o)
|
||||
{
|
||||
// Make sure it's not the same handle instance in both
|
||||
if (Hnd != o.Hnd)
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
// Assign the specified handle
|
||||
Hnd = o.Hnd;
|
||||
// Grab a reference to the new handle
|
||||
Grab();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle & ConnectionHandle::operator = (ConnectionHandle && o)
|
||||
{
|
||||
// Make sure it's not the same handle instance in both
|
||||
if (Hnd != o.Hnd)
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
// Steal the handle reference from the other instance
|
||||
Hnd = o.Hnd;
|
||||
// Prevent the other instance from releasing the stolen reference
|
||||
o.Hnd = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Transaction::Transaction(const Connection & db)
|
||||
: m_Connection(db), m_Commited(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Transaction::~Transaction()
|
||||
{
|
||||
if (!m_Commited && m_Connection)
|
||||
{
|
||||
if ((m_Connection->Status = sqlite3_exec(m_Connection, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <rollback transaction> because: %s", m_Connection.ErrMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Transaction::Commit()
|
||||
{
|
||||
if (!m_Commited && m_Connection)
|
||||
{
|
||||
if ((m_Connection->Status = sqlite3_exec(m_Connection, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit transaction> because: %s", m_Connection.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Commited = true;
|
||||
}
|
||||
}
|
||||
else if (m_Commited)
|
||||
{
|
||||
LogWrn("Attempting to <commit transaction> which was already committed");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <commit transaction> using an invalid connection");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSoftHeapLimit(SQInt32 limit)
|
||||
{
|
||||
sqlite3_soft_heap_limit(limit);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 ReleaseMemory(SQInt32 bytes)
|
||||
{
|
||||
return sqlite3_release_memory(bytes);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt GetMemoryUsage()
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_used()));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt GetMemoryHighwaterMark(bool reset)
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_highwater(reset)));
|
||||
}
|
||||
|
||||
} // Namespace:: SQLite
|
||||
|
||||
// ================================================================================================
|
||||
bool Register_SQLite(HSQUIRRELVM vm)
|
||||
{
|
||||
using namespace SQLite;
|
||||
|
||||
// Attempt to create the SQLite namespace
|
||||
Sqrat::Table sqlns(vm);
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Connection> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Connection"), Sqrat::Class< Connection >(vm, _SC("Connection"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< const SQChar * >()
|
||||
.Ctor< const SQChar *, SQInt32 >()
|
||||
.Ctor< const SQChar *, SQInt32, const SQChar * >()
|
||||
/* Metamethods */
|
||||
.Func(_SC("_cmp"), &Connection::Cmp)
|
||||
.Func(_SC("_tostring"), &Connection::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("gtag"), &Connection::GetGlobalTag, &Connection::SetGlobalTag)
|
||||
.Prop(_SC("gdata"), &Connection::GetGlobalData, &Connection::SetGlobalData)
|
||||
.Prop(_SC("ltag"), &Connection::GetLocalTag, &Connection::SetLocalTag)
|
||||
.Prop(_SC("ldata"), &Connection::GetLocalData, &Connection::SetLocalData)
|
||||
.Prop(_SC("refs"), &Connection::GetRefs)
|
||||
.Prop(_SC("valid"), &Connection::IsValid)
|
||||
.Prop(_SC("connected"), &Connection::IsValid)
|
||||
.Prop(_SC("status"), &Connection::GetStatus)
|
||||
.Prop(_SC("flags"), &Connection::GetFlags)
|
||||
.Prop(_SC("path"), &Connection::GetPath)
|
||||
.Prop(_SC("vfs"), &Connection::GetVFS)
|
||||
.Prop(_SC("err_str"), &Connection::GetErrStr)
|
||||
.Prop(_SC("err_msg"), &Connection::GetErrMsg)
|
||||
.Prop(_SC("read_only"), &Connection::IsReadOnly)
|
||||
.Prop(_SC("auto_commit"), &Connection::GetAutoCommit)
|
||||
.Prop(_SC("last_insert_row_id"), &Connection::GetLastInsertRowID)
|
||||
.Prop(_SC("changes"), &Connection::GetChanges)
|
||||
.Prop(_SC("total_changes"), &Connection::GetTotalChanges)
|
||||
.Prop(_SC("err_code"), &Connection::GetErrorCode)
|
||||
.Prop(_SC("extended_err_code"), &Connection::GetExtendedErrorCode)
|
||||
.Prop(_SC("trace"), &Connection::GetTracing, &Connection::SetTracing)
|
||||
.Prop(_SC("profile"), &Connection::GetProfiling, &Connection::SetProfiling)
|
||||
.Prop(_SC("busy_timeout"), &Connection::SetBusyTimeout)
|
||||
.Prop(_SC("number_of_checked_out_lookaside_memory_slots"), &Connection::GetNumberOfCheckedOutLookasideMemorySlots)
|
||||
.Prop(_SC("heap_memory_used_by_pager_caches"), &Connection::GetHeapMemoryUsedByPagerCaches)
|
||||
.Prop(_SC("heap_memory_used_to_store_schemas"), &Connection::GetHeapMemoryUsedToStoreSchemas)
|
||||
.Prop(_SC("heap_and_lookaside_memory_used_by_prepared_statements"), &Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements)
|
||||
.Prop(_SC("pagercache_hit_count"), &Connection::GetPagerCacheHitCount)
|
||||
.Prop(_SC("pagercache_miss_count"), &Connection::GetPagerCacheMissCount)
|
||||
.Prop(_SC("number_of_dirty_cache_entries"), &Connection::GetNumberOfDirtyCacheEntries)
|
||||
.Prop(_SC("number_of_unresolved_foreign_keys"), &Connection::GetNumberOfUnresolvedForeignKeys)
|
||||
.Prop(_SC("highest_number_of_checked_out_lookaside_memory_slots"), &Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots)
|
||||
.Prop(_SC("lookaside_memory_hit_count"), &Connection::GetLookasideMemoryHitCount)
|
||||
.Prop(_SC("lookaside_memory_miss_count_due_to_small_slot_size"), &Connection::GetLookasideMemoryMissCountDueToSmallSlotSize)
|
||||
.Prop(_SC("lookaside_memory_miss_count_due_to_full_memory"), &Connection::GetLookasideMemoryMissCountDueToFullMemory)
|
||||
/* Functions */
|
||||
.Func(_SC("release"), &Connection::Release)
|
||||
.Func(_SC("exec"), &Connection::Exec)
|
||||
.Func(_SC("queue"), &Connection::Queue)
|
||||
.Func(_SC("table_exists"), &Connection::TableExists)
|
||||
.Func(_SC("interrupt_operation"), &Connection::InterruptOperation)
|
||||
.Func(_SC("release_memory"), &Connection::ReleaseMemory)
|
||||
.Func(_SC("copy_to_memory"), &Connection::CopyToMemory)
|
||||
.Func(_SC("copy_to_database"), &Connection::CopyToDatabase)
|
||||
/* Raw Functions */
|
||||
.SquirrelFunc(_SC("execf"), &Connection::ExecF)
|
||||
.SquirrelFunc(_SC("queuef"), &Connection::QueueF)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Connection> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Statement> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Statement"), Sqrat::Class< Statement, NoCopy< Statement > >(vm, _SC("Statement"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< const Connection &, const SQChar * >()
|
||||
/* Metamethods */
|
||||
.Func(_SC("_cmp"), &Statement::Cmp)
|
||||
.Func(_SC("_tostring"), &Statement::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("ltag"), &Statement::GetLocalTag, &Statement::SetLocalTag)
|
||||
.Prop(_SC("ldata"), &Statement::GetLocalData, &Statement::SetLocalData)
|
||||
.Prop(_SC("valid"), &Statement::IsValid)
|
||||
.Prop(_SC("status"), &Statement::GetStatus)
|
||||
.Prop(_SC("columns"), &Statement::GetColumns)
|
||||
.Prop(_SC("query"), &Statement::GetQuery)
|
||||
.Prop(_SC("err_str"), &Statement::GetErrStr)
|
||||
.Prop(_SC("err_msg"), &Statement::GetErrMsg)
|
||||
.Prop(_SC("connection"), &Statement::GetConnection)
|
||||
.Prop(_SC("good"), &Statement::GetGood)
|
||||
.Prop(_SC("done"), &Statement::GetDone)
|
||||
.Prop(_SC("err_code"), &Statement::GetErrorCode)
|
||||
.Prop(_SC("extended_err_code"), &Statement::GetExtendedErrorCode)
|
||||
/* Functions */
|
||||
.Func(_SC("reset"), &Statement::Reset)
|
||||
.Func(_SC("clear"), &Statement::Clear)
|
||||
.Func(_SC("exec"), &Statement::Exec)
|
||||
.Func(_SC("step"), &Statement::Step)
|
||||
.Func(_SC("ibind_a"), &Statement::IndexBindA)
|
||||
.Func(_SC("ibind_t"), &Statement::IndexBindT)
|
||||
.Func(_SC("ibind_i"), &Statement::IndexBindI)
|
||||
.Func(_SC("ibind_l"), &Statement::IndexBindL)
|
||||
.Func(_SC("ibind_v"), &Statement::IndexBindV)
|
||||
.Func(_SC("ibind_f"), &Statement::IndexBindF)
|
||||
.Func(_SC("ibind_s"), &Statement::IndexBindS)
|
||||
.Func(_SC("ibind_b"), &Statement::IndexBindB)
|
||||
.Func(_SC("ibind_n"), &Statement::IndexBindN)
|
||||
.Func(_SC("nbind_t"), &Statement::NameBindT)
|
||||
.Func(_SC("nbind_i"), &Statement::NameBindI)
|
||||
.Func(_SC("nbind_l"), &Statement::NameBindL)
|
||||
.Func(_SC("nbind_v"), &Statement::NameBindV)
|
||||
.Func(_SC("nbind_f"), &Statement::NameBindF)
|
||||
.Func(_SC("nbind_s"), &Statement::NameBindS)
|
||||
.Func(_SC("nbind_b"), &Statement::NameBindB)
|
||||
.Func(_SC("nbind_n"), &Statement::NameBindN)
|
||||
.Func(_SC("ibind"), &Statement::IndexBind)
|
||||
.Func(_SC("nbind"), &Statement::NameBind)
|
||||
.Func(_SC("fetchi"), &Statement::FetchColumnIndex)
|
||||
.Func(_SC("fetchn"), &Statement::FetchColumnName)
|
||||
.Func(_SC("fetcha"), &Statement::FetchArray)
|
||||
.Func(_SC("fetcht"), &Statement::FetchTable)
|
||||
.Func(_SC("is_column_null"), &Statement::IsColumnNull)
|
||||
.Func(_SC("column_name"), &Statement::GetColumnName)
|
||||
.Func(_SC("column_origin_name"), &Statement::GetColumnOriginName)
|
||||
.Func(_SC("column_type"), &Statement::GetColumnType)
|
||||
.Func(_SC("column_bytes"), &Statement::GetColumnBytes)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Statement> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Transaction> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Transaction"), Sqrat::Class< Transaction, NoCopy< Transaction > >(vm, _SC("Transaction"))
|
||||
/* Constructors */
|
||||
.Ctor< const Connection & >()
|
||||
/* Properties */
|
||||
.Prop(_SC("committed"), &Transaction::Commited)
|
||||
/* Functions */
|
||||
.Func(_SC("commit"), &Transaction::Commit)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Transaction> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite functions> type");
|
||||
// Attempt to register the specified functions
|
||||
sqlns.Func(_SC("set_soft_heap_limit"), &SetSoftHeapLimit);
|
||||
sqlns.Func(_SC("release_memory"), &ReleaseMemory);
|
||||
sqlns.Func(_SC("memory_usage"), &GetMemoryUsage);
|
||||
sqlns.Func(_SC("memory_highwater_mark"), &GetMemoryHighwaterMark);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite functions> type was successful");
|
||||
|
||||
// Attempt to bind the namespace to the root table
|
||||
Sqrat::RootTable(vm).Bind(_SC("SQLite"), sqlns);
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Constants> type");
|
||||
/*
|
||||
// Attempt to register the SQLite constants enumeration
|
||||
Sqrat::ConstTable(vm).Enum(_SC("ESQLITE"), Sqrat::Enumeration(vm)
|
||||
.Const(_SC("ABORT"), SQLITE_ABORT)
|
||||
.Const(_SC("ABORT_ROLLBACK"), SQLITE_ABORT_ROLLBACK)
|
||||
.Const(_SC("ACCESS_EXISTS"), SQLITE_ACCESS_EXISTS)
|
||||
.Const(_SC("ACCESS_READ"), SQLITE_ACCESS_READ)
|
||||
.Const(_SC("ACCESS_READWRITE"), SQLITE_ACCESS_READWRITE)
|
||||
.Const(_SC("ALTER_TABLE"), SQLITE_ALTER_TABLE)
|
||||
.Const(_SC("ANALYZE"), SQLITE_ANALYZE)
|
||||
.Const(_SC("ANY"), SQLITE_ANY)
|
||||
.Const(_SC("ATTACH"), SQLITE_ATTACH)
|
||||
.Const(_SC("AUTH"), SQLITE_AUTH)
|
||||
.Const(_SC("AUTH_USER"), SQLITE_AUTH_USER)
|
||||
.Const(_SC("BLOB"), SQLITE_BLOB)
|
||||
.Const(_SC("BUSY"), SQLITE_BUSY)
|
||||
.Const(_SC("BUSY_RECOVERY"), SQLITE_BUSY_RECOVERY)
|
||||
.Const(_SC("BUSY_SNAPSHOT"), SQLITE_BUSY_SNAPSHOT)
|
||||
.Const(_SC("CANTOPEN"), SQLITE_CANTOPEN)
|
||||
.Const(_SC("CANTOPEN_CONVPATH"), SQLITE_CANTOPEN_CONVPATH)
|
||||
.Const(_SC("CANTOPEN_FULLPATH"), SQLITE_CANTOPEN_FULLPATH)
|
||||
.Const(_SC("CANTOPEN_ISDIR"), SQLITE_CANTOPEN_ISDIR)
|
||||
.Const(_SC("CANTOPEN_NOTEMPDIR"), SQLITE_CANTOPEN_NOTEMPDIR)
|
||||
.Const(_SC("CHECKPOINT_FULL"), SQLITE_CHECKPOINT_FULL)
|
||||
.Const(_SC("CHECKPOINT_PASSIVE"), SQLITE_CHECKPOINT_PASSIVE)
|
||||
.Const(_SC("CHECKPOINT_RESTART"), SQLITE_CHECKPOINT_RESTART)
|
||||
.Const(_SC("CHECKPOINT_TRUNCATE"), SQLITE_CHECKPOINT_TRUNCATE)
|
||||
.Const(_SC("CONFIG_COVERING_INDEX_SCAN"), SQLITE_CONFIG_COVERING_INDEX_SCAN)
|
||||
.Const(_SC("CONFIG_GETMALLOC"), SQLITE_CONFIG_GETMALLOC)
|
||||
.Const(_SC("CONFIG_GETMUTEX"), SQLITE_CONFIG_GETMUTEX)
|
||||
.Const(_SC("CONFIG_GETPCACHE"), SQLITE_CONFIG_GETPCACHE)
|
||||
.Const(_SC("CONFIG_GETPCACHE2"), SQLITE_CONFIG_GETPCACHE2)
|
||||
.Const(_SC("CONFIG_HEAP"), SQLITE_CONFIG_HEAP)
|
||||
.Const(_SC("CONFIG_LOG"), SQLITE_CONFIG_LOG)
|
||||
.Const(_SC("CONFIG_LOOKASIDE"), SQLITE_CONFIG_LOOKASIDE)
|
||||
.Const(_SC("CONFIG_MALLOC"), SQLITE_CONFIG_MALLOC)
|
||||
.Const(_SC("CONFIG_MEMSTATUS"), SQLITE_CONFIG_MEMSTATUS)
|
||||
.Const(_SC("CONFIG_MMAP_SIZE"), SQLITE_CONFIG_MMAP_SIZE)
|
||||
.Const(_SC("CONFIG_MULTITHREAD"), SQLITE_CONFIG_MULTITHREAD)
|
||||
.Const(_SC("CONFIG_MUTEX"), SQLITE_CONFIG_MUTEX)
|
||||
.Const(_SC("CONFIG_PAGECACHE"), SQLITE_CONFIG_PAGECACHE)
|
||||
.Const(_SC("CONFIG_PCACHE"), SQLITE_CONFIG_PCACHE)
|
||||
.Const(_SC("CONFIG_PCACHE2"), SQLITE_CONFIG_PCACHE2)
|
||||
.Const(_SC("CONFIG_PCACHE_HDRSZ"), SQLITE_CONFIG_PCACHE_HDRSZ)
|
||||
.Const(_SC("CONFIG_PMASZ"), SQLITE_CONFIG_PMASZ)
|
||||
.Const(_SC("CONFIG_SCRATCH"), SQLITE_CONFIG_SCRATCH)
|
||||
.Const(_SC("CONFIG_SERIALIZED"), SQLITE_CONFIG_SERIALIZED)
|
||||
.Const(_SC("CONFIG_SINGLETHREAD"), SQLITE_CONFIG_SINGLETHREAD)
|
||||
.Const(_SC("CONFIG_SQLLOG"), SQLITE_CONFIG_SQLLOG)
|
||||
.Const(_SC("CONFIG_URI"), SQLITE_CONFIG_URI)
|
||||
.Const(_SC("CONFIG_WIN32_HEAPSIZE"), SQLITE_CONFIG_WIN32_HEAPSIZE)
|
||||
.Const(_SC("CONSTRAINT"), SQLITE_CONSTRAINT)
|
||||
.Const(_SC("CONSTRAINT_CHECK"), SQLITE_CONSTRAINT_CHECK)
|
||||
.Const(_SC("CONSTRAINT_COMMITHOOK"), SQLITE_CONSTRAINT_COMMITHOOK)
|
||||
.Const(_SC("CONSTRAINT_FOREIGNKEY"), SQLITE_CONSTRAINT_FOREIGNKEY)
|
||||
.Const(_SC("CONSTRAINT_FUNCTION"), SQLITE_CONSTRAINT_FUNCTION)
|
||||
.Const(_SC("CONSTRAINT_NOTNULL"), SQLITE_CONSTRAINT_NOTNULL)
|
||||
.Const(_SC("CONSTRAINT_PRIMARYKEY"), SQLITE_CONSTRAINT_PRIMARYKEY)
|
||||
.Const(_SC("CONSTRAINT_ROWID"), SQLITE_CONSTRAINT_ROWID)
|
||||
.Const(_SC("CONSTRAINT_TRIGGER"), SQLITE_CONSTRAINT_TRIGGER)
|
||||
.Const(_SC("CONSTRAINT_UNIQUE"), SQLITE_CONSTRAINT_UNIQUE)
|
||||
.Const(_SC("CONSTRAINT_VTAB"), SQLITE_CONSTRAINT_VTAB)
|
||||
.Const(_SC("COPY"), SQLITE_COPY)
|
||||
.Const(_SC("CORRUPT"), SQLITE_CORRUPT)
|
||||
.Const(_SC("CORRUPT_VTAB"), SQLITE_CORRUPT_VTAB)
|
||||
.Const(_SC("CREATE_INDEX"), SQLITE_CREATE_INDEX)
|
||||
.Const(_SC("CREATE_TABLE"), SQLITE_CREATE_TABLE)
|
||||
.Const(_SC("CREATE_TEMP_INDEX"), SQLITE_CREATE_TEMP_INDEX)
|
||||
.Const(_SC("CREATE_TEMP_TABLE"), SQLITE_CREATE_TEMP_TABLE)
|
||||
.Const(_SC("CREATE_TEMP_TRIGGER"), SQLITE_CREATE_TEMP_TRIGGER)
|
||||
.Const(_SC("CREATE_TEMP_VIEW"), SQLITE_CREATE_TEMP_VIEW)
|
||||
.Const(_SC("CREATE_TRIGGER"), SQLITE_CREATE_TRIGGER)
|
||||
.Const(_SC("CREATE_VIEW"), SQLITE_CREATE_VIEW)
|
||||
.Const(_SC("CREATE_VTABLE"), SQLITE_CREATE_VTABLE)
|
||||
.Const(_SC("DBCONFIG_ENABLE_FKEY"), SQLITE_DBCONFIG_ENABLE_FKEY)
|
||||
.Const(_SC("DBCONFIG_ENABLE_TRIGGER"), SQLITE_DBCONFIG_ENABLE_TRIGGER)
|
||||
.Const(_SC("DBCONFIG_LOOKASIDE"), SQLITE_DBCONFIG_LOOKASIDE)
|
||||
.Const(_SC("DBSTATUS_CACHE_HIT"), SQLITE_DBSTATUS_CACHE_HIT)
|
||||
.Const(_SC("DBSTATUS_CACHE_MISS"), SQLITE_DBSTATUS_CACHE_MISS)
|
||||
.Const(_SC("DBSTATUS_CACHE_USED"), SQLITE_DBSTATUS_CACHE_USED)
|
||||
.Const(_SC("DBSTATUS_CACHE_WRITE"), SQLITE_DBSTATUS_CACHE_WRITE)
|
||||
.Const(_SC("DBSTATUS_DEFERRED_FKS"), SQLITE_DBSTATUS_DEFERRED_FKS)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_HIT"), SQLITE_DBSTATUS_LOOKASIDE_HIT)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_FULL"), SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_SIZE"), SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_USED"), SQLITE_DBSTATUS_LOOKASIDE_USED)
|
||||
.Const(_SC("DBSTATUS_MAX"), SQLITE_DBSTATUS_MAX)
|
||||
.Const(_SC("DBSTATUS_SCHEMA_USED"), SQLITE_DBSTATUS_SCHEMA_USED)
|
||||
.Const(_SC("DBSTATUS_STMT_USED"), SQLITE_DBSTATUS_STMT_USED)
|
||||
.Const(_SC("DELETE"), SQLITE_DELETE)
|
||||
.Const(_SC("DENY"), SQLITE_DENY)
|
||||
.Const(_SC("DETACH"), SQLITE_DETACH)
|
||||
.Const(_SC("DETERMINISTIC"), SQLITE_DETERMINISTIC)
|
||||
.Const(_SC("DONE"), SQLITE_DONE)
|
||||
.Const(_SC("DROP_INDEX"), SQLITE_DROP_INDEX)
|
||||
.Const(_SC("DROP_TABLE"), SQLITE_DROP_TABLE)
|
||||
.Const(_SC("DROP_TEMP_INDEX"), SQLITE_DROP_TEMP_INDEX)
|
||||
.Const(_SC("DROP_TEMP_TABLE"), SQLITE_DROP_TEMP_TABLE)
|
||||
.Const(_SC("DROP_TEMP_TRIGGER"), SQLITE_DROP_TEMP_TRIGGER)
|
||||
.Const(_SC("DROP_TEMP_VIEW"), SQLITE_DROP_TEMP_VIEW)
|
||||
.Const(_SC("DROP_TRIGGER"), SQLITE_DROP_TRIGGER)
|
||||
.Const(_SC("DROP_VIEW"), SQLITE_DROP_VIEW)
|
||||
.Const(_SC("DROP_VTABLE"), SQLITE_DROP_VTABLE)
|
||||
.Const(_SC("EMPTY"), SQLITE_EMPTY)
|
||||
.Const(_SC("ERROR"), SQLITE_ERROR)
|
||||
.Const(_SC("FAIL"), SQLITE_FAIL)
|
||||
.Const(_SC("FCNTL_BUSYHANDLER"), SQLITE_FCNTL_BUSYHANDLER)
|
||||
.Const(_SC("FCNTL_CHUNK_SIZE"), SQLITE_FCNTL_CHUNK_SIZE)
|
||||
.Const(_SC("FCNTL_COMMIT_PHASETWO"), SQLITE_FCNTL_COMMIT_PHASETWO)
|
||||
.Const(_SC("FCNTL_FILE_POINTER"), SQLITE_FCNTL_FILE_POINTER)
|
||||
.Const(_SC("FCNTL_GET_LOCKPROXYFILE"), SQLITE_FCNTL_GET_LOCKPROXYFILE)
|
||||
.Const(_SC("FCNTL_HAS_MOVED"), SQLITE_FCNTL_HAS_MOVED)
|
||||
.Const(_SC("FCNTL_LAST_ERRNO"), SQLITE_FCNTL_LAST_ERRNO)
|
||||
.Const(_SC("FCNTL_LOCKSTATE"), SQLITE_FCNTL_LOCKSTATE)
|
||||
.Const(_SC("FCNTL_MMAP_SIZE"), SQLITE_FCNTL_MMAP_SIZE)
|
||||
.Const(_SC("FCNTL_OVERWRITE"), SQLITE_FCNTL_OVERWRITE)
|
||||
.Const(_SC("FCNTL_PERSIST_WAL"), SQLITE_FCNTL_PERSIST_WAL)
|
||||
.Const(_SC("FCNTL_POWERSAFE_OVERWRITE"), SQLITE_FCNTL_POWERSAFE_OVERWRITE)
|
||||
.Const(_SC("FCNTL_PRAGMA"), SQLITE_FCNTL_PRAGMA)
|
||||
.Const(_SC("FCNTL_RBU"), SQLITE_FCNTL_RBU)
|
||||
.Const(_SC("FCNTL_SET_LOCKPROXYFILE"), SQLITE_FCNTL_SET_LOCKPROXYFILE)
|
||||
.Const(_SC("FCNTL_SIZE_HINT"), SQLITE_FCNTL_SIZE_HINT)
|
||||
.Const(_SC("FCNTL_SYNC"), SQLITE_FCNTL_SYNC)
|
||||
.Const(_SC("FCNTL_SYNC_OMITTED"), SQLITE_FCNTL_SYNC_OMITTED)
|
||||
.Const(_SC("FCNTL_TEMPFILENAME"), SQLITE_FCNTL_TEMPFILENAME)
|
||||
.Const(_SC("FCNTL_TRACE"), SQLITE_FCNTL_TRACE)
|
||||
.Const(_SC("FCNTL_VFSNAME"), SQLITE_FCNTL_VFSNAME)
|
||||
.Const(_SC("FCNTL_WAL_BLOCK"), SQLITE_FCNTL_WAL_BLOCK)
|
||||
.Const(_SC("FCNTL_WIN32_AV_RETRY"), SQLITE_FCNTL_WIN32_AV_RETRY)
|
||||
.Const(_SC("FCNTL_WIN32_SET_HANDLE"), SQLITE_FCNTL_WIN32_SET_HANDLE)
|
||||
.Const(_SC("FCNTL_ZIPVFS"), SQLITE_FCNTL_ZIPVFS)
|
||||
.Const(_SC("FLOAT"), SQLITE_FLOAT)
|
||||
.Const(_SC("FORMAT"), SQLITE_FORMAT)
|
||||
.Const(_SC("FULL"), SQLITE_FULL)
|
||||
.Const(_SC("FUNCTION"), SQLITE_FUNCTION)
|
||||
.Const(_SC("IGNORE"), SQLITE_IGNORE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_EQ"), SQLITE_INDEX_CONSTRAINT_EQ)
|
||||
.Const(_SC("INDEX_CONSTRAINT_GE"), SQLITE_INDEX_CONSTRAINT_GE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_GT"), SQLITE_INDEX_CONSTRAINT_GT)
|
||||
.Const(_SC("INDEX_CONSTRAINT_LE"), SQLITE_INDEX_CONSTRAINT_LE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_LT"), SQLITE_INDEX_CONSTRAINT_LT)
|
||||
.Const(_SC("INDEX_CONSTRAINT_MATCH"), SQLITE_INDEX_CONSTRAINT_MATCH)
|
||||
.Const(_SC("INDEX_SCAN_UNIQUE"), SQLITE_INDEX_SCAN_UNIQUE)
|
||||
.Const(_SC("INSERT"), SQLITE_INSERT)
|
||||
.Const(_SC("INTEGER"), SQLITE_INTEGER)
|
||||
.Const(_SC("INTERNAL"), SQLITE_INTERNAL)
|
||||
.Const(_SC("INTERRUPT"), SQLITE_INTERRUPT)
|
||||
.Const(_SC("IOCAP_ATOMIC"), SQLITE_IOCAP_ATOMIC)
|
||||
.Const(_SC("IOCAP_ATOMIC16K"), SQLITE_IOCAP_ATOMIC16K)
|
||||
.Const(_SC("IOCAP_ATOMIC1K"), SQLITE_IOCAP_ATOMIC1K)
|
||||
.Const(_SC("IOCAP_ATOMIC2K"), SQLITE_IOCAP_ATOMIC2K)
|
||||
.Const(_SC("IOCAP_ATOMIC32K"), SQLITE_IOCAP_ATOMIC32K)
|
||||
.Const(_SC("IOCAP_ATOMIC4K"), SQLITE_IOCAP_ATOMIC4K)
|
||||
.Const(_SC("IOCAP_ATOMIC512"), SQLITE_IOCAP_ATOMIC512)
|
||||
.Const(_SC("IOCAP_ATOMIC64K"), SQLITE_IOCAP_ATOMIC64K)
|
||||
.Const(_SC("IOCAP_ATOMIC8K"), SQLITE_IOCAP_ATOMIC8K)
|
||||
.Const(_SC("IOCAP_IMMUTABLE"), SQLITE_IOCAP_IMMUTABLE)
|
||||
.Const(_SC("IOCAP_POWERSAFE_OVERWRITE"), SQLITE_IOCAP_POWERSAFE_OVERWRITE)
|
||||
.Const(_SC("IOCAP_SAFE_APPEND"), SQLITE_IOCAP_SAFE_APPEND)
|
||||
.Const(_SC("IOCAP_SEQUENTIAL"), SQLITE_IOCAP_SEQUENTIAL)
|
||||
.Const(_SC("IOCAP_UNDELETABLE_WHEN_OPEN"), SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
|
||||
.Const(_SC("IOERR"), SQLITE_IOERR)
|
||||
.Const(_SC("IOERR_ACCESS"), SQLITE_IOERR_ACCESS)
|
||||
.Const(_SC("IOERR_BLOCKED"), SQLITE_IOERR_BLOCKED)
|
||||
.Const(_SC("IOERR_CHECKRESERVEDLOCK"), SQLITE_IOERR_CHECKRESERVEDLOCK)
|
||||
.Const(_SC("IOERR_CLOSE"), SQLITE_IOERR_CLOSE)
|
||||
.Const(_SC("IOERR_CONVPATH"), SQLITE_IOERR_CONVPATH)
|
||||
.Const(_SC("IOERR_DELETE"), SQLITE_IOERR_DELETE)
|
||||
.Const(_SC("IOERR_DELETE_NOENT"), SQLITE_IOERR_DELETE_NOENT)
|
||||
.Const(_SC("IOERR_DIR_CLOSE"), SQLITE_IOERR_DIR_CLOSE)
|
||||
.Const(_SC("IOERR_DIR_FSYNC"), SQLITE_IOERR_DIR_FSYNC)
|
||||
.Const(_SC("IOERR_FSTAT"), SQLITE_IOERR_FSTAT)
|
||||
.Const(_SC("IOERR_FSYNC"), SQLITE_IOERR_FSYNC)
|
||||
.Const(_SC("IOERR_GETTEMPPATH"), SQLITE_IOERR_GETTEMPPATH)
|
||||
.Const(_SC("IOERR_LOCK"), SQLITE_IOERR_LOCK)
|
||||
.Const(_SC("IOERR_MMAP"), SQLITE_IOERR_MMAP)
|
||||
.Const(_SC("IOERR_NOMEM"), SQLITE_IOERR_NOMEM)
|
||||
.Const(_SC("IOERR_RDLOCK"), SQLITE_IOERR_RDLOCK)
|
||||
.Const(_SC("IOERR_READ"), SQLITE_IOERR_READ)
|
||||
.Const(_SC("IOERR_SEEK"), SQLITE_IOERR_SEEK)
|
||||
.Const(_SC("IOERR_SHMLOCK"), SQLITE_IOERR_SHMLOCK)
|
||||
.Const(_SC("IOERR_SHMMAP"), SQLITE_IOERR_SHMMAP)
|
||||
.Const(_SC("IOERR_SHMOPEN"), SQLITE_IOERR_SHMOPEN)
|
||||
.Const(_SC("IOERR_SHMSIZE"), SQLITE_IOERR_SHMSIZE)
|
||||
.Const(_SC("IOERR_SHORT_READ"), SQLITE_IOERR_SHORT_READ)
|
||||
.Const(_SC("IOERR_TRUNCATE"), SQLITE_IOERR_TRUNCATE)
|
||||
.Const(_SC("IOERR_UNLOCK"), SQLITE_IOERR_UNLOCK)
|
||||
.Const(_SC("IOERR_VNODE"), SQLITE_IOERR_VNODE)
|
||||
.Const(_SC("IOERR_WRITE"), SQLITE_IOERR_WRITE)
|
||||
.Const(_SC("LIMIT_ATTACHED"), SQLITE_LIMIT_ATTACHED)
|
||||
.Const(_SC("LIMIT_COLUMN"), SQLITE_LIMIT_COLUMN)
|
||||
.Const(_SC("LIMIT_COMPOUND_SELECT"), SQLITE_LIMIT_COMPOUND_SELECT)
|
||||
.Const(_SC("LIMIT_EXPR_DEPTH"), SQLITE_LIMIT_EXPR_DEPTH)
|
||||
.Const(_SC("LIMIT_FUNCTION_ARG"), SQLITE_LIMIT_FUNCTION_ARG)
|
||||
.Const(_SC("LIMIT_LENGTH"), SQLITE_LIMIT_LENGTH)
|
||||
.Const(_SC("LIMIT_LIKE_PATTERN_LENGTH"), SQLITE_LIMIT_LIKE_PATTERN_LENGTH)
|
||||
.Const(_SC("LIMIT_SQL_LENGTH"), SQLITE_LIMIT_SQL_LENGTH)
|
||||
.Const(_SC("LIMIT_TRIGGER_DEPTH"), SQLITE_LIMIT_TRIGGER_DEPTH)
|
||||
.Const(_SC("LIMIT_VARIABLE_NUMBER"), SQLITE_LIMIT_VARIABLE_NUMBER)
|
||||
.Const(_SC("LIMIT_VDBE_OP"), SQLITE_LIMIT_VDBE_OP)
|
||||
.Const(_SC("LIMIT_WORKER_THREADS"), SQLITE_LIMIT_WORKER_THREADS)
|
||||
.Const(_SC("LOCKED"), SQLITE_LOCKED)
|
||||
.Const(_SC("LOCKED_SHAREDCACHE"), SQLITE_LOCKED_SHAREDCACHE)
|
||||
.Const(_SC("LOCK_EXCLUSIVE"), SQLITE_LOCK_EXCLUSIVE)
|
||||
.Const(_SC("LOCK_NONE"), SQLITE_LOCK_NONE)
|
||||
.Const(_SC("LOCK_PENDING"), SQLITE_LOCK_PENDING)
|
||||
.Const(_SC("LOCK_RESERVED"), SQLITE_LOCK_RESERVED)
|
||||
.Const(_SC("LOCK_SHARED"), SQLITE_LOCK_SHARED)
|
||||
.Const(_SC("MISMATCH"), SQLITE_MISMATCH)
|
||||
.Const(_SC("MISUSE"), SQLITE_MISUSE)
|
||||
.Const(_SC("MUTEX_FAST"), SQLITE_MUTEX_FAST)
|
||||
.Const(_SC("MUTEX_RECURSIVE"), SQLITE_MUTEX_RECURSIVE)
|
||||
.Const(_SC("MUTEX_STATIC_APP1"), SQLITE_MUTEX_STATIC_APP1)
|
||||
.Const(_SC("MUTEX_STATIC_APP2"), SQLITE_MUTEX_STATIC_APP2)
|
||||
.Const(_SC("MUTEX_STATIC_APP3"), SQLITE_MUTEX_STATIC_APP3)
|
||||
.Const(_SC("MUTEX_STATIC_LRU"), SQLITE_MUTEX_STATIC_LRU)
|
||||
.Const(_SC("MUTEX_STATIC_LRU2"), SQLITE_MUTEX_STATIC_LRU2)
|
||||
.Const(_SC("MUTEX_STATIC_MASTER"), SQLITE_MUTEX_STATIC_MASTER)
|
||||
.Const(_SC("MUTEX_STATIC_MEM"), SQLITE_MUTEX_STATIC_MEM)
|
||||
.Const(_SC("MUTEX_STATIC_MEM2"), SQLITE_MUTEX_STATIC_MEM2)
|
||||
.Const(_SC("MUTEX_STATIC_OPEN"), SQLITE_MUTEX_STATIC_OPEN)
|
||||
.Const(_SC("MUTEX_STATIC_PMEM"), SQLITE_MUTEX_STATIC_PMEM)
|
||||
.Const(_SC("MUTEX_STATIC_PRNG"), SQLITE_MUTEX_STATIC_PRNG)
|
||||
.Const(_SC("MUTEX_STATIC_VFS1"), SQLITE_MUTEX_STATIC_VFS1)
|
||||
.Const(_SC("MUTEX_STATIC_VFS2"), SQLITE_MUTEX_STATIC_VFS2)
|
||||
.Const(_SC("MUTEX_STATIC_VFS3"), SQLITE_MUTEX_STATIC_VFS3)
|
||||
.Const(_SC("NOLFS"), SQLITE_NOLFS)
|
||||
.Const(_SC("NOMEM"), SQLITE_NOMEM)
|
||||
.Const(_SC("NOTADB"), SQLITE_NOTADB)
|
||||
.Const(_SC("NOTFOUND"), SQLITE_NOTFOUND)
|
||||
.Const(_SC("NOTICE"), SQLITE_NOTICE)
|
||||
.Const(_SC("NOTICE_RECOVER_ROLLBACK"), SQLITE_NOTICE_RECOVER_ROLLBACK)
|
||||
.Const(_SC("NOTICE_RECOVER_WAL"), SQLITE_NOTICE_RECOVER_WAL)
|
||||
.Const(_SC("NULL"), SQLITE_NULL)
|
||||
.Const(_SC("OK"), SQLITE_OK)
|
||||
.Const(_SC("OPEN_AUTOPROXY"), SQLITE_OPEN_AUTOPROXY)
|
||||
.Const(_SC("OPEN_CREATE"), SQLITE_OPEN_CREATE)
|
||||
.Const(_SC("OPEN_DELETEONCLOSE"), SQLITE_OPEN_DELETEONCLOSE)
|
||||
.Const(_SC("OPEN_EXCLUSIVE"), SQLITE_OPEN_EXCLUSIVE)
|
||||
.Const(_SC("OPEN_FULLMUTEX"), SQLITE_OPEN_FULLMUTEX)
|
||||
.Const(_SC("OPEN_MAIN_DB"), SQLITE_OPEN_MAIN_DB)
|
||||
.Const(_SC("OPEN_MAIN_JOURNAL"), SQLITE_OPEN_MAIN_JOURNAL)
|
||||
.Const(_SC("OPEN_MASTER_JOURNAL"), SQLITE_OPEN_MASTER_JOURNAL)
|
||||
.Const(_SC("OPEN_MEMORY"), SQLITE_OPEN_MEMORY)
|
||||
.Const(_SC("OPEN_NOMUTEX"), SQLITE_OPEN_NOMUTEX)
|
||||
.Const(_SC("OPEN_PRIVATECACHE"), SQLITE_OPEN_PRIVATECACHE)
|
||||
.Const(_SC("OPEN_READONLY"), SQLITE_OPEN_READONLY)
|
||||
.Const(_SC("OPEN_READWRITE"), SQLITE_OPEN_READWRITE)
|
||||
.Const(_SC("OPEN_SHAREDCACHE"), SQLITE_OPEN_SHAREDCACHE)
|
||||
.Const(_SC("OPEN_SUBJOURNAL"), SQLITE_OPEN_SUBJOURNAL)
|
||||
.Const(_SC("OPEN_TEMP_DB"), SQLITE_OPEN_TEMP_DB)
|
||||
.Const(_SC("OPEN_TEMP_JOURNAL"), SQLITE_OPEN_TEMP_JOURNAL)
|
||||
.Const(_SC("OPEN_TRANSIENT_DB"), SQLITE_OPEN_TRANSIENT_DB)
|
||||
.Const(_SC("OPEN_URI"), SQLITE_OPEN_URI)
|
||||
.Const(_SC("OPEN_WAL"), SQLITE_OPEN_WAL)
|
||||
.Const(_SC("PERM"), SQLITE_PERM)
|
||||
.Const(_SC("PRAGMA"), SQLITE_PRAGMA)
|
||||
.Const(_SC("PROTOCOL"), SQLITE_PROTOCOL)
|
||||
.Const(_SC("RANGE"), SQLITE_RANGE)
|
||||
.Const(_SC("READ"), SQLITE_READ)
|
||||
.Const(_SC("READONLY"), SQLITE_READONLY)
|
||||
.Const(_SC("READONLY_CANTLOCK"), SQLITE_READONLY_CANTLOCK)
|
||||
.Const(_SC("READONLY_DBMOVED"), SQLITE_READONLY_DBMOVED)
|
||||
.Const(_SC("READONLY_RECOVERY"), SQLITE_READONLY_RECOVERY)
|
||||
.Const(_SC("READONLY_ROLLBACK"), SQLITE_READONLY_ROLLBACK)
|
||||
.Const(_SC("RECURSIVE"), SQLITE_RECURSIVE)
|
||||
.Const(_SC("REINDEX"), SQLITE_REINDEX)
|
||||
.Const(_SC("REPLACE"), SQLITE_REPLACE)
|
||||
.Const(_SC("ROLLBACK"), SQLITE_ROLLBACK)
|
||||
.Const(_SC("ROW"), SQLITE_ROW)
|
||||
.Const(_SC("SAVEPOINT"), SQLITE_SAVEPOINT)
|
||||
.Const(_SC("SCANSTAT_EST"), SQLITE_SCANSTAT_EST)
|
||||
.Const(_SC("SCANSTAT_EXPLAIN"), SQLITE_SCANSTAT_EXPLAIN)
|
||||
.Const(_SC("SCANSTAT_NAME"), SQLITE_SCANSTAT_NAME)
|
||||
.Const(_SC("SCANSTAT_NLOOP"), SQLITE_SCANSTAT_NLOOP)
|
||||
.Const(_SC("SCANSTAT_NVISIT"), SQLITE_SCANSTAT_NVISIT)
|
||||
.Const(_SC("SCANSTAT_SELECTID"), SQLITE_SCANSTAT_SELECTID)
|
||||
.Const(_SC("SCHEMA"), SQLITE_SCHEMA)
|
||||
.Const(_SC("SELECT"), SQLITE_SELECT)
|
||||
.Const(_SC("SHM_EXCLUSIVE"), SQLITE_SHM_EXCLUSIVE)
|
||||
.Const(_SC("SHM_LOCK"), SQLITE_SHM_LOCK)
|
||||
.Const(_SC("SHM_NLOCK"), SQLITE_SHM_NLOCK)
|
||||
.Const(_SC("SHM_SHARED"), SQLITE_SHM_SHARED)
|
||||
.Const(_SC("SHM_UNLOCK"), SQLITE_SHM_UNLOCK)
|
||||
.Const(_SC("SOURCE_ID"), SQLITE_SOURCE_ID)
|
||||
.Const(_SC("STATUS_MALLOC_COUNT"), SQLITE_STATUS_MALLOC_COUNT)
|
||||
.Const(_SC("STATUS_MALLOC_SIZE"), SQLITE_STATUS_MALLOC_SIZE)
|
||||
.Const(_SC("STATUS_MEMORY_USED"), SQLITE_STATUS_MEMORY_USED)
|
||||
.Const(_SC("STATUS_PAGECACHE_OVERFLOW"), SQLITE_STATUS_PAGECACHE_OVERFLOW)
|
||||
.Const(_SC("STATUS_PAGECACHE_SIZE"), SQLITE_STATUS_PAGECACHE_SIZE)
|
||||
.Const(_SC("STATUS_PAGECACHE_USED"), SQLITE_STATUS_PAGECACHE_USED)
|
||||
.Const(_SC("STATUS_PARSER_STACK"), SQLITE_STATUS_PARSER_STACK)
|
||||
.Const(_SC("STATUS_SCRATCH_OVERFLOW"), SQLITE_STATUS_SCRATCH_OVERFLOW)
|
||||
.Const(_SC("STATUS_SCRATCH_SIZE"), SQLITE_STATUS_SCRATCH_SIZE)
|
||||
.Const(_SC("STATUS_SCRATCH_USED"), SQLITE_STATUS_SCRATCH_USED)
|
||||
.Const(_SC("STMTSTATUS_AUTOINDEX"), SQLITE_STMTSTATUS_AUTOINDEX)
|
||||
.Const(_SC("STMTSTATUS_FULLSCAN_STEP"), SQLITE_STMTSTATUS_FULLSCAN_STEP)
|
||||
.Const(_SC("STMTSTATUS_SORT"), SQLITE_STMTSTATUS_SORT)
|
||||
.Const(_SC("STMTSTATUS_VM_STEP"), SQLITE_STMTSTATUS_VM_STEP)
|
||||
.Const(_SC("SYNC_DATAONLY"), SQLITE_SYNC_DATAONLY)
|
||||
.Const(_SC("SYNC_FULL"), SQLITE_SYNC_FULL)
|
||||
.Const(_SC("SYNC_NORMAL"), SQLITE_SYNC_NORMAL)
|
||||
.Const(_SC("TESTCTRL_ALWAYS"), SQLITE_TESTCTRL_ALWAYS)
|
||||
.Const(_SC("TESTCTRL_ASSERT"), SQLITE_TESTCTRL_ASSERT)
|
||||
.Const(_SC("TESTCTRL_BENIGN_MALLOC_HOOKS"), SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS)
|
||||
.Const(_SC("TESTCTRL_BITVEC_TEST"), SQLITE_TESTCTRL_BITVEC_TEST)
|
||||
.Const(_SC("TESTCTRL_BYTEORDER"), SQLITE_TESTCTRL_BYTEORDER)
|
||||
.Const(_SC("TESTCTRL_EXPLAIN_STMT"), SQLITE_TESTCTRL_EXPLAIN_STMT)
|
||||
.Const(_SC("TESTCTRL_FAULT_INSTALL"), SQLITE_TESTCTRL_FAULT_INSTALL)
|
||||
.Const(_SC("TESTCTRL_FIRST"), SQLITE_TESTCTRL_FIRST)
|
||||
.Const(_SC("TESTCTRL_IMPOSTER"), SQLITE_TESTCTRL_IMPOSTER)
|
||||
.Const(_SC("TESTCTRL_ISINIT"), SQLITE_TESTCTRL_ISINIT)
|
||||
.Const(_SC("TESTCTRL_ISKEYWORD"), SQLITE_TESTCTRL_ISKEYWORD)
|
||||
.Const(_SC("TESTCTRL_LAST"), SQLITE_TESTCTRL_LAST)
|
||||
.Const(_SC("TESTCTRL_LOCALTIME_FAULT"), SQLITE_TESTCTRL_LOCALTIME_FAULT)
|
||||
.Const(_SC("TESTCTRL_NEVER_CORRUPT"), SQLITE_TESTCTRL_NEVER_CORRUPT)
|
||||
.Const(_SC("TESTCTRL_OPTIMIZATIONS"), SQLITE_TESTCTRL_OPTIMIZATIONS)
|
||||
.Const(_SC("TESTCTRL_PENDING_BYTE"), SQLITE_TESTCTRL_PENDING_BYTE)
|
||||
.Const(_SC("TESTCTRL_PRNG_RESET"), SQLITE_TESTCTRL_PRNG_RESET)
|
||||
.Const(_SC("TESTCTRL_PRNG_RESTORE"), SQLITE_TESTCTRL_PRNG_RESTORE)
|
||||
.Const(_SC("TESTCTRL_PRNG_SAVE"), SQLITE_TESTCTRL_PRNG_SAVE)
|
||||
.Const(_SC("TESTCTRL_RESERVE"), SQLITE_TESTCTRL_RESERVE)
|
||||
.Const(_SC("TESTCTRL_SCRATCHMALLOC"), SQLITE_TESTCTRL_SCRATCHMALLOC)
|
||||
.Const(_SC("TESTCTRL_SORTER_MMAP"), SQLITE_TESTCTRL_SORTER_MMAP)
|
||||
.Const(_SC("TESTCTRL_VDBE_COVERAGE"), SQLITE_TESTCTRL_VDBE_COVERAGE)
|
||||
.Const(_SC("TEXT"), SQLITE_TEXT)
|
||||
.Const(_SC("TOOBIG"), SQLITE_TOOBIG)
|
||||
.Const(_SC("TRANSACTION"), SQLITE_TRANSACTION)
|
||||
.Const(_SC("UPDATE"), SQLITE_UPDATE)
|
||||
.Const(_SC("UTF16"), SQLITE_UTF16)
|
||||
.Const(_SC("UTF16BE"), SQLITE_UTF16BE)
|
||||
.Const(_SC("UTF16LE"), SQLITE_UTF16LE)
|
||||
.Const(_SC("UTF16_ALIGNED"), SQLITE_UTF16_ALIGNED)
|
||||
.Const(_SC("UTF8"), SQLITE_UTF8)
|
||||
.Const(_SC("VERSION"), SQLITE_VERSION)
|
||||
.Const(_SC("VERSION_NUMBER"), SQLITE_VERSION_NUMBER)
|
||||
.Const(_SC("VTAB_CONSTRAINT_SUPPORT"), SQLITE_VTAB_CONSTRAINT_SUPPORT)
|
||||
.Const(_SC("WARNING"), SQLITE_WARNING)
|
||||
.Const(_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX)
|
||||
);
|
||||
*/
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Constants> type was successful");
|
||||
// Registration succeeded
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,415 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_SHARED_HPP_
|
||||
#define _LIBRARY_SQLITE_SHARED_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
#include "Library/LongInt.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqlite3.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <queue>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class Connection;
|
||||
class Statement;
|
||||
class Result;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* A managed handle to a shared SQLite connection.
|
||||
*/
|
||||
class ConnectionHandle
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Connection;
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Helper class responsible for managing the handle to an SQLite connection resource.
|
||||
*/
|
||||
struct Handle
|
||||
{
|
||||
friend class ConnectionHandle;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The type of container used to queue queries for group execution.
|
||||
*/
|
||||
typedef std::queue< String > QueryList;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The amount of references to this handle instance.
|
||||
*/
|
||||
mutable SQUint32 Ref;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The handle to the managed SQLite connection resource.
|
||||
*/
|
||||
sqlite3* Ptr;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The flags used to create the SQLite connection handle.
|
||||
*/
|
||||
SQInt32 Flags;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The specified path to be used as the database file.
|
||||
*/
|
||||
String Path;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The specified virtual file system.
|
||||
*/
|
||||
String VFS;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The last status code of this connection handle.
|
||||
*/
|
||||
SQInt32 Status;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* A queue of queries to be executed in groups in order to reduce lag.
|
||||
*/
|
||||
QueryList Queue;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The global tag associated with this resource.
|
||||
*/
|
||||
SqTag Tag;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The global data associated with this resource.
|
||||
*/
|
||||
SqObj Data;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether the database exists in memory and not disk.
|
||||
*/
|
||||
bool Memory;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether tracing was activated on the database.
|
||||
*/
|
||||
bool Trace;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether profiling was activated on the database.
|
||||
*/
|
||||
bool Profile;
|
||||
|
||||
private:
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Handle constructor.
|
||||
*/
|
||||
Handle(const String & path, SQInt32 flags, const String & vfs)
|
||||
: Ref(1), Ptr(NULL), Flags(flags), Path(path), VFS(vfs)
|
||||
, Status(SQLITE_OK), Queue(), Tag(), Data()
|
||||
, Memory(path == ":memory:"), Trace(false), Profile(false)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled)
|
||||
*/
|
||||
Handle(const Handle &) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled)
|
||||
*/
|
||||
Handle(Handle &&) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Handle destructor.
|
||||
*/
|
||||
~Handle()
|
||||
{
|
||||
// If a valid handle exists then attempt to release it
|
||||
if (Ptr != NULL && (Status = sqlite3_close(Ptr)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <close database connection> because : %s", sqlite3_errmsg(Ptr));
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled)
|
||||
*/
|
||||
Handle & operator = (const Handle &) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator (disabled)
|
||||
*/
|
||||
Handle & operator = (Handle &&) = delete;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Acquire a strong reference to the resource handle.
|
||||
*/
|
||||
void Grab()
|
||||
{
|
||||
// If a valid handle exists then grab a reference to it
|
||||
if (Hnd != nullptr)
|
||||
{
|
||||
++(Hnd->Ref);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the handle reference and therefore the handle it self if no more references exist.
|
||||
*/
|
||||
void Drop()
|
||||
{
|
||||
// If a valid handle exists then delete it if this is the last released reference
|
||||
if (Hnd != nullptr && --(Hnd->Ref) == 0)
|
||||
{
|
||||
delete Hnd;
|
||||
}
|
||||
// Explicitly make sure the handle is null
|
||||
Hnd = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The handle instance that manages the SQLite resource.
|
||||
*/
|
||||
Handle * Hnd;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Open a connection to a database using the specified path, flags and vfs.
|
||||
*/
|
||||
ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
ConnectionHandle(const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
ConnectionHandle(ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
ConnectionHandle & operator = (const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
ConnectionHandle & operator = (ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return (Hnd != nullptr) && (Hnd->Ptr != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Negation operator.
|
||||
*/
|
||||
operator ! () const
|
||||
{
|
||||
return (Hnd == nullptr) || (Hnd->Ptr == NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Ptr : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to integer status code.
|
||||
*/
|
||||
operator SQInt32 () const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Status : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Member of pointer operator.
|
||||
*/
|
||||
Handle * operator -> () const
|
||||
{
|
||||
return Hnd;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Indirection operator.
|
||||
*/
|
||||
Handle & operator * () const
|
||||
{
|
||||
return *Hnd;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const ConnectionHandle & o) const
|
||||
{
|
||||
return (Hnd == o.Hnd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const ConnectionHandle & o) const
|
||||
{
|
||||
return (Hnd != o.Hnd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset this handle and release the internal reference.
|
||||
*/
|
||||
void Release()
|
||||
{
|
||||
Drop();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of active references to this handle.
|
||||
*/
|
||||
SQUint32 Count() const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Ref : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error message associated with the value in status.
|
||||
*/
|
||||
const SQChar * ErrStr() const
|
||||
{
|
||||
return sqlite3_errstr(Hnd->Status);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error message associated with the connection.
|
||||
*/
|
||||
const SQChar * ErrMsg() const
|
||||
{
|
||||
return sqlite3_errmsg(Hnd->Ptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error code associated with the connection.
|
||||
*/
|
||||
SQInt32 ErrNo() const
|
||||
{
|
||||
return sqlite3_errcode(Hnd->Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII encapsulation of a SQLite Transaction.
|
||||
*/
|
||||
class Transaction
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Transaction(const Connection & db);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
Transaction(const Transaction & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled).
|
||||
*/
|
||||
Transaction(Transaction && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Transaction();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
Transaction & operator = (const Transaction & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator (disabled).
|
||||
*/
|
||||
Transaction & operator = (Transaction && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Commit the transaction.
|
||||
*/
|
||||
void Commit();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the transaction was committed.
|
||||
*/
|
||||
bool Commited() const
|
||||
{
|
||||
return m_Commited;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The SQLite connection associated with this transaction.
|
||||
*/
|
||||
ConnectionHandle m_Connection;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the changes were committed.
|
||||
*/
|
||||
bool m_Commited;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Places a "soft" limit on the amount of heap memory that may be allocated by SQLite.
|
||||
*/
|
||||
void SetSoftHeapLimit(SQInt32 limit);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempts to free N bytes of heap memory by deallocating non-essential memory allocations
|
||||
* held by the database library.
|
||||
*/
|
||||
SQInt32 ReleaseMemory(SQInt32 bytes);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Returns the number of bytes of memory currently outstanding (malloced but not freed).
|
||||
*/
|
||||
SLongInt GetMemoryUsage();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Returns the maximum value of used bytes since the high-water mark was last reset.
|
||||
*/
|
||||
SLongInt GetMemoryHighwaterMark(bool reset);
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_SHARED_HPP_
|
File diff suppressed because it is too large
Load Diff
@ -1,436 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_STATEMENT_HPP_
|
||||
#define _LIBRARY_SQLITE_STATEMENT_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <unordered_map>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to manage a connection to an SQLite statement.
|
||||
*/
|
||||
class Statement
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
Statement();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a statement on the specified connection and use the specified query.
|
||||
*/
|
||||
Statement(const Connection & db, const SQChar * query);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Statement(const Statement &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Statement(Statement &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Statement();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Statement & operator = (const Statement &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Statement & operator = (Statement &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite statement handle.
|
||||
*/
|
||||
operator sqlite3_stmt * () const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Connection);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return (m_Handle != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Negation operator.
|
||||
*/
|
||||
operator ! () const
|
||||
{
|
||||
return (m_Handle == NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const Statement & o) const
|
||||
{
|
||||
return (m_Handle == o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const Statement & o) const
|
||||
{
|
||||
return (m_Handle != o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script to compare two instances of this type.
|
||||
*/
|
||||
SQInt32 Cmp(const Statement & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Convert this type to a string.
|
||||
*/
|
||||
const SQChar * ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local tag.
|
||||
*/
|
||||
const SQChar * GetLocalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local tag.
|
||||
*/
|
||||
void SetLocalTag(const SQChar * tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local data.
|
||||
*/
|
||||
SqObj & GetLocalData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local data.
|
||||
*/
|
||||
void SetLocalData(SqObj & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
return (m_Handle != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetStatus() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetColumns() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetQuery() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetErrStr() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetErrMsg() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Connection GetConnection() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool GetGood() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool GetDone() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the extended numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetExtendedErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 Exec();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool Step();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindA(const Array & arr);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindT(const Table & tbl);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindI(SQInt32 idx, SQInt32 value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindL(SQInt32 idx, const SLongInt & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindV(SQInt32 idx, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindF(SQInt32 idx, SQFloat value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindS(SQInt32 idx, const SQChar * value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindB(SQInt32 idx, bool value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindN(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindT(const Table & tbl);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindI(const SQChar * name, SQInt32 value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindL(const SQChar * name, const SLongInt & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindV(const SQChar * name, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindF(const SQChar * name, SQFloat value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindS(const SQChar * name, const SQChar * value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindB(const SQChar * name, bool value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindN(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBind(SQInt32 idx, SqObj & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBind(const SQChar * name, SqObj & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SqObj FetchColumnIndex(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SqObj FetchColumnName(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Array FetchArray();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Table FetchTable();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool CheckIndex(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool IsColumnNull(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetColumnIndex(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetColumnName(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetColumnOriginName(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger GetColumnType(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger GetColumnBytes(SQInt32 idx) const;
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
typedef std::unordered_map< String, SQInt32 > ColumnIndex;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
template < typename... Args > void Status(const SQChar * msg, Args&&... args) const
|
||||
{
|
||||
if (m_Status != SQLITE_OK)
|
||||
{
|
||||
LogErr(msg, std::forward< Args >(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The handle to the managed SQLite statement resource.
|
||||
*/
|
||||
sqlite3_stmt* m_Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The SQLite connection associated with this statement.
|
||||
*/
|
||||
ConnectionHandle m_Connection;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The query string used to create this statement.
|
||||
*/
|
||||
String m_Query;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The last status code of this connection handle.
|
||||
*/
|
||||
SQInt32 m_Status;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The amount of columns available in this statement.
|
||||
*/
|
||||
SQInt32 m_Columns;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when a row has been fetched with step.
|
||||
*/
|
||||
ColumnIndex m_ColIdx;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when a row has been fetched with step.
|
||||
*/
|
||||
bool m_Good;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when the last step had no more rows to fetch.
|
||||
*/
|
||||
bool m_Done;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local tag associated with this instance.
|
||||
*/
|
||||
SqTag m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local data associated with this instance.
|
||||
*/
|
||||
SqObj m_Data;
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_STATEMENT_HPP_
|
@ -1,18 +0,0 @@
|
||||
#include "Library/Shared.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Library(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,12 +0,0 @@
|
||||
#ifndef _LIBRARY_SHARED_HPP_
|
||||
#define _LIBRARY_SHARED_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SHARED_HPP_
|
@ -1,14 +1,287 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/String.hpp"
|
||||
#include "Register.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqstdstring.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <algorithm>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_String(HSQUIRRELVM vm)
|
||||
CSStr LeftStr(CSStr t, SQChar f, Uint32 w)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
// Allocate a buffer with the requested width
|
||||
Buffer b(w * sizeof(SQChar));
|
||||
Uint32 n = !t ? 0 : strlen(t);
|
||||
// Populate the entire buffer with the fill character
|
||||
memset(b.Data(), f, w * sizeof(SQChar));
|
||||
// Is the specified width valid?
|
||||
if (w >= b.Size< SQChar >())
|
||||
{
|
||||
SqThrow("Invalid width specified: %d > %d", w, b.Size< SQChar >());
|
||||
w = 0;
|
||||
}
|
||||
// Is the specified string valid?
|
||||
else if (n == 0)
|
||||
{
|
||||
SqThrow("Invalid string length: %d < 0", n);
|
||||
}
|
||||
// Is the specified string within width range?
|
||||
else if (n > w)
|
||||
{
|
||||
SqThrow("String is out of bounds: %d > %d", n, w);
|
||||
}
|
||||
// Insert the specified string
|
||||
else
|
||||
{
|
||||
strncpy(b.Data(), t, n);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(w) = 0;
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
CSStr LeftStr(CSStr t, SQChar f, Uint32 w, Uint32 o)
|
||||
{
|
||||
// Allocate a buffer with the requested width
|
||||
Buffer b(w * sizeof(SQChar));
|
||||
Uint32 n = !t ? 0 : strlen(t);
|
||||
// Populate the entire buffer with the fill character
|
||||
memset(b.Data(), f, w * sizeof(SQChar));
|
||||
// Is the specified width valid?
|
||||
if (w >= b.Size< SQChar >())
|
||||
{
|
||||
SqThrow("Invalid width specified: %d > %d", w, b.Size< SQChar >());
|
||||
w = 0;
|
||||
}
|
||||
// Is the specified string valid?
|
||||
else if (n == 0)
|
||||
{
|
||||
SqThrow("Invalid string length: %d < 0", n);
|
||||
}
|
||||
// Is the specified string within width range?
|
||||
else if ((o+n) > w)
|
||||
{
|
||||
SqThrow("String is out of bounds: (%d+%d) > %d", o, n, w);
|
||||
}
|
||||
// Insert the specified string
|
||||
else
|
||||
{
|
||||
strncpy(b.Get< SQChar >() + o, t, n);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(w) = 0;
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr RightStr(CSStr t, SQChar f, Uint32 w)
|
||||
{
|
||||
// Allocate a buffer with the requested width
|
||||
Buffer b(w * sizeof(SQChar));
|
||||
Uint32 n = !t ? 0 : strlen(t);
|
||||
// Populate the entire buffer with the fill character
|
||||
memset(b.Data(), f, w * sizeof(SQChar));
|
||||
// Is the specified width valid?
|
||||
if (w >= b.Size< SQChar >())
|
||||
{
|
||||
SqThrow("Invalid width specified: %d > %d", w, b.Size< SQChar >());
|
||||
w = 0;
|
||||
}
|
||||
// Is the specified string valid?
|
||||
else if (n == 0)
|
||||
{
|
||||
SqThrow("Invalid string length: %d < 0", n);
|
||||
}
|
||||
// Is the specified string within width range?
|
||||
else if (n > w)
|
||||
{
|
||||
SqThrow("String is out of bounds: %d > %d", n, w);
|
||||
}
|
||||
// Insert the specified string
|
||||
else
|
||||
{
|
||||
strncpy(b.Get< SQChar >() + (w-n), t, n);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(w) = 0;
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
CSStr RightStr(CSStr t, SQChar f, Uint32 w, Uint32 o)
|
||||
{
|
||||
// Allocate a buffer with the requested width
|
||||
Buffer b(w * sizeof(SQChar));
|
||||
Uint32 n = !t ? 0 : strlen(t);
|
||||
// Populate the entire buffer with the fill character
|
||||
memset(b.Data(), f, w * sizeof(SQChar));
|
||||
// Is the specified width valid?
|
||||
if (w >= b.Size< SQChar >())
|
||||
{
|
||||
SqThrow("Invalid width specified: %d > %d", w, b.Size< SQChar >());
|
||||
w = 0;
|
||||
}
|
||||
// Is the specified string valid?
|
||||
else if (n == 0)
|
||||
{
|
||||
SqThrow("Invalid string length: %d < 0", n);
|
||||
}
|
||||
// Is the specified string within width range?
|
||||
else if ((n+o) > w)
|
||||
{
|
||||
SqThrow("String is out of bounds: (%d+%d) > %d", n, o, w);
|
||||
}
|
||||
// Insert the specified string
|
||||
else
|
||||
{
|
||||
strncpy(b.Get< SQChar >() + ((w-n)-o), t, n);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(w) = 0;
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr CenterStr(CSStr t, SQChar f, Uint32 w)
|
||||
{
|
||||
// Allocate a buffer with the requested width
|
||||
Buffer b(w * sizeof(SQChar));
|
||||
Uint32 n = !t ? 0 : strlen(t);
|
||||
// Populate the entire buffer with the fill character
|
||||
memset(b.Data(), f, w * sizeof(SQChar));
|
||||
// Is the specified width valid?
|
||||
if (w >= b.Size< SQChar >())
|
||||
{
|
||||
SqThrow("Invalid width specified: %d > %d", w, b.Size< SQChar >());
|
||||
w = 0;
|
||||
}
|
||||
// Is the specified string valid?
|
||||
else if (n == 0)
|
||||
{
|
||||
SqThrow("Invalid string length: %d < 0", n);
|
||||
}
|
||||
// Is the specified string within width range?
|
||||
else if (n > w)
|
||||
{
|
||||
SqThrow("String is out of bounds: %d > %d", n, w);
|
||||
}
|
||||
// Insert the specified string
|
||||
else
|
||||
{
|
||||
strncpy(b.Get< SQChar >() + (w/2 - n/2), t, n);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(w) = 0;
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr StrJustAlphaNum(CSStr str)
|
||||
{
|
||||
Uint32 size = 0;
|
||||
// See if we actually have something to search for
|
||||
if(!str || (size = strlen(str)) <= 0)
|
||||
{
|
||||
return _SC("");
|
||||
}
|
||||
// Obtain a temporary buffer
|
||||
Buffer b(size);
|
||||
// Resulted string size
|
||||
Uint32 n = 0;
|
||||
// Currently processed character
|
||||
SQChar c = 0;
|
||||
// Process characters
|
||||
while ((c = *(str++)) != 0)
|
||||
{
|
||||
// Is this an alpha-numeric character?
|
||||
if (isalnum(c) != 0)
|
||||
{
|
||||
// Save it and move to the next one
|
||||
b.At< SQChar >(n++) = c;
|
||||
}
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(n) = 0;
|
||||
// Return the string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr StrToLowercase(CSStr str)
|
||||
{
|
||||
Uint32 size = 0;
|
||||
// See if we actually have something to search for
|
||||
if(!str || (size = strlen(str)) <= 0)
|
||||
{
|
||||
return _SC("");
|
||||
}
|
||||
// Obtain a temporary buffer
|
||||
Buffer b(size);
|
||||
// Resulted string size
|
||||
Uint32 n = 0;
|
||||
// Currently processed character
|
||||
SQChar c = 0;
|
||||
// Process characters
|
||||
while ((c = *(str++)) != 0)
|
||||
{
|
||||
// Convert it and move to the next one
|
||||
b.At< SQChar >(n++) = tolower(c);
|
||||
}
|
||||
// End the resulted string
|
||||
b.At< SQChar >(n) = 0;
|
||||
// Return the string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static CSStr FromArray(Array & arr)
|
||||
{
|
||||
Buffer b((arr.Length()+1) * sizeof(SQChar));
|
||||
arr.GetArray< SQChar >(b.Get< SQChar >(), b.Size< SQChar >());
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static SQInteger StdPrintF(HSQUIRRELVM vm)
|
||||
{
|
||||
CStr msg = NULL;
|
||||
SQInteger length = 0;
|
||||
if(SQ_FAILED(sqstd_format(vm, 2, &length, &msg)))
|
||||
return -1;
|
||||
LogUsr("%s", msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_String(HSQUIRRELVM vm)
|
||||
{
|
||||
Table strns(vm);
|
||||
|
||||
strns.Func(_SC("FromArray"), &FromArray)
|
||||
.Overload< CSStr (*)(CSStr, SQChar, Uint32) >(_SC("Left"), &LeftStr)
|
||||
.Overload< CSStr (*)(CSStr, SQChar, Uint32, Uint32) >(_SC("Left"), &LeftStr)
|
||||
.Overload< CSStr (*)(CSStr, SQChar, Uint32) >(_SC("Right"), &RightStr)
|
||||
.Overload< CSStr (*)(CSStr, SQChar, Uint32, Uint32) >(_SC("Right"), &RightStr)
|
||||
.Func(_SC("Center"), &CenterStr);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqStr"), strns);
|
||||
RootTable(vm).SquirrelFunc(_SC("printf"), &StdPrintF);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -2,15 +2,30 @@
|
||||
#define _LIBRARY_STRING_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Utility used to generate a string with an arbitrary text surrounded by a specific character
|
||||
*/
|
||||
CSStr LeftStr(CSStr t, SQChar f, Uint32 w = 72);
|
||||
CSStr LeftStr(CSStr t, SQChar f, Uint32 w = 72, Uint32 o = 0);
|
||||
CSStr RightStr(CSStr t, SQChar f, Uint32 w = 72);
|
||||
CSStr RightStr(CSStr t, SQChar f, Uint32 w = 72, Uint32 o = 0);
|
||||
CSStr CenterStr(CSStr t, SQChar f, Uint32 w = 72);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a new string with only the alpha numeric characters from the specified string.
|
||||
*/
|
||||
CSStr StrJustAlphaNum(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert the specified string to lowercase.
|
||||
*/
|
||||
CSStr StrToLowercase(CSStr str);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_STRING_HPP_
|
||||
#endif // _LIBRARY_STRING_HPP_
|
||||
|
@ -1,14 +0,0 @@
|
||||
#include "Library/SysPath.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_SysPath(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_SYSPATH_HPP_
|
||||
#define _LIBRARY_SYSPATH_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SYSPATH_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/System.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_System(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_SYSTEM_HPP_
|
||||
#define _LIBRARY_SYSTEM_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SYSTEM_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/Timer.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Timer(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_TIMER_HPP_
|
||||
#define _LIBRARY_TIMER_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_TIMER_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/Utils.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_Utils(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_UTILS_HPP_
|
||||
#define _LIBRARY_UTILS_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_UTILS_HPP_
|
@ -1,14 +0,0 @@
|
||||
#include "Library/XML.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Register_XML(HSQUIRRELVM vm)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
#ifndef _LIBRARY_XML_HPP_
|
||||
#define _LIBRARY_XML_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Config.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_XML_HPP_
|
Reference in New Issue
Block a user