2016-05-24 17:37:34 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Library/IO/INI.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include <sqratConst.h>
|
2016-05-24 17:37:34 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(ResultTypename, _SC("SqIniResult"))
|
|
|
|
SQMOD_DECL_TYPENAME(EntriesTypename, _SC("SqIniEntries"))
|
|
|
|
SQMOD_DECL_TYPENAME(DocumentTypename, _SC("SqIniDocument"))
|
2016-05-24 17:37:34 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void IniResult::Check() const
|
|
|
|
{
|
|
|
|
// Identify the error type
|
|
|
|
switch (m_Result)
|
|
|
|
{
|
|
|
|
case SI_FAIL:
|
|
|
|
STHROWF("Unable to %s. Probably invalid", m_Action.c_str());
|
|
|
|
break;
|
|
|
|
case SI_NOMEM:
|
|
|
|
STHROWF("Unable to %s. Ran out of memory", m_Action.c_str());
|
|
|
|
break;
|
|
|
|
case SI_FILE:
|
|
|
|
STHROWF("Unable to %s. %s", strerror(errno));
|
|
|
|
break;
|
|
|
|
case SI_OK:
|
|
|
|
case SI_UPDATED:
|
|
|
|
case SI_INSERTED:
|
2021-01-30 07:51:39 +01:00
|
|
|
break; /* These are not error messages. */
|
2016-05-24 17:37:34 +02:00
|
|
|
default:
|
|
|
|
STHROWF("Unable to %s for some unforeseen reason", m_Action.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 00:33:11 +01:00
|
|
|
void IniDocumentRef::Validate() const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Is the document handle valid?
|
|
|
|
if (!m_Ptr)
|
|
|
|
{
|
|
|
|
STHROWF("Invalid INI document reference");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t IniEntries::Cmp(const IniEntries & o) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
if (m_Elem == o.m_Elem)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (m_List.size() > o.m_List.size())
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 00:33:11 +01:00
|
|
|
void IniEntries::Next()
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Are there any other elements ahead?
|
|
|
|
if (!m_List.empty() && m_Elem != m_List.end())
|
|
|
|
{
|
|
|
|
++m_Elem; // Go ahead one element
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 00:33:11 +01:00
|
|
|
void IniEntries::Prev()
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Are there any other elements behind?
|
|
|
|
if (!m_List.empty() && m_Elem != m_List.begin())
|
|
|
|
{
|
|
|
|
--m_Elem; // Go back one element
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void IniEntries::Advance(int32_t n)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Are there any other elements ahead?
|
|
|
|
if (m_List.empty() || m_Elem == m_List.end())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Jump as many elements as possible within the specified distance
|
|
|
|
while ((--n >= 0) && m_Elem != m_List.end())
|
|
|
|
{
|
|
|
|
++m_Elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void IniEntries::Retreat(int32_t n)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Are there any other elements behind?
|
|
|
|
if (m_List.empty() || m_Elem == m_List.begin())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Jump as many elements as possible within the specified distance
|
|
|
|
while ((--n >= 0) && m_Elem != m_List.begin())
|
|
|
|
{
|
|
|
|
--m_Elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const SQChar * IniEntries::GetItem() const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// is the current element valid?
|
|
|
|
if (m_List.empty() || m_Elem == m_List.end())
|
|
|
|
{
|
|
|
|
STHROWF("Invalid INI entry [item]");
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return m_Elem->pItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const SQChar * IniEntries::GetComment() const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// is the current element valid?
|
|
|
|
if (m_List.empty() || m_Elem == m_List.end())
|
|
|
|
{
|
|
|
|
STHROWF("Invalid INI entry [comment]");
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return m_Elem->pComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t IniEntries::GetOrder() const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// is the current element valid?
|
|
|
|
if (m_List.empty() || m_Elem == m_List.end())
|
|
|
|
{
|
|
|
|
STHROWF("Invalid INI entry [order]");
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return m_Elem->nOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t IniDocument::Cmp(const IniDocument & o) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
if (m_Doc == o.m_Doc)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (m_Doc.m_Ptr > o.m_Doc.m_Ptr)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::LoadFile(const SQChar * filepath)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to load the file from disk and return the result
|
|
|
|
return IniResult("load INI file", m_Doc->LoadFile(filepath));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::LoadData(const SQChar * source, int32_t size)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to load the file from memory and return the result
|
|
|
|
return IniResult("load INI file", m_Doc->LoadData(source, size < 0 ? strlen(source) : size));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::SaveFile(const SQChar * filepath, bool signature)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to save the file to disk and return the result
|
|
|
|
return IniResult("save INI file", m_Doc->SaveFile(filepath, signature));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 00:33:11 +01:00
|
|
|
Object IniDocument::SaveData(bool signature)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// The string where the content will be saved
|
|
|
|
String source;
|
|
|
|
// Attempt to save the data to string
|
|
|
|
if (m_Doc->Save(source, signature) < 0)
|
|
|
|
{
|
|
|
|
STHROWF("Unable to save INI document");
|
|
|
|
}
|
|
|
|
// Obtain the initial stack size
|
2020-04-27 12:10:54 +02:00
|
|
|
const StackGuard sg(SqVM());
|
2016-05-24 17:37:34 +02:00
|
|
|
// Transform it into a script object
|
2020-04-27 12:10:54 +02:00
|
|
|
sq_pushstring(SqVM(), source.c_str(), source.size());
|
2016-05-24 17:37:34 +02:00
|
|
|
// Get the object from the stack and return it
|
2020-04-27 12:10:54 +02:00
|
|
|
return Var< Object >(SqVM(), -1).value;
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 00:33:11 +01:00
|
|
|
IniEntries IniDocument::GetAllSections() const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Prepare a container to receive the entries
|
|
|
|
static Container entries;
|
|
|
|
// Obtain all sections from the INI document
|
|
|
|
m_Doc->GetAllSections(entries);
|
|
|
|
// Return the entries and take over content
|
2020-03-22 00:33:11 +01:00
|
|
|
return IniEntries(m_Doc, entries);
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniEntries IniDocument::GetAllKeys(const SQChar * section) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Prepare a container to receive the entries
|
|
|
|
static Container entries;
|
|
|
|
// Obtain all sections from the INI document
|
|
|
|
m_Doc->GetAllKeys(section, entries);
|
|
|
|
// Return the entries and take over content
|
2020-03-22 00:33:11 +01:00
|
|
|
return IniEntries(m_Doc, entries);
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniEntries IniDocument::GetAllValues(const SQChar * section, const SQChar * key) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Prepare a container to receive the entries
|
|
|
|
static Container entries;
|
|
|
|
// Obtain all sections from the INI document
|
|
|
|
m_Doc->GetAllValues(section, key, entries);
|
|
|
|
// Return the entries and take over content
|
2020-03-22 00:33:11 +01:00
|
|
|
return IniEntries(m_Doc, entries);
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t IniDocument::GetSectionSize(const SQChar * section) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Doc->GetSectionSize(section);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
bool IniDocument::HasMultipleKeys(const SQChar * section, const SQChar * key) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
2021-01-30 07:51:39 +01:00
|
|
|
// Where to retrieve whether the key has multiple instances
|
2016-05-24 17:37:34 +02:00
|
|
|
bool multiple = false;
|
|
|
|
// Attempt to query the information
|
|
|
|
if (m_Doc->GetValue(section, key, nullptr, &multiple) == nullptr)
|
|
|
|
{
|
|
|
|
return true; // Doesn't exist
|
|
|
|
}
|
|
|
|
// Return the result
|
|
|
|
return multiple;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const char * IniDocument::GetValue(const SQChar * section, const SQChar * key, const SQChar * def) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to query the information and return it
|
|
|
|
return m_Doc->GetValue(section, key, def, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQInteger IniDocument::GetInteger(const SQChar * section, const SQChar * key, SQInteger def) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to query the information and return it
|
2021-01-30 07:51:39 +01:00
|
|
|
return static_cast< SQInteger >(m_Doc->GetLongValue(section, key, static_cast< long >(def), nullptr));
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQFloat IniDocument::GetFloat(const SQChar * section, const SQChar * key, SQFloat def) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to query the information and return it
|
|
|
|
return static_cast< SQFloat >(m_Doc->GetDoubleValue(section, key, def, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
bool IniDocument::GetBoolean(const SQChar * section, const SQChar * key, bool def) const
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to query the information and return it
|
|
|
|
return m_Doc->GetBoolValue(section, key, def, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force, const SQChar * comment)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to apply the specified information and return the result
|
|
|
|
return IniResult("set INI value", m_Doc->SetValue(section, key, value, comment, force));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force, const SQChar * comment)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to apply the specified information and return the result
|
2021-01-30 07:51:39 +01:00
|
|
|
return IniResult("set INI integer", m_Doc->SetLongValue(section, key, static_cast< long >(value), comment, hex, force));
|
2016-05-24 17:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force, const SQChar * comment)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to apply the specified information and return the result
|
|
|
|
return IniResult("set INI float", m_Doc->SetDoubleValue(section, key, value, comment, force));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
IniResult IniDocument::SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force, const SQChar * comment)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to apply the specified information
|
|
|
|
return IniResult("set INI boolean", m_Doc->SetBoolValue(section, key, value, comment, force));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
bool IniDocument::DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value, bool empty)
|
2016-05-24 17:37:34 +02:00
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
m_Doc.Validate();
|
|
|
|
// Attempt to remove the specified value and return the result
|
|
|
|
return m_Doc->DeleteValue(section, key, value, empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
void Register_INI(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
Table inins(vm);
|
|
|
|
|
2016-11-15 20:42:00 +01:00
|
|
|
inins.Bind(_SC("Result"),
|
|
|
|
Class< IniResult >(vm, ResultTypename::Str)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Constructors
|
|
|
|
.Ctor()
|
2021-01-30 07:51:39 +01:00
|
|
|
.Ctor< const SQChar *, SQInteger >()
|
2016-05-24 17:37:34 +02:00
|
|
|
.Ctor< const IniResult & >()
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-11-15 20:42:00 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &ResultTypename::Fn)
|
2016-05-24 17:37:34 +02:00
|
|
|
.Func(_SC("_tostring"), &IniResult::ToString)
|
2016-11-15 20:55:03 +01:00
|
|
|
.Func(_SC("cmp"), &IniResult::Cmp)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("Valid"), &IniResult::IsValid)
|
|
|
|
.Prop(_SC("Action"), &IniResult::GetAction)
|
|
|
|
.Prop(_SC("Result"), &IniResult::GetResult)
|
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("Check"), &IniResult::Check)
|
|
|
|
);
|
|
|
|
|
2020-03-22 00:33:11 +01:00
|
|
|
inins.Bind(_SC("IniEntries"),
|
|
|
|
Class< IniEntries >(vm, EntriesTypename::Str)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Constructors
|
|
|
|
.Ctor()
|
2020-03-22 00:33:11 +01:00
|
|
|
.Ctor< const IniEntries & >()
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-11-15 20:42:00 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &EntriesTypename::Fn)
|
2020-03-22 00:33:11 +01:00
|
|
|
.Func(_SC("_tostring"), &IniEntries::ToString)
|
|
|
|
.Func(_SC("cmp"), &IniEntries::Cmp)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Properties
|
2020-03-22 00:33:11 +01:00
|
|
|
.Prop(_SC("Valid"), &IniEntries::IsValid)
|
|
|
|
.Prop(_SC("Empty"), &IniEntries::IsEmpty)
|
|
|
|
.Prop(_SC("References"), &IniEntries::GetRefCount)
|
|
|
|
.Prop(_SC("Size"), &IniEntries::GetSize)
|
|
|
|
.Prop(_SC("Item"), &IniEntries::GetItem)
|
|
|
|
.Prop(_SC("Comment"), &IniEntries::GetComment)
|
|
|
|
.Prop(_SC("Order"), &IniEntries::GetOrder)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Member Methods
|
2020-03-22 00:33:11 +01:00
|
|
|
.Func(_SC("Reset"), &IniEntries::Reset)
|
|
|
|
.Func(_SC("Next"), &IniEntries::Next)
|
|
|
|
.Func(_SC("Prev"), &IniEntries::Prev)
|
|
|
|
.Func(_SC("Advance"), &IniEntries::Advance)
|
|
|
|
.Func(_SC("Retreat"), &IniEntries::Retreat)
|
|
|
|
.Func(_SC("Sort"), &IniEntries::Sort)
|
|
|
|
.Func(_SC("SortByKeyOrder"), &IniEntries::SortByKeyOrder)
|
|
|
|
.Func(_SC("SortByLoadOrder"), &IniEntries::SortByLoadOrder)
|
2016-05-24 17:37:34 +02:00
|
|
|
);
|
|
|
|
|
2020-03-22 00:33:11 +01:00
|
|
|
inins.Bind(_SC("IniDocument"),
|
|
|
|
Class< IniDocument, NoCopy< IniDocument > >(vm, DocumentTypename::Str)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Constructors
|
|
|
|
.Ctor()
|
|
|
|
.Ctor< bool >()
|
|
|
|
.Ctor< bool, bool >()
|
|
|
|
.Ctor< bool, bool, bool >()
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-11-15 20:42:00 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &DocumentTypename::Fn)
|
2020-03-22 00:33:11 +01:00
|
|
|
.Func(_SC("_tostring"), &IniDocument::ToString)
|
|
|
|
.Func(_SC("cmp"), &IniDocument::Cmp)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Properties
|
2020-03-22 00:33:11 +01:00
|
|
|
.Prop(_SC("Valid"), &IniDocument::IsValid)
|
|
|
|
.Prop(_SC("Empty"), &IniDocument::IsEmpty)
|
|
|
|
.Prop(_SC("References"), &IniDocument::GetRefCount)
|
|
|
|
.Prop(_SC("Unicode"), &IniDocument::GetUnicode, &IniDocument::SetUnicode)
|
|
|
|
.Prop(_SC("MultiKey"), &IniDocument::GetMultiKey, &IniDocument::SetMultiKey)
|
|
|
|
.Prop(_SC("MultiLine"), &IniDocument::GetMultiLine, &IniDocument::SetMultiLine)
|
|
|
|
.Prop(_SC("Spaces"), &IniDocument::GetSpaces, &IniDocument::SetSpaces)
|
2016-05-24 17:37:34 +02:00
|
|
|
// Member Methods
|
2020-03-22 00:33:11 +01:00
|
|
|
.Func(_SC("Reset"), &IniDocument::Reset)
|
|
|
|
.Func(_SC("LoadFile"), &IniDocument::LoadFile)
|
2021-01-30 07:51:39 +01:00
|
|
|
.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)
|
2020-03-22 00:33:11 +01:00
|
|
|
.Func(_SC("SaveData"), &IniDocument::SaveData)
|
|
|
|
.Func(_SC("GetSections"), &IniDocument::GetAllSections)
|
|
|
|
.Func(_SC("GetKeys"), &IniDocument::GetAllKeys)
|
|
|
|
.Func(_SC("GetValues"), &IniDocument::GetAllValues)
|
|
|
|
.Func(_SC("GetSectionSize"), &IniDocument::GetSectionSize)
|
|
|
|
.Func(_SC("HasMultipleKeys"), &IniDocument::HasMultipleKeys)
|
|
|
|
.Func(_SC("GetValue"), &IniDocument::GetValue)
|
|
|
|
.Func(_SC("GetInteger"), &IniDocument::GetInteger)
|
|
|
|
.Func(_SC("GetFloat"), &IniDocument::GetFloat)
|
|
|
|
.Func(_SC("GetBoolean"), &IniDocument::GetBoolean)
|
2021-01-30 07:51:39 +01:00
|
|
|
.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)
|
2016-05-24 17:37:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
RootTable(vm).Bind(_SC("SqIni"), inins);
|
|
|
|
|
|
|
|
ConstTable(vm).Enum(_SC("SqIniError"), Enumeration(vm)
|
2021-01-30 07:51:39 +01:00
|
|
|
.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))
|
2016-05-24 17:37:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|