1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-08-06 08:01:47 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@@ -0,0 +1,480 @@
// ------------------------------------------------------------------------------------------------
#include "Library/IO/Buffer.hpp"
#include "Library/Numeric/Long.hpp"
#include "Base/AABB.hpp"
#include "Base/Circle.hpp"
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Sphere.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Vector4.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMOD_DECL_TYPENAME(Typename, _SC("SqBuffer"))
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteInt64(const SLongInt & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< int64_t >(val.GetNum());
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteUint64(const ULongInt & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< uint64_t >(val.GetNum());
}
// ------------------------------------------------------------------------------------------------
SQInteger SqBuffer::WriteRawString(StackStrF & val)
{
// Validate the managed buffer reference
Validate();
// Is the given string value even valid?
if (!val.mLen)
{
STHROWF("Invalid string argument: null");
}
// Calculate the string length
Buffer::SzType length = ConvTo< Buffer::SzType >::From(val.mLen);
// Write the the string contents
m_Buffer->AppendS(val.mPtr, length);
// Return the length of the written string
return val.mLen;
}
// ------------------------------------------------------------------------------------------------
SQInteger SqBuffer::WriteClientString(StackStrF & val)
{
// Validate the managed buffer reference
Validate();
// Is the given string value even valid?
if (!val.mLen)
{
STHROWF("Invalid string argument: null");
}
else if (val.mLen > 0xFFFF)
{
STHROWF("String too large");
}
// Calculate the string length
uint16_t length = ConvTo< uint16_t >::From(val.mLen);
// Change the size endianness to big endian
auto size = static_cast< uint16_t >(((length >> 8) & 0xFF) | ((length & 0xFF) << 8));
// Write the size and then the string contents
m_Buffer->Push< uint16_t >(size);
m_Buffer->AppendS(val.mPtr, length);
// Return the length of the written string
return val.mLen;
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteAABB(const AABB & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< AABB >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteCircle(const Circle & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Circle >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteColor3(const Color3 & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Color3 >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteColor4(const Color4 & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Color4 >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteQuaternion(const Quaternion & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Quaternion >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteSphere(const Sphere &val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Sphere >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteVector2(const Vector2 & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Vector2 >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteVector2i(const Vector2i & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Vector2i >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteVector3(const Vector3 & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Vector3 >(val);
}
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteVector4(const Vector4 & val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Vector4 >(val);
}
// ------------------------------------------------------------------------------------------------
SLongInt SqBuffer::ReadInt64()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const int64_t value = m_Buffer->Cursor< int64_t >();
// Advance the buffer cursor
m_Buffer->Advance< int64_t >(1);
// Return the requested information
return SLongInt(value);
}
// ------------------------------------------------------------------------------------------------
ULongInt SqBuffer::ReadUint64()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const uint64_t value = m_Buffer->Cursor< uint64_t >();
// Advance the buffer cursor
m_Buffer->Advance< uint64_t >(1);
// Return the requested information
return ULongInt(value);
}
// ------------------------------------------------------------------------------------------------
LightObj SqBuffer::ReadRawString(SQInteger length)
{
// Validate the managed buffer reference
ValidateDeeper();
// Start with a length of zero
Buffer::SzType len = 0;
// Should we Identify the string length ourselves?
if (length < 0)
{
// Grab the buffer range to search for
const char * ptr = &m_Buffer->Cursor(), * itr = ptr, * end = m_Buffer->End();
// Attempt to look for a string terminator
while (itr != end && *itr != '\0')
{
++itr;
}
// If nothing was found, consider the remaining buffer part of the requested string
len = static_cast< Buffer::SzType >(ptr - itr);
}
else
{
len = ConvTo< Buffer::SzType >::From(length);
}
// Validate the obtained length
if ((m_Buffer->Position() + len) > m_Buffer->Capacity())
{
STHROWF("String of size (%u) starting at (%u) is out of buffer capacity (%u)",
len, m_Buffer->Position(), m_Buffer->Capacity());
}
// Remember the current stack size
const StackGuard sg;
// Attempt to create the string as an object
sq_pushstring(SqVM(), &m_Buffer->Cursor(), len);
// Advance the cursor after the string
m_Buffer->Advance(len);
// Return the resulted object
return LightObj(-1, SqVM());
}
// ------------------------------------------------------------------------------------------------
LightObj SqBuffer::ReadClientString()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
uint16_t length = m_Buffer->Cursor< uint16_t >();
// Convert the length to little endian
length = static_cast< uint16_t >(((length >> 8) & 0xFF) | ((length & 0xFF) << 8));
// Validate the obtained length
if ((m_Buffer->Position() + sizeof(uint16_t) + length) > m_Buffer->Capacity())
{
STHROWF("String of size (%u) starting at (%u) is out of buffer capacity (%u)",
length, m_Buffer->Position() + sizeof(uint16_t), m_Buffer->Capacity());
}
// Advance the buffer to the actual string
m_Buffer->Advance< uint16_t >(1);
// Remember the current stack size
const StackGuard sg;
// Attempt to create the string as an object
sq_pushstring(SqVM(), &m_Buffer->Cursor(), length);
// Advance the cursor after the string
m_Buffer->Advance(length);
// Return the resulted object
return LightObj(-1, SqVM());
}
// ------------------------------------------------------------------------------------------------
AABB SqBuffer::ReadAABB()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const AABB & value = m_Buffer->Cursor< AABB >();
// Advance the buffer cursor
m_Buffer->Advance< AABB >(1);
// Return the requested information
return AABB(value);
}
// ------------------------------------------------------------------------------------------------
Circle SqBuffer::ReadCircle()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Circle & value = m_Buffer->Cursor< Circle >();
// Advance the buffer cursor
m_Buffer->Advance< Circle >(1);
// Return the requested information
return Circle(value);
}
// ------------------------------------------------------------------------------------------------
Color3 SqBuffer::ReadColor3()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Color3 & value = m_Buffer->Cursor< Color3 >();
// Advance the buffer cursor
m_Buffer->Advance< Color3 >(1);
// Return the requested information
return Color3(value);
}
// ------------------------------------------------------------------------------------------------
Color4 SqBuffer::ReadColor4()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Color4 & value = m_Buffer->Cursor< Color4 >();
// Advance the buffer cursor
m_Buffer->Advance< Color4 >(1);
// Return the requested information
return Color4(value);
}
// ------------------------------------------------------------------------------------------------
Quaternion SqBuffer::ReadQuaternion()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Quaternion & value = m_Buffer->Cursor< Quaternion >();
// Advance the buffer cursor
m_Buffer->Advance< Quaternion >(1);
// Return the requested information
return Quaternion(value);
}
// ------------------------------------------------------------------------------------------------
Sphere SqBuffer::ReadSphere()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Sphere & value = m_Buffer->Cursor< Sphere >();
// Advance the buffer cursor
m_Buffer->Advance< Sphere >(1);
// Return the requested information
return Sphere(value);
}
// ------------------------------------------------------------------------------------------------
Vector2 SqBuffer::ReadVector2()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Vector2 & value = m_Buffer->Cursor< Vector2 >();
// Advance the buffer cursor
m_Buffer->Advance< Vector2 >(1);
// Return the requested information
return Vector2(value);
}
// ------------------------------------------------------------------------------------------------
Vector2i SqBuffer::ReadVector2i()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Vector2i & value = m_Buffer->Cursor< Vector2i >();
// Advance the buffer cursor
m_Buffer->Advance< Vector2i >(1);
// Return the requested information
return Vector2i(value);
}
// ------------------------------------------------------------------------------------------------
Vector3 SqBuffer::ReadVector3()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Vector3 & value = m_Buffer->Cursor< Vector3 >();
// Advance the buffer cursor
m_Buffer->Advance< Vector3 >(1);
// Return the requested information
return Vector3(value);
}
// ------------------------------------------------------------------------------------------------
Vector4 SqBuffer::ReadVector4()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Vector4 & value = m_Buffer->Cursor< Vector4 >();
// Advance the buffer cursor
m_Buffer->Advance< Vector4 >(1);
// Return the requested information
return Vector4(value);
}
// ================================================================================================
void Register_Buffer(HSQUIRRELVM vm)
{
RootTable(vm).Bind(Typename::Str,
Class< SqBuffer, NoCopy< SqBuffer > >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< SQInteger >()
// Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
// Properties
.Prop(_SC("Front"), &SqBuffer::GetFront, &SqBuffer::SetFront)
.Prop(_SC("Next"), &SqBuffer::GetNext, &SqBuffer::SetNext)
.Prop(_SC("Back"), &SqBuffer::GetBack, &SqBuffer::SetBack)
.Prop(_SC("Prev"), &SqBuffer::GetPrev, &SqBuffer::SetPrev)
.Prop(_SC("Cursor"), &SqBuffer::GetCursor, &SqBuffer::SetCursor)
.Prop(_SC("Before"), &SqBuffer::GetBefore, &SqBuffer::SetBefore)
.Prop(_SC("After"), &SqBuffer::GetAfter, &SqBuffer::SetAfter)
.Prop(_SC("Max"), &SqBuffer::GetMax)
.Prop(_SC("Size"), &SqBuffer::GetSize, &SqBuffer::Adjust)
.Prop(_SC("Capacity"), &SqBuffer::GetCapacity, &SqBuffer::Adjust)
.Prop(_SC("Position"), &SqBuffer::GetPosition, &SqBuffer::Move)
.Prop(_SC("Remaining"), &SqBuffer::GetRemaining)
// Member Methods
.Func(_SC("Get"), &SqBuffer::Get)
.Func(_SC("Set"), &SqBuffer::Set)
.Func(_SC("Move"), &SqBuffer::Move)
.Func(_SC("Advance"), &SqBuffer::Advance)
.Func(_SC("Retreat"), &SqBuffer::Retreat)
.Func(_SC("Push"), &SqBuffer::Push)
.Func(_SC("Grow"), &SqBuffer::Grow)
.Func(_SC("Adjust"), &SqBuffer::Adjust)
.Func(_SC("WriteByte"), &SqBuffer::WriteUint8)
.Func(_SC("WriteShort"), &SqBuffer::WriteInt16)
.Func(_SC("WriteInt"), &SqBuffer::WriteInt32)
.Func(_SC("WriteFloat"), &SqBuffer::WriteFloat32)
.Func(_SC("WriteInt8"), &SqBuffer::WriteInt8)
.Func(_SC("WriteUint8"), &SqBuffer::WriteUint8)
.Func(_SC("WriteInt16"), &SqBuffer::WriteInt16)
.Func(_SC("WriteUint16"), &SqBuffer::WriteUint16)
.Func(_SC("WriteInt32"), &SqBuffer::WriteInt32)
.Func(_SC("WriteUint32"), &SqBuffer::WriteUint32)
.Func(_SC("WriteInt64"), &SqBuffer::WriteInt64)
.Func(_SC("WriteUint64"), &SqBuffer::WriteUint64)
.Func(_SC("WriteFloat32"), &SqBuffer::WriteFloat32)
.Func(_SC("WriteFloat64"), &SqBuffer::WriteFloat64)
.Func(_SC("WriteRawString"), &SqBuffer::WriteRawString)
.Func(_SC("WriteClientString"), &SqBuffer::WriteClientString)
.Func(_SC("WriteAABB"), &SqBuffer::WriteAABB)
.Func(_SC("WriteCircle"), &SqBuffer::WriteCircle)
.Func(_SC("WriteColor3"), &SqBuffer::WriteColor3)
.Func(_SC("WriteColor4"), &SqBuffer::WriteColor4)
.Func(_SC("WriteQuaternion"), &SqBuffer::WriteQuaternion)
.Func(_SC("WriteSphere"), &SqBuffer::WriteSphere)
.Func(_SC("WriteVector2"), &SqBuffer::WriteVector2)
.Func(_SC("WriteVector2i"), &SqBuffer::WriteVector2i)
.Func(_SC("WriteVector3"), &SqBuffer::WriteVector3)
.Func(_SC("WriteVector4"), &SqBuffer::WriteVector4)
.Func(_SC("ReadByte"), &SqBuffer::ReadUint8)
.Func(_SC("ReadShort"), &SqBuffer::ReadInt16)
.Func(_SC("ReadInt"), &SqBuffer::ReadInt32)
.Func(_SC("ReadFloat"), &SqBuffer::ReadFloat32)
.Func(_SC("ReadInt8"), &SqBuffer::ReadInt8)
.Func(_SC("ReadUint8"), &SqBuffer::ReadUint8)
.Func(_SC("ReadInt16"), &SqBuffer::ReadInt16)
.Func(_SC("ReadUint16"), &SqBuffer::ReadUint16)
.Func(_SC("ReadInt32"), &SqBuffer::ReadInt32)
.Func(_SC("ReadUint32"), &SqBuffer::ReadUint32)
.Func(_SC("ReadInt64"), &SqBuffer::ReadInt64)
.Func(_SC("ReadUint64"), &SqBuffer::ReadUint64)
.Func(_SC("ReadFloat32"), &SqBuffer::ReadFloat32)
.Func(_SC("ReadFloat64"), &SqBuffer::ReadFloat64)
.Func(_SC("ReadRawString"), &SqBuffer::ReadRawString)
.Func(_SC("ReadClientString"), &SqBuffer::ReadClientString)
.Func(_SC("ReadAABB"), &SqBuffer::ReadAABB)
.Func(_SC("ReadCircle"), &SqBuffer::ReadCircle)
.Func(_SC("ReadColor3"), &SqBuffer::ReadColor3)
.Func(_SC("ReadColor4"), &SqBuffer::ReadColor4)
.Func(_SC("ReadQuaternion"), &SqBuffer::ReadQuaternion)
.Func(_SC("ReadSphere"), &SqBuffer::ReadSphere)
.Func(_SC("ReadVector2"), &SqBuffer::ReadVector2)
.Func(_SC("ReadVector2i"), &SqBuffer::ReadVector2i)
.Func(_SC("ReadVector3"), &SqBuffer::ReadVector3)
.Func(_SC("ReadVector4"), &SqBuffer::ReadVector4)
);
}
} // Namespace:: SqMod

View File

@@ -0,0 +1,829 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Squirrel wrapper for the shared buffer class.
*/
class SqBuffer
{
private:
// --------------------------------------------------------------------------------------------
typedef SharedPtr< Buffer > SRef; // Strong reference type to the managed memory buffer.
typedef WeakPtr< Buffer > WRef; // Weak reference type to the managed memory buffer.
// --------------------------------------------------------------------------------------------
SRef m_Buffer; // The managed memory buffer.
public:
// --------------------------------------------------------------------------------------------
typedef Buffer::Value Value; // The type of value used to represent a byte.
// --------------------------------------------------------------------------------------------
typedef Value & Reference; // A reference to the stored value type.
typedef const Value & ConstRef; // A const reference to the stored value type.
// --------------------------------------------------------------------------------------------
typedef Value * Pointer; // A pointer to the stored value type.
typedef const Value * ConstPtr; // A const pointer to the stored value type.
// --------------------------------------------------------------------------------------------
typedef Buffer::SzType SzType; // The type used to represent size in general.
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
SqBuffer()
: m_Buffer(new Buffer())
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Allocate constructor.
*/
explicit SqBuffer(SQInteger n)
: m_Buffer(new Buffer(ConvTo< SzType >::From(n)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Allocate constructor.
*/
SqBuffer(SQInteger n, SQInteger c)
: m_Buffer(new Buffer(ConvTo< SzType >::From(n), ConvTo< SzType >::From(c)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SqBuffer(ConstPtr p, SQInteger n)
: m_Buffer(new Buffer(p, ConvTo< SzType >::From(n)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SqBuffer(ConstPtr p, SQInteger n, SQInteger c)
: m_Buffer(new Buffer(p, ConvTo< SzType >::From(n), ConvTo< SzType >::From(c)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Reference constructor.
*/
explicit SqBuffer(const SRef & ref) // NOLINT(modernize-pass-by-value)
: m_Buffer(ref)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Buffer constructor.
*/
explicit SqBuffer(const Buffer & b)
: m_Buffer(new Buffer(b))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Buffer constructor.
*/
explicit SqBuffer(Buffer && b)
: m_Buffer(new Buffer(std::move(b)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SqBuffer(const SqBuffer & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
SqBuffer(SqBuffer && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~SqBuffer() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
SqBuffer & operator = (const SqBuffer & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
SqBuffer & operator = (SqBuffer && o) = default;
/* --------------------------------------------------------------------------------------------
* Retrieve a reference to the managed memory buffer.
*/
SQMOD_NODISCARD const SRef & GetRef() const
{
return m_Buffer;
}
/* --------------------------------------------------------------------------------------------
* Validate the managed memory buffer reference.
*/
void Validate() const
{
// Do we even point to a valid buffer?
if (!m_Buffer)
{
STHROWF("Invalid memory buffer reference");
}
}
/* --------------------------------------------------------------------------------------------
* Validate the managed memory buffer reference and the buffer itself.
*/
void ValidateDeeper() const
{
// Do we even point to a valid buffer?
if (!m_Buffer)
{
STHROWF("Invalid memory buffer reference");
}
// Validate the buffer itself
else if (!(*m_Buffer))
{
STHROWF("Invalid memory buffer");
}
}
/* --------------------------------------------------------------------------------------------
* Retrieve a certain element type at the specified position.
*/
SQMOD_NODISCARD Value Get(SQInteger n) const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->At(ConvTo< SzType >::From(n));
}
/* --------------------------------------------------------------------------------------------
* Modify a certain element type at the specified position.
*/
void Set(SQInteger n, SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->At(ConvTo< SzType >::From(n)) = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the front of the buffer.
*/
SQMOD_NODISCARD Value GetFront() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Front();
}
/* --------------------------------------------------------------------------------------------
* Modify the element at the front of the buffer.
*/
void SetFront(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Front() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the first element in the buffer.
*/
SQMOD_NODISCARD Value GetNext() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Next();
}
/* --------------------------------------------------------------------------------------------
* Modify the element after the first element in the buffer.
*/
void SetNext(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Next() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the back of the buffer.
*/
SQMOD_NODISCARD Value GetBack() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Back();
}
/* --------------------------------------------------------------------------------------------
* Modify the element at the back of the buffer.
*/
void SetBack(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Back() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the last element in the buffer.
*/
SQMOD_NODISCARD Value GetPrev() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Prev();
}
/* --------------------------------------------------------------------------------------------
* Modify the element before the last element in the buffer.
*/
void SetPrev(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Prev() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to the specified number of elements ahead.
*/
void Advance(SQInteger n)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Advance(ConvTo< SzType >::From(n));
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to the specified number of elements behind.
*/
void Retreat(SQInteger n)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Retreat(ConvTo< SzType >::From(n));
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to a fixed position within the buffer.
*/
void Move(SQInteger n)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Move(ConvTo< SzType >::From(n));
}
/* --------------------------------------------------------------------------------------------
* Append a value to the current cursor location and advance the cursor.
*/
void Push(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push(ConvTo< Value >::From(v));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the cursor position.
*/
SQMOD_NODISCARD Value GetCursor() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Cursor();
}
/* --------------------------------------------------------------------------------------------
* Modify the element at the cursor position.
*/
void SetCursor(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Cursor() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the cursor position.
*/
SQMOD_NODISCARD Value GetBefore() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->Before();
}
/* --------------------------------------------------------------------------------------------
* Modify the element before the cursor position.
*/
void SetBefore(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->Before() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the cursor position.
*/
SQMOD_NODISCARD Value GetAfter() const
{
// Validate the managed buffer reference
Validate();
// Return the requested element
return m_Buffer->After();
}
/* --------------------------------------------------------------------------------------------
* Modify the element after the cursor position.
*/
void SetAfter(SQInteger v)
{
// Validate the managed buffer reference
Validate();
// Return the requested element
m_Buffer->After() = ConvTo< Value >::From(v);
}
/* --------------------------------------------------------------------------------------------
* Retrieve maximum elements it can hold for a certain type.
*/
SQMOD_NODISCARD SzType GetMax() const // NOLINT(readability-convert-member-functions-to-static)
{
return Buffer::Max();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in element count.
*/
SQMOD_NODISCARD SzType GetSize() const
{
// Validate the managed buffer reference
Validate();
// Return the requested information
return m_Buffer->CapacityAs< Value >();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in byte count.
*/
SQMOD_NODISCARD SzType GetCapacity() const
{
// Validate the managed buffer reference
Validate();
// Return the requested information
return m_Buffer->Capacity();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the current position of the cursor in the buffer.
*/
SQMOD_NODISCARD SzType GetPosition() const
{
// Validate the managed buffer reference
Validate();
// Return the requested information
return m_Buffer->Position();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of unused buffer after the edit cursor.
*/
SQMOD_NODISCARD SzType GetRemaining() const
{
// Validate the managed buffer reference
Validate();
// Return the requested information
return m_Buffer->Remaining();
}
/* --------------------------------------------------------------------------------------------
* Grow the size of the internal buffer by the specified amount of bytes.
*/
void Grow(SQInteger n)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
return m_Buffer->Grow(ConvTo< SzType >::From(n) * sizeof(Value));
}
/* --------------------------------------------------------------------------------------------
* Makes sure there is enough capacity to hold the specified element count.
*/
void Adjust(SQInteger n)
{
// Validate the managed buffer reference
Validate();
// Attempt to perform the requested operation
try
{
Buffer bkp(m_Buffer->Adjust(ConvTo< SzType >::From(n) * sizeof(Value)));
// Copy the data into the new buffer
m_Buffer->Write(0, bkp.Data(), bkp.Capacity());
m_Buffer->Move(bkp.Position());
}
catch (const std::exception & e)
{
STHROWF("%s", e.what()); // Re-package
}
}
/* --------------------------------------------------------------------------------------------
* Write a signed 8 bit integer to the buffer.
*/
void WriteInt8(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< int8_t >(ConvTo< int8_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write an unsigned 8 bit integer to the buffer.
*/
void WriteUint8(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< uint8_t >(ConvTo< uint8_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write a signed 16 bit integer to the buffer.
*/
void WriteInt16(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< int16_t >(ConvTo< int16_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write an unsigned 16 bit integer to the buffer.
*/
void WriteUint16(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< uint16_t >(ConvTo< uint16_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write a signed 32 bit integer to the buffer.
*/
void WriteInt32(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< int32_t >(ConvTo< int32_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write an unsigned 32 bit integer to the buffer.
*/
void WriteUint32(SQInteger val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< uint32_t >(ConvTo< uint32_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write a signed 64 bit integer to the buffer.
*/
void WriteInt64(const SLongInt & val);
/* --------------------------------------------------------------------------------------------
* Write an unsigned 64 bit integer to the buffer.
*/
void WriteUint64(const ULongInt & val);
/* --------------------------------------------------------------------------------------------
* Write a 32 bit float to the buffer.
*/
void WriteFloat32(SQFloat val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< float >(ConvTo< float >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write a 64 bit float to the buffer.
*/
void WriteFloat64(SQFloat val)
{
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< double >(ConvTo< double >::From(val));
}
/* --------------------------------------------------------------------------------------------
* Write a raw string to the buffer.
*/
SQInteger WriteRawString(StackStrF & val);
/* --------------------------------------------------------------------------------------------
* Write a client encoded string to the buffer.
*/
SQInteger WriteClientString(StackStrF & val);
/* --------------------------------------------------------------------------------------------
* Write a AABB to the buffer.
*/
void WriteAABB(const AABB & val);
/* --------------------------------------------------------------------------------------------
* Write a Circle to the buffer.
*/
void WriteCircle(const Circle & val);
/* --------------------------------------------------------------------------------------------
* Write a Color3 to the buffer.
*/
void WriteColor3(const Color3 & val);
/* --------------------------------------------------------------------------------------------
* Write a Color4 to the buffer.
*/
void WriteColor4(const Color4 & val);
/* --------------------------------------------------------------------------------------------
* Write a Quaternion to the buffer.
*/
void WriteQuaternion(const Quaternion & val);
/* --------------------------------------------------------------------------------------------
* Write a Sphere to the buffer.
*/
void WriteSphere(const Sphere &val);
/* --------------------------------------------------------------------------------------------
* Write a Vector2 to the buffer.
*/
void WriteVector2(const Vector2 & val);
/* --------------------------------------------------------------------------------------------
* Write a Vector2i to the buffer.
*/
void WriteVector2i(const Vector2i & val);
/* --------------------------------------------------------------------------------------------
* Write a Vector3 to the buffer.
*/
void WriteVector3(const Vector3 & val);
/* --------------------------------------------------------------------------------------------
* Write a Vector4 to the buffer.
*/
void WriteVector4(const Vector4 & val);
/* --------------------------------------------------------------------------------------------
* Write a signed 8 bit integer from the buffer.
*/
SQInteger ReadInt8()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const int8_t value = m_Buffer->Cursor< int8_t >();
// Advance the buffer cursor
m_Buffer->Advance< int8_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read an unsigned 8 bit integer from the buffer.
*/
SQInteger ReadUint8()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const uint8_t value = m_Buffer->Cursor< uint8_t >();
// Advance the buffer cursor
m_Buffer->Advance< uint8_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read a signed 16 bit integer from the buffer.
*/
SQInteger ReadInt16()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const int16_t value = m_Buffer->Cursor< int16_t >();
// Advance the buffer cursor
m_Buffer->Advance< int16_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read an unsigned 16 bit integer from the buffer.
*/
SQInteger ReadUint16()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const uint16_t value = m_Buffer->Cursor< uint16_t >();
// Advance the buffer cursor
m_Buffer->Advance< uint16_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read a signed 32 bit integer from the buffer.
*/
SQInteger ReadInt32()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const int32_t value = m_Buffer->Cursor< int32_t >();
// Advance the buffer cursor
m_Buffer->Advance< int32_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read an unsigned 32 bit integer from the buffer.
*/
SQInteger ReadUint32()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const uint32_t value = m_Buffer->Cursor< uint32_t >();
// Advance the buffer cursor
m_Buffer->Advance< uint32_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read a signed 64 bit integer from the buffer.
*/
SLongInt ReadInt64();
/* --------------------------------------------------------------------------------------------
* Read an unsigned 64 bit integer from the buffer.
*/
ULongInt ReadUint64();
/* --------------------------------------------------------------------------------------------
* Read a 32 bit float from the buffer.
*/
SQFloat ReadFloat32()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const float value = m_Buffer->Cursor< float >();
// Advance the buffer cursor
m_Buffer->Advance< float >(1);
// Return the requested information
return ConvTo< SQFloat >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read a 64 bit float from the buffer.
*/
SQFloat ReadFloat64()
{
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const double value = m_Buffer->Cursor< double >();
// Advance the buffer cursor
m_Buffer->Advance< double >(1);
// Return the requested information
return ConvTo< SQFloat >::From(value);
}
/* --------------------------------------------------------------------------------------------
* Read a raw string from the buffer.
*/
LightObj ReadRawString(SQInteger length);
/* --------------------------------------------------------------------------------------------
* Read a string from the buffer.
*/
LightObj ReadClientString();
/* --------------------------------------------------------------------------------------------
* Read a AABB from the buffer.
*/
AABB ReadAABB();
/* --------------------------------------------------------------------------------------------
* Read a Circle from the buffer.
*/
Circle ReadCircle();
/* --------------------------------------------------------------------------------------------
* Read a Color3 from the buffer.
*/
Color3 ReadColor3();
/* --------------------------------------------------------------------------------------------
* Read a Color4 from the buffer.
*/
Color4 ReadColor4();
/* --------------------------------------------------------------------------------------------
* Read a Quaternion from the buffer.
*/
Quaternion ReadQuaternion();
/* --------------------------------------------------------------------------------------------
* Read a Sphere from the buffer.
*/
Sphere ReadSphere();
/* --------------------------------------------------------------------------------------------
* Read a Vector2 from the buffer.
*/
Vector2 ReadVector2();
/* --------------------------------------------------------------------------------------------
* Read a Vector2i from the buffer.
*/
Vector2i ReadVector2i();
/* --------------------------------------------------------------------------------------------
* Read a Vector3 from the buffer.
*/
Vector3 ReadVector3();
/* --------------------------------------------------------------------------------------------
* Read a Vector4 from the buffer.
*/
Vector4 ReadVector4();
};
} // Namespace:: SqMod

View File

@@ -2,15 +2,15 @@
#include "Library/IO/INI.hpp"
// ------------------------------------------------------------------------------------------------
#include <cerrno>
#include <sqratConst.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(ResultTypename, _SC("SqIniResult"))
SQMODE_DECL_TYPENAME(EntriesTypename, _SC("SqIniEntries"))
SQMODE_DECL_TYPENAME(DocumentTypename, _SC("SqIniDocument"))
SQMOD_DECL_TYPENAME(ResultTypename, _SC("SqIniResult"))
SQMOD_DECL_TYPENAME(EntriesTypename, _SC("SqIniEntries"))
SQMOD_DECL_TYPENAME(DocumentTypename, _SC("SqIniDocument"))
// ------------------------------------------------------------------------------------------------
void IniResult::Check() const
@@ -30,7 +30,7 @@ void IniResult::Check() const
case SI_OK:
case SI_UPDATED:
case SI_INSERTED:
break; /* These are not error messahes. */
break; /* These are not error messages. */
default:
STHROWF("Unable to %s for some unforeseen reason", m_Action.c_str());
}
@@ -47,7 +47,7 @@ void IniDocumentRef::Validate() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::Cmp(const IniEntries & o) const
int32_t IniEntries::Cmp(const IniEntries & o) const
{
if (m_Elem == o.m_Elem)
{
@@ -84,7 +84,7 @@ void IniEntries::Prev()
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Advance(Int32 n)
void IniEntries::Advance(int32_t n)
{
// Are there any other elements ahead?
if (m_List.empty() || m_Elem == m_List.end())
@@ -99,7 +99,7 @@ void IniEntries::Advance(Int32 n)
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Retreat(Int32 n)
void IniEntries::Retreat(int32_t n)
{
// Are there any other elements behind?
if (m_List.empty() || m_Elem == m_List.begin())
@@ -114,7 +114,7 @@ void IniEntries::Retreat(Int32 n)
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetItem() const
const SQChar * IniEntries::GetItem() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -126,7 +126,7 @@ CSStr IniEntries::GetItem() const
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetComment() const
const SQChar * IniEntries::GetComment() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -138,7 +138,7 @@ CSStr IniEntries::GetComment() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::GetOrder() const
int32_t IniEntries::GetOrder() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -150,7 +150,7 @@ Int32 IniEntries::GetOrder() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::Cmp(const IniDocument & o) const
int32_t IniDocument::Cmp(const IniDocument & o) const
{
if (m_Doc == o.m_Doc)
{
@@ -167,7 +167,7 @@ Int32 IniDocument::Cmp(const IniDocument & o) const
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::LoadFile(CSStr filepath)
IniResult IniDocument::LoadFile(const SQChar * filepath)
{
// Validate the handle
m_Doc.Validate();
@@ -176,7 +176,7 @@ IniResult IniDocument::LoadFile(CSStr filepath)
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::LoadData(CSStr source, Int32 size)
IniResult IniDocument::LoadData(const SQChar * source, int32_t size)
{
// Validate the handle
m_Doc.Validate();
@@ -185,7 +185,7 @@ IniResult IniDocument::LoadData(CSStr source, Int32 size)
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SaveFile(CSStr filepath, bool signature)
IniResult IniDocument::SaveFile(const SQChar * filepath, bool signature)
{
// Validate the handle
m_Doc.Validate();
@@ -227,7 +227,7 @@ IniEntries IniDocument::GetAllSections() const
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllKeys(CSStr section) const
IniEntries IniDocument::GetAllKeys(const SQChar * section) const
{
// Validate the handle
m_Doc.Validate();
@@ -240,7 +240,7 @@ IniEntries IniDocument::GetAllKeys(CSStr section) const
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllValues(CSStr section, CSStr key) const
IniEntries IniDocument::GetAllValues(const SQChar * section, const SQChar * key) const
{
// Validate the handle
m_Doc.Validate();
@@ -253,7 +253,7 @@ IniEntries IniDocument::GetAllValues(CSStr section, CSStr key) const
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::GetSectionSize(CSStr section) const
int32_t IniDocument::GetSectionSize(const SQChar * section) const
{
// Validate the handle
m_Doc.Validate();
@@ -262,11 +262,11 @@ Int32 IniDocument::GetSectionSize(CSStr section) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
bool IniDocument::HasMultipleKeys(const SQChar * section, const SQChar * key) const
{
// Validate the handle
m_Doc.Validate();
// Where to retrive whether the key has multiple instances
// Where to retrieve whether the key has multiple instances
bool multiple = false;
// Attempt to query the information
if (m_Doc->GetValue(section, key, nullptr, &multiple) == nullptr)
@@ -278,7 +278,7 @@ bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
}
// ------------------------------------------------------------------------------------------------
CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
const char * IniDocument::GetValue(const SQChar * section, const SQChar * key, const SQChar * def) const
{
// Validate the handle
m_Doc.Validate();
@@ -287,16 +287,16 @@ CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
}
// ------------------------------------------------------------------------------------------------
SQInteger IniDocument::GetInteger(CSStr section, CSStr key, SQInteger def) const
SQInteger IniDocument::GetInteger(const SQChar * section, const SQChar * key, SQInteger def) const
{
// Validate the handle
m_Doc.Validate();
// Attempt to query the information and return it
return static_cast< SQInteger >(m_Doc->GetLongValue(section, key, def, nullptr));
return static_cast< SQInteger >(m_Doc->GetLongValue(section, key, static_cast< long >(def), nullptr));
}
// ------------------------------------------------------------------------------------------------
SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
SQFloat IniDocument::GetFloat(const SQChar * section, const SQChar * key, SQFloat def) const
{
// Validate the handle
m_Doc.Validate();
@@ -305,7 +305,7 @@ SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
bool IniDocument::GetBoolean(const SQChar * section, const SQChar * key, bool def) const
{
// Validate the handle
m_Doc.Validate();
@@ -314,7 +314,7 @@ bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment)
IniResult IniDocument::SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -323,16 +323,16 @@ IniResult IniDocument::SetValue(CSStr section, CSStr key, CSStr value, bool forc
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment)
IniResult IniDocument::SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
// Attempt to apply the specified information and return the result
return IniResult("set INI integer", m_Doc->SetLongValue(section, key, value, comment, hex, force));
return IniResult("set INI integer", m_Doc->SetLongValue(section, key, static_cast< long >(value), comment, hex, force));
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment)
IniResult IniDocument::SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -341,7 +341,7 @@ IniResult IniDocument::SetFloat(CSStr section, CSStr key, SQFloat value, bool fo
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment)
IniResult IniDocument::SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -350,7 +350,7 @@ IniResult IniDocument::SetBoolean(CSStr section, CSStr key, bool value, bool for
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::DeleteValue(CSStr section, CSStr key, CSStr value, bool empty)
bool IniDocument::DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value, bool empty)
{
// Validate the handle
m_Doc.Validate();
@@ -367,7 +367,7 @@ void Register_INI(HSQUIRRELVM vm)
Class< IniResult >(vm, ResultTypename::Str)
// Constructors
.Ctor()
.Ctor< CSStr, SQInteger >()
.Ctor< const SQChar *, SQInteger >()
.Ctor< const IniResult & >()
// Core Meta-methods
.SquirrelFunc(_SC("_typename"), &ResultTypename::Fn)
@@ -431,10 +431,10 @@ void Register_INI(HSQUIRRELVM vm)
// Member Methods
.Func(_SC("Reset"), &IniDocument::Reset)
.Func(_SC("LoadFile"), &IniDocument::LoadFile)
.Overload< IniResult (IniDocument::*)(CSStr) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(CSStr, Int32) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(CSStr) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(CSStr, bool) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(const SQChar *) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(const SQChar *, int32_t) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(const SQChar *) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(const SQChar *, bool) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Func(_SC("SaveData"), &IniDocument::SaveData)
.Func(_SC("GetSections"), &IniDocument::GetAllSections)
.Func(_SC("GetKeys"), &IniDocument::GetAllKeys)
@@ -445,34 +445,34 @@ void Register_INI(HSQUIRRELVM vm)
.Func(_SC("GetInteger"), &IniDocument::GetInteger)
.Func(_SC("GetFloat"), &IniDocument::GetFloat)
.Func(_SC("GetBoolean"), &IniDocument::GetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr, bool, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool, CSStr) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat, bool) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat, bool, CSStr) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool, bool, CSStr) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< bool (IniDocument::*)(CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool, const SQChar *) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool, bool, const SQChar *) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat, bool) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat, bool, const SQChar *) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool, bool, const SQChar *) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< bool (IniDocument::*)(const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
);
RootTable(vm).Bind(_SC("SqIni"), inins);
ConstTable(vm).Enum(_SC("SqIniError"), Enumeration(vm)
.Const(_SC("Ok"), Int32(SI_OK))
.Const(_SC("Updated"), Int32(SI_UPDATED))
.Const(_SC("Inserted"), Int32(SI_INSERTED))
.Const(_SC("Fail"), Int32(SI_FAIL))
.Const(_SC("NoMem"), Int32(SI_NOMEM))
.Const(_SC("File"), Int32(SI_FILE))
.Const(_SC("Ok"), int32_t(SI_OK))
.Const(_SC("Updated"), int32_t(SI_UPDATED))
.Const(_SC("Inserted"), int32_t(SI_INSERTED))
.Const(_SC("Fail"), int32_t(SI_FAIL))
.Const(_SC("NoMem"), int32_t(SI_NOMEM))
.Const(_SC("File"), int32_t(SI_FILE))
);
}

View File

@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <SimpleIni.h>
@@ -34,7 +34,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Construct with no specific result.
*/
explicit IniResult(CSStr action)
explicit IniResult(const SQChar * action)
: m_Action(!action ? _SC("") : action), m_Result(SI_OK)
{
/* ... */
@@ -52,7 +52,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Construct with specific action and result.
*/
IniResult(CSStr action, SQInteger result)
IniResult(const SQChar * action, SQInteger result)
: m_Action(!action ? _SC("") : action), m_Result(result)
{
/* ... */
@@ -61,30 +61,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
IniResult(const IniResult & o)
: m_Action(o.m_Action), m_Result(o.m_Result)
{
/* ... */
}
IniResult(const IniResult & o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniResult()
{
/* ... */
}
~IniResult() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniResult & operator = (const IniResult & o)
{
m_Action = o.m_Action;
m_Result = o.m_Result;
return *this;
}
IniResult & operator = (const IniResult & o) = default;
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two results.
@@ -105,7 +92,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
operator bool () const // NOLINT(google-explicit-constructor)
{
return (m_Result >= 0);
}
@@ -113,7 +100,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniResult & o) const
SQMOD_NODISCARD int32_t Cmp(const IniResult & o) const
{
if (m_Result == o.m_Result)
{
@@ -132,7 +119,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const
{
return m_Action.c_str();
}
@@ -140,7 +127,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this instance references a valid INI result.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return (m_Result >= 0);
}
@@ -148,7 +135,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated action.
*/
CSStr GetAction() const
SQMOD_NODISCARD const SQChar * GetAction() const
{
return m_Action.c_str();
}
@@ -156,7 +143,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the resulted code.
*/
SQInteger GetResult() const
SQMOD_NODISCARD SQInteger GetResult() const
{
return m_Result;
}
@@ -222,8 +209,8 @@ private:
{
delete m_Ptr;
delete m_Ref;
m_Ptr = NULL;
m_Ref = NULL;
m_Ptr = nullptr;
m_Ref = nullptr;
}
}
@@ -242,7 +229,7 @@ public:
* Default constructor (null).
*/
IniDocumentRef()
: m_Ptr(NULL), m_Ref(NULL)
: m_Ptr(nullptr), m_Ref(nullptr)
{
/* ... */
}
@@ -260,12 +247,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
IniDocumentRef(IniDocumentRef && o)
IniDocumentRef(IniDocumentRef && o) noexcept
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
{
o.m_Ptr = NULL;
o.m_Ref = NULL;
o.m_Ptr = nullptr;
o.m_Ref = nullptr;
}
/* --------------------------------------------------------------------------------------------
@@ -279,7 +266,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniDocumentRef & operator = (const IniDocumentRef & o)
IniDocumentRef & operator = (const IniDocumentRef & o) noexcept // NOLINT(bugprone-unhandled-self-assignment)
{
if (m_Ptr != o.m_Ptr)
{
@@ -294,14 +281,14 @@ public:
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
IniDocumentRef & operator = (IniDocumentRef && o)
IniDocumentRef & operator = (IniDocumentRef && o) noexcept
{
if (m_Ptr != o.m_Ptr)
{
m_Ptr = o.m_Ptr;
m_Ref = o.m_Ref;
o.m_Ptr = NULL;
o.m_Ref = NULL;
o.m_Ptr = nullptr;
o.m_Ref = nullptr;
}
return *this;
}
@@ -325,7 +312,15 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
operator bool () const // NOLINT(google-explicit-constructor)
{
return static_cast< bool >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator Pointer () // NOLINT(google-explicit-constructor)
{
return m_Ptr;
}
@@ -333,15 +328,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator Pointer ()
{
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator ConstPtr () const
operator ConstPtr () const // NOLINT(google-explicit-constructor)
{
return m_Ptr;
}
@@ -349,7 +336,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance reference.
*/
operator Reference ()
operator Reference () // NOLINT(google-explicit-constructor)
{
assert(m_Ptr);
return *m_Ptr;
@@ -358,7 +345,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance reference.
*/
operator ConstRef () const
operator ConstRef () const // NOLINT(google-explicit-constructor)
{
assert(m_Ptr);
return *m_Ptr;
@@ -385,7 +372,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of active references to the managed instance.
*/
Counter Count() const
SQMOD_NODISCARD Counter Count() const
{
return (m_Ptr && m_Ref) ? (*m_Ref) : 0;
}
@@ -410,7 +397,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
IniEntries(const IniDocumentRef & ini, Container & list)
IniEntries(const IniDocumentRef & ini, Container & list) // NOLINT(modernize-pass-by-value)
: m_Doc(ini), m_List(), m_Elem()
{
m_List.swap(list);
@@ -447,10 +434,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniEntries()
{
/* ... */
}
~IniEntries() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
@@ -466,12 +450,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniEntries & o) const;
SQMOD_NODISCARD int32_t Cmp(const IniEntries & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const
{
return GetItem();
}
@@ -479,7 +463,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return whether the current element is valid and can be accessed.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return !(m_List.empty() || m_Elem == m_List.end());
}
@@ -487,7 +471,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return whether the entry list is empty.
*/
bool IsEmpty() const
SQMOD_NODISCARD bool IsEmpty() const
{
return m_List.empty();
}
@@ -495,7 +479,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this document instance.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Doc.Count();
}
@@ -503,9 +487,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the total entries in the list.
*/
Int32 GetSize() const
SQMOD_NODISCARD int32_t GetSize() const
{
return static_cast< Int32 >(m_List.size());
return static_cast< int32_t >(m_List.size());
}
/* --------------------------------------------------------------------------------------------
@@ -536,12 +520,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Advance a certain number of elements.
*/
void Advance(Int32 n);
void Advance(int32_t n);
/* --------------------------------------------------------------------------------------------
* Retreat a certain number of elements.
*/
void Retreat(Int32 n);
void Retreat(int32_t n);
/* --------------------------------------------------------------------------------------------
* Sort the entries using the default options.
@@ -579,17 +563,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the string value of the current element item.
*/
CSStr GetItem() const;
SQMOD_NODISCARD const SQChar * GetItem() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the string value of the current element comment.
*/
CSStr GetComment() const;
SQMOD_NODISCARD const SQChar * GetComment() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the order of the current element.
*/
Int32 GetOrder() const;
SQMOD_NODISCARD int32_t GetOrder() const;
};
/* ------------------------------------------------------------------------------------------------
@@ -602,16 +586,6 @@ protected:
// --------------------------------------------------------------------------------------------
typedef IniDocumentRef::Type::TNamesDepend Container;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
IniDocument(const IniDocument & o);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
IniDocument & operator = (const IniDocument & o);
private:
// ---------------------------------------------------------------------------------------------
@@ -631,7 +605,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
IniDocument(bool utf8)
explicit IniDocument(bool utf8)
: m_Doc(utf8, false, true)
{
/* ... */
@@ -655,23 +629,30 @@ public:
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
IniDocument(const IniDocument & o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniDocument()
{
/* ... */
}
~IniDocument() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
IniDocument & operator = (const IniDocument & o) = delete;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniDocument & o) const;
SQMOD_NODISCARD int32_t Cmp(const IniDocument & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const // NOLINT(readability-convert-member-functions-to-static)
{
return _SC("");
}
@@ -679,7 +660,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this instance references a valid INI document.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return m_Doc;
}
@@ -687,7 +668,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this document instance.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Doc.Count();
}
@@ -695,7 +676,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether any data has been loaded into this document.
*/
bool IsEmpty() const
SQMOD_NODISCARD bool IsEmpty() const
{
return m_Doc->IsEmpty();
}
@@ -711,7 +692,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the INI data is treated as unicode.
*/
bool GetUnicode() const
SQMOD_NODISCARD bool GetUnicode() const
{
return m_Doc->IsUnicode();
}
@@ -727,7 +708,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether multiple identical keys be permitted in the file.
*/
bool GetMultiKey() const
SQMOD_NODISCARD bool GetMultiKey() const
{
return m_Doc->IsMultiKey();
}
@@ -743,7 +724,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether data values are permitted to span multiple lines in the file.
*/
bool GetMultiLine() const
SQMOD_NODISCARD bool GetMultiLine() const
{
return m_Doc->IsMultiLine();
}
@@ -759,7 +740,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether spaces are added around the equals sign when writing key/value pairs out.
*/
bool GetSpaces() const
SQMOD_NODISCARD bool GetSpaces() const
{
return m_Doc->UsingSpaces();
}
@@ -775,12 +756,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Load an INI file from disk into memory.
*/
IniResult LoadFile(CSStr filepath);
IniResult LoadFile(const SQChar * filepath);
/* --------------------------------------------------------------------------------------------
* Load INI file data direct from a string. (LoadString collides with the windows api)
*/
IniResult LoadData(CSStr source)
IniResult LoadData(const SQChar * source)
{
return LoadData(source, -1);
}
@@ -788,12 +769,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Load INI file data direct from a string. (LoadString collides with the windows api)
*/
IniResult LoadData(CSStr source, Int32 size);
IniResult LoadData(const SQChar * source, int32_t size);
/* --------------------------------------------------------------------------------------------
* Save an INI file from memory to disk.
*/
IniResult SaveFile(CSStr filepath)
IniResult SaveFile(const SQChar * filepath)
{
return SaveFile(filepath, true);
}
@@ -801,7 +782,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Save an INI file from memory to disk.
*/
IniResult SaveFile(CSStr filepath, bool signature);
IniResult SaveFile(const SQChar * filepath, bool signature);
/* --------------------------------------------------------------------------------------------
* Save the INI data to a string.
@@ -811,52 +792,52 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all section names.
*/
IniEntries GetAllSections() const;
SQMOD_NODISCARD IniEntries GetAllSections() const;
/* --------------------------------------------------------------------------------------------
* Retrieve all unique key names in a section.
*/
IniEntries GetAllKeys(CSStr section) const;
SQMOD_NODISCARD IniEntries GetAllKeys(const SQChar * section) const;
/* --------------------------------------------------------------------------------------------
* Retrieve all values for a specific key.
*/
IniEntries GetAllValues(CSStr section, CSStr key) const;
SQMOD_NODISCARD IniEntries GetAllValues(const SQChar * section, const SQChar * key) const;
/* --------------------------------------------------------------------------------------------
* Query the number of keys in a specific section.
*/
Int32 GetSectionSize(CSStr section) const;
SQMOD_NODISCARD int32_t GetSectionSize(const SQChar * section) const;
/* --------------------------------------------------------------------------------------------
* See whether a certain key has multiple instances.
*/
bool HasMultipleKeys(CSStr section, CSStr key) const;
SQMOD_NODISCARD bool HasMultipleKeys(const SQChar * section, const SQChar * key) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the value for a specific key.
*/
CCStr GetValue(CSStr section, CSStr key, CSStr def) const;
SQMOD_NODISCARD const char * GetValue(const SQChar * section, const SQChar * key, const SQChar * def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a numeric value for a specific key.
*/
SQInteger GetInteger(CSStr section, CSStr key, SQInteger def) const;
SQMOD_NODISCARD SQInteger GetInteger(const SQChar * section, const SQChar * key, SQInteger def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a numeric value for a specific key.
*/
SQFloat GetFloat(CSStr section, CSStr key, SQFloat def) const;
SQMOD_NODISCARD SQFloat GetFloat(const SQChar * section, const SQChar * key, SQFloat def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a boolean value for a specific key.
*/
bool GetBoolean(CSStr section, CSStr key, bool def) const;
SQMOD_NODISCARD bool GetBoolean(const SQChar * section, const SQChar * key, bool def) const;
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value)
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value)
{
return SetValue(section, key, value, false, nullptr);
}
@@ -864,7 +845,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value, bool force)
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force)
{
return SetValue(section, key, value, force, nullptr);
}
@@ -872,12 +853,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment);
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value)
{
return SetInteger(section, key, value, false, false, nullptr);
}
@@ -885,7 +866,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex)
{
return SetInteger(section, key, value, hex, false, nullptr);
}
@@ -893,7 +874,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force)
{
return SetInteger(section, key, value, hex, force, nullptr);
}
@@ -901,12 +882,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment);
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value)
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value)
{
return SetFloat(section, key, value, false, nullptr);
}
@@ -914,7 +895,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value, bool force)
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force)
{
return SetFloat(section, key, value, force, nullptr);
}
@@ -922,12 +903,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment);
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value)
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value)
{
return SetBoolean(section, key, value, false, nullptr);
}
@@ -935,7 +916,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value, bool force)
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force)
{
return SetBoolean(section, key, value, force, nullptr);
}
@@ -943,12 +924,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a boolean value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment);
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section)
bool DeleteValue(const SQChar * section)
{
return DeleteValue(section, nullptr, nullptr, false);
}
@@ -956,7 +937,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key)
bool DeleteValue(const SQChar * section, const SQChar * key)
{
return DeleteValue(section, key, nullptr, false);
}
@@ -964,7 +945,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key, CSStr value)
bool DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value)
{
return DeleteValue(section, key, value, false);
}
@@ -972,7 +953,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key, CSStr value, bool empty);
bool DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value, bool empty);
};
} // Namespace:: SqMod

View File

View File

View File

View File