2016-02-21 14:55:50 +01:00
|
|
|
#ifndef _LIBRARY_INI_HPP_
|
|
|
|
#define _LIBRARY_INI_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Base/Shared.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <SimpleIni.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
class IniEntries;
|
|
|
|
class IniDocument;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
* Manages a reference counted ini document instance.
|
2016-02-21 14:55:50 +01:00
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
class IniDocumentRef
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
friend class IniDocument;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
typedef CSimpleIniA Document;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef unsigned int Counter;
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
Document* m_Ptr; /* The document reader, writer and manager instance. */
|
2016-02-21 14:55:50 +01:00
|
|
|
Counter* m_Ref; /* Reference count to the managed instance. */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
* Grab a strong reference to a document instance.
|
2016-02-21 14:55:50 +01:00
|
|
|
*/
|
|
|
|
void Grab()
|
|
|
|
{
|
|
|
|
if (m_Ptr)
|
|
|
|
{
|
|
|
|
++(*m_Ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
* Drop a strong reference to a document instance.
|
2016-02-21 14:55:50 +01:00
|
|
|
*/
|
|
|
|
void Drop()
|
|
|
|
{
|
|
|
|
if (m_Ptr && --(*m_Ref) == 0)
|
|
|
|
{
|
|
|
|
delete m_Ptr;
|
|
|
|
delete m_Ref;
|
|
|
|
m_Ptr = NULL;
|
|
|
|
m_Ref = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef(bool utf8, bool multikey, bool multiline)
|
|
|
|
: m_Ptr(new Document(utf8, multikey, multiline)), m_Ref(new Counter(1))
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor (null).
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef()
|
2016-02-21 14:55:50 +01:00
|
|
|
: m_Ptr(NULL), m_Ref(NULL)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef(const IniDocumentRef & o)
|
2016-02-21 14:55:50 +01:00
|
|
|
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
|
|
|
|
|
|
|
{
|
|
|
|
Grab();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
~IniDocumentRef()
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
Drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef & operator = (const IniDocumentRef & o)
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
if (m_Ptr != o.m_Ptr)
|
|
|
|
{
|
|
|
|
Drop();
|
|
|
|
m_Ptr = o.m_Ptr;
|
|
|
|
m_Ref = o.m_Ref;
|
|
|
|
Grab();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
* Perform an equality comparison between two document instances.
|
2016-02-21 14:55:50 +01:00
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
bool operator == (const IniDocumentRef & o) const
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
return (m_Ptr == o.m_Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
* Perform an inequality comparison between two document instances.
|
2016-02-21 14:55:50 +01:00
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
bool operator != (const IniDocumentRef & o) const
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
return (m_Ptr != o.m_Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Implicit conversion to boolean for use in boolean operations.
|
|
|
|
*/
|
|
|
|
operator bool () const
|
|
|
|
{
|
|
|
|
return m_Ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Member operator for dereferencing the managed pointer.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
Document * operator -> () const
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
assert(m_Ptr != NULL);
|
|
|
|
return m_Ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Indirection operator for obtaining a reference of the managed pointer.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
Document & operator * () const
|
2016-02-21 14:55:50 +01:00
|
|
|
{
|
|
|
|
assert(m_Ptr != NULL);
|
|
|
|
return *m_Ptr;
|
|
|
|
}
|
2016-02-22 08:26:52 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the number of active references to the managed instance.
|
|
|
|
*/
|
|
|
|
Counter Count() const
|
|
|
|
{
|
|
|
|
return (m_Ptr && m_Ref) ? (*m_Ref) : 0;
|
|
|
|
}
|
|
|
|
|
2016-02-21 14:55:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Class that can access and iterate a series of entries in the ini document.
|
|
|
|
*/
|
|
|
|
class IniEntries
|
|
|
|
{
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
friend class IniDocument;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
typedef CSimpleIniA Document;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
typedef Document::TNamesDepend Container;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Container::iterator Iterator;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Default constructor.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
IniEntries(const IniDocumentRef & ini, Container & list)
|
2016-02-21 14:55:50 +01:00
|
|
|
: m_Doc(ini), m_List(), m_Elem()
|
|
|
|
{
|
|
|
|
m_List.swap(list);
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef m_Doc; /* The document that contains the elements. */
|
|
|
|
Container m_List; /* The list of elements to iterate. */
|
|
|
|
Iterator m_Elem; /* The currently processed element. */
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Default constructor. (null)
|
|
|
|
*/
|
|
|
|
IniEntries()
|
|
|
|
: m_Doc(), m_List(), m_Elem(m_List.end())
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
IniEntries(const IniEntries & o)
|
|
|
|
: m_Doc(o.m_Doc), m_List(o.m_List), m_Elem()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~IniEntries()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
|
|
|
IniEntries & operator = (const IniEntries & o)
|
|
|
|
{
|
|
|
|
m_Doc = o.m_Doc;
|
|
|
|
m_List = o.m_List;
|
|
|
|
Reset();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Used by the script engine to compare two instances of this type.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
Int32 Cmp(const IniEntries & o) const;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
|
|
|
CSStr ToString() const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Return whether the current element is valid and can be accessed.
|
|
|
|
*/
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return !(m_List.empty() || m_Elem == m_List.end());
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Return whether the entry list is empty.
|
|
|
|
*/
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return m_List.empty();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Return the number of active references to this document instance.
|
|
|
|
*/
|
|
|
|
Uint32 GetRefCount() const
|
|
|
|
{
|
|
|
|
return m_Doc.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Return the total entries in the list.
|
|
|
|
*/
|
|
|
|
Int32 GetSize() const
|
|
|
|
{
|
|
|
|
return (Int32)m_List.size();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Reset the internal iterator to the first element.
|
|
|
|
*/
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
if (m_List.empty())
|
|
|
|
m_Elem = m_List.end();
|
|
|
|
else
|
|
|
|
m_Elem = m_List.begin();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Go to the next element.
|
|
|
|
*/
|
|
|
|
void Next();
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Go to the previous element.
|
|
|
|
*/
|
|
|
|
void Prev();
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Advance a certain number of elements.
|
|
|
|
*/
|
|
|
|
void Advance(Int32 n);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retreat a certain number of elements.
|
|
|
|
*/
|
|
|
|
void Retreat(Int32 n);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Sort the entries using the default options.
|
|
|
|
*/
|
|
|
|
void Sort()
|
|
|
|
{
|
|
|
|
if (!m_List.empty())
|
2016-02-22 08:26:52 +01:00
|
|
|
m_List.sort(Document::Entry::KeyOrder());
|
2016-02-21 14:55:50 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Sort the entries by name of key only.
|
|
|
|
*/
|
|
|
|
void SortByKeyOrder()
|
|
|
|
{
|
|
|
|
if (!m_List.empty())
|
2016-02-22 08:26:52 +01:00
|
|
|
m_List.sort(Document::Entry::KeyOrder());
|
2016-02-21 14:55:50 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Sort the entries by their load order and then name of key.
|
|
|
|
*/
|
|
|
|
void SortByLoadOrder()
|
|
|
|
{
|
|
|
|
if (!m_List.empty())
|
2016-02-22 08:26:52 +01:00
|
|
|
m_List.sort(Document::Entry::LoadOrder());
|
2016-02-21 14:55:50 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Sort the entries by their load order but empty name always goes first.
|
|
|
|
*/
|
|
|
|
void SortByLoadOrderEmptyFirst()
|
|
|
|
{
|
|
|
|
if (!m_List.empty())
|
2016-02-22 08:26:52 +01:00
|
|
|
m_List.sort(Document::Entry::LoadOrderEmptyFirst());
|
2016-02-21 14:55:50 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve the string value of the current element item.
|
|
|
|
*/
|
|
|
|
CSStr GetItem() const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve the string value of the current element comment.
|
|
|
|
*/
|
|
|
|
CSStr GetComment() const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve the order of the current element.
|
|
|
|
*/
|
|
|
|
Int32 GetOrder() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Class that can read/write and alter the contents of ini files.
|
|
|
|
*/
|
|
|
|
class IniDocument
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
typedef CSimpleIniA Document;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
typedef Document::TNamesDepend Container;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
IniDocument(const IniDocument & o);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Copy assignment operator. (disabled)
|
|
|
|
*/
|
|
|
|
IniDocument & operator = (const IniDocument & o);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Validate the document reference.
|
|
|
|
*/
|
|
|
|
bool Validate() const
|
|
|
|
{
|
|
|
|
if (m_Doc)
|
|
|
|
return true;
|
|
|
|
SqThrow("Invalid ini document reference");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2016-02-22 08:26:52 +01:00
|
|
|
IniDocumentRef m_Doc; /* The main ini document instance. */
|
2016-02-21 14:55:50 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
IniDocument();
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Explicit constructor.
|
|
|
|
*/
|
|
|
|
IniDocument(bool utf8, bool multikey, bool multiline);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~IniDocument();
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Used by the script engine to compare two instances of this type.
|
|
|
|
*/
|
2016-02-22 08:26:52 +01:00
|
|
|
Int32 Cmp(const IniDocument & o) const;
|
2016-02-21 14:55:50 +01:00
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
|
|
|
CSStr ToString() const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether this instance references a valid ini document.
|
|
|
|
*/
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return m_Doc;
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether any data has been loaded into this document.
|
|
|
|
*/
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return m_Doc->IsEmpty();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Return the number of active references to this document instance.
|
|
|
|
*/
|
|
|
|
Uint32 GetRefCount() const
|
|
|
|
{
|
|
|
|
return m_Doc.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Deallocate all memory stored by this document.
|
|
|
|
*/
|
|
|
|
void Reset() const
|
|
|
|
{
|
|
|
|
m_Doc->Reset();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether the ini data is treated as unicode.
|
|
|
|
*/
|
|
|
|
bool GetUnicode() const
|
|
|
|
{
|
|
|
|
return m_Doc->IsUnicode();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Set whether the ini data should be treated as unicode.
|
|
|
|
*/
|
|
|
|
void SetUnicode(bool toggle)
|
|
|
|
{
|
|
|
|
m_Doc->SetUnicode(toggle);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether multiple identical keys be permitted in the file.
|
|
|
|
*/
|
|
|
|
bool GetMultiKey() const
|
|
|
|
{
|
|
|
|
return m_Doc->IsMultiKey();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Set whether multiple identical keys be permitted in the file.
|
|
|
|
*/
|
|
|
|
void SetMultiKey(bool toggle)
|
|
|
|
{
|
|
|
|
m_Doc->SetMultiKey(toggle);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether data values are permitted to span multiple lines in the file.
|
|
|
|
*/
|
|
|
|
bool GetMultiLine() const
|
|
|
|
{
|
|
|
|
return m_Doc->IsMultiLine();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Set whether data values are permitted to span multiple lines in the file.
|
|
|
|
*/
|
|
|
|
void SetMultiLine(bool toggle)
|
|
|
|
{
|
|
|
|
m_Doc->SetMultiLine(toggle);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether spaces are added around the equals sign when writing key/value pairs out.
|
|
|
|
*/
|
|
|
|
bool GetSpaces() const
|
|
|
|
{
|
|
|
|
return m_Doc->UsingSpaces();
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Set whether spaces are added around the equals sign when writing key/value pairs out.
|
|
|
|
*/
|
|
|
|
void SetSpaces(bool toggle)
|
|
|
|
{
|
|
|
|
m_Doc->SetSpaces(toggle);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Load an INI file from disk into memory.
|
|
|
|
*/
|
|
|
|
void LoadFile(CSStr filepath);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Load INI file data direct from a string.
|
|
|
|
*/
|
|
|
|
void LoadData(CSStr source)
|
|
|
|
{
|
|
|
|
LoadData(source, -1);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Load INI file data direct from a string.
|
|
|
|
*/
|
|
|
|
void LoadData(CSStr source, Int32 size);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Save an INI file from memory to disk.
|
|
|
|
*/
|
|
|
|
void SaveFile(CSStr filepath)
|
|
|
|
{
|
|
|
|
SaveFile(filepath, true);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Save an INI file from memory to disk.
|
|
|
|
*/
|
|
|
|
void SaveFile(CSStr filepath, bool signature);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Save the INI data to a string.
|
|
|
|
*/
|
|
|
|
Object SaveData(bool signature);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve all section names.
|
|
|
|
*/
|
|
|
|
IniEntries GetAllSections() const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve all unique key names in a section.
|
|
|
|
*/
|
|
|
|
IniEntries GetAllKeys(CSStr section) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve all values for a specific key.
|
|
|
|
*/
|
|
|
|
IniEntries GetAllValues(CSStr section, CSStr key) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Query the number of keys in a specific section.
|
|
|
|
*/
|
|
|
|
Int32 GetSectionSize(CSStr section) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* See whether a certain key has multiple instances.
|
|
|
|
*/
|
|
|
|
bool HasMultipleKeys(CSStr section, CSStr key) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve the value for a specific key.
|
|
|
|
*/
|
|
|
|
CCStr GetValue(CSStr section, CSStr key, CSStr def) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve a numeric value for a specific key.
|
|
|
|
*/
|
|
|
|
SQInteger GetInteger(CSStr section, CSStr key, SQInteger def) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve a numeric value for a specific key.
|
|
|
|
*/
|
|
|
|
SQFloat GetFloat(CSStr section, CSStr key, SQFloat def) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Retrieve a boolean value for a specific key.
|
|
|
|
*/
|
|
|
|
bool GetBoolean(CSStr section, CSStr key, bool def) const;
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a section or value.
|
|
|
|
*/
|
|
|
|
void SetValue(CSStr section, CSStr key, CSStr value)
|
|
|
|
{
|
|
|
|
SetValue(section, key, value, false, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a section or value.
|
|
|
|
*/
|
|
|
|
void SetValue(CSStr section, CSStr key, CSStr value, bool force)
|
|
|
|
{
|
|
|
|
SetValue(section, key, value, force, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a section or value.
|
|
|
|
*/
|
|
|
|
void SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a numeric value.
|
|
|
|
*/
|
|
|
|
void SetInteger(CSStr section, CSStr key, SQInteger value)
|
|
|
|
{
|
|
|
|
SetInteger(section, key, value, false, false, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a numeric value.
|
|
|
|
*/
|
|
|
|
void SetInteger(CSStr section, CSStr key, SQInteger value, bool hex)
|
|
|
|
{
|
|
|
|
SetInteger(section, key, value, hex, false, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a numeric value.
|
|
|
|
*/
|
|
|
|
void SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force)
|
|
|
|
{
|
|
|
|
SetInteger(section, key, value, hex, force, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a numeric value.
|
|
|
|
*/
|
|
|
|
void SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a double value.
|
|
|
|
*/
|
|
|
|
void SetFloat(CSStr section, CSStr key, SQFloat value)
|
|
|
|
{
|
|
|
|
SetFloat(section, key, value, false, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a double value.
|
|
|
|
*/
|
|
|
|
void SetFloat(CSStr section, CSStr key, SQFloat value, bool force)
|
|
|
|
{
|
|
|
|
SetFloat(section, key, value, force, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a double value.
|
|
|
|
*/
|
|
|
|
void SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a double value.
|
|
|
|
*/
|
|
|
|
void SetBoolean(CSStr section, CSStr key, bool value)
|
|
|
|
{
|
|
|
|
SetBoolean(section, key, value, false, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a double value.
|
|
|
|
*/
|
|
|
|
void SetBoolean(CSStr section, CSStr key, bool value, bool force)
|
|
|
|
{
|
|
|
|
SetBoolean(section, key, value, force, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Add or update a boolean value.
|
|
|
|
*/
|
|
|
|
void SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment);
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Delete an entire section, or a key from a section.
|
|
|
|
*/
|
|
|
|
bool DeleteValue(CSStr section)
|
|
|
|
{
|
|
|
|
return DeleteValue(section, NULL, NULL, false);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Delete an entire section, or a key from a section.
|
|
|
|
*/
|
|
|
|
bool DeleteValue(CSStr section, CSStr key)
|
|
|
|
{
|
|
|
|
return DeleteValue(section, key, NULL, false);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Delete an entire section, or a key from a section.
|
|
|
|
*/
|
|
|
|
bool DeleteValue(CSStr section, CSStr key, CSStr value)
|
|
|
|
{
|
|
|
|
return DeleteValue(section, key, value, false);
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:26:52 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-21 14:55:50 +01:00
|
|
|
* Delete an entire section, or a key from a section.
|
|
|
|
*/
|
|
|
|
bool DeleteValue(CSStr section, CSStr key, CSStr value, bool empty);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _LIBRARY_INI_HPP_
|