2016-11-14 13:06:30 +01:00
|
|
|
#ifndef _SQMMDB_ENTRYDATALIST_HPP_
|
|
|
|
#define _SQMMDB_ENTRYDATALIST_HPP_
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
#include "Handle/Database.hpp"
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Class that can hold and be used inspect database meta-data.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
|
|
|
class EntryDataList
|
|
|
|
{
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MMDB_entry_data_list_s Type; // The managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type* Pointer; // Pointer to the managed type.
|
|
|
|
typedef const Type* ConstPtr; // Constant pointer to the managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type& Reference; // Reference to the managed type.
|
|
|
|
typedef const Type& ConstRef; // Constant reference to the managed type.
|
|
|
|
|
2016-11-14 14:46:48 +01:00
|
|
|
protected:
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void Validate(CCStr file, Int32 line) const;
|
|
|
|
#else
|
2016-03-10 04:57:13 +01:00
|
|
|
void Validate() const;
|
2016-11-14 13:06:30 +01:00
|
|
|
#endif // _DEBUG
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
Pointer GetValid(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
Pointer GetValid() const;
|
|
|
|
#endif // _DEBUG
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
Pointer GetValidElem(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
Pointer GetValidElem() const;
|
|
|
|
#endif // _DEBUG
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
DbRef m_Handle; // The database associated with this meta-data.
|
|
|
|
Pointer m_List; // The managed entry data list.
|
|
|
|
Pointer m_Elem; // The currently processed element from the list.
|
2016-03-10 04:57:13 +01:00
|
|
|
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Construct and with a specific entry list.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
|
|
|
EntryDataList(const DbRef & db, Pointer list)
|
2016-11-14 13:06:30 +01:00
|
|
|
: m_Handle(db), m_List(list), m_Elem(list)
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Default constructor. (null)
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
EntryDataList()
|
|
|
|
: m_Handle(), m_List(nullptr), m_Elem(nullptr)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
EntryDataList(const EntryDataList &) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
EntryDataList(EntryDataList && o)
|
2016-11-14 13:06:30 +01:00
|
|
|
: m_Handle(o.m_Handle)
|
2016-03-10 04:57:13 +01:00
|
|
|
, m_List(o.m_List)
|
|
|
|
, m_Elem(o.m_Elem)
|
|
|
|
{
|
|
|
|
o.m_List = nullptr;
|
|
|
|
o.m_Elem = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
~EntryDataList()
|
|
|
|
{
|
|
|
|
// Do we have to free any list?
|
|
|
|
if (m_List)
|
|
|
|
{
|
|
|
|
MMDB_free_entry_data_list(m_List);
|
|
|
|
}
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator. (disabled)
|
|
|
|
*/
|
|
|
|
EntryDataList & operator = (const EntryDataList &) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
EntryDataList & operator = (EntryDataList && o)
|
|
|
|
{
|
|
|
|
if (m_List != o.m_List)
|
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
m_Handle = o.m_Handle;
|
2016-03-10 04:57:13 +01:00
|
|
|
m_List = o.m_List;
|
|
|
|
m_Elem = o.m_Elem;
|
|
|
|
o.m_List = nullptr;
|
|
|
|
o.m_Elem = nullptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
CSStr ToString() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return m_Elem ? AsTypeStr(m_Elem->entry_data.type) : _SC("invalid");
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Used by the script engine to retrieve the name from instances of this type.
|
|
|
|
*/
|
|
|
|
static SQInteger Typename(HSQUIRRELVM vm);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether this instance references a valid database and element pointer.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
bool IsValid() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return m_Handle && m_Elem;
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Release the manages handles/pointers and become a null instance.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
void Release()
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
m_Handle.Reset();
|
|
|
|
// Do we have to free any list?
|
|
|
|
if (m_List)
|
|
|
|
{
|
|
|
|
MMDB_free_entry_data_list(m_List);
|
|
|
|
}
|
|
|
|
// Finally, release those as well
|
|
|
|
m_List = nullptr;
|
|
|
|
m_Elem = nullptr;
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Retrieve the database associated with the managed handle/pointer.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
Database GetDatabase() const;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Return the number of active references to the managed database instance.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
Uint32 GetRefCount() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return m_Handle.Count();
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether a valid element is currently processed.
|
|
|
|
*/
|
|
|
|
bool HaveElement() const
|
|
|
|
{
|
|
|
|
return m_Elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used to retrieve the type of the current element as a string.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
CSStr TypeName() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return AsTypeStr(SQMOD_GET_VALID_ELEM(*this)->entry_data.type);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Return the total entries in the list.
|
|
|
|
*/
|
|
|
|
Uint32 GetCount() const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Go to the next element.
|
|
|
|
*/
|
|
|
|
bool Next();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Advance a certain number of elements.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
bool Advance(SQInteger n);
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Go back to the first element in the list.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_Elem = SQMOD_GET_VALID_ELEM(*this);
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether a valid element is currently processed.
|
|
|
|
*/
|
|
|
|
bool HasData() const
|
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return ConvTo< bool >::From(SQMOD_GET_VALID_ELEM(*this)->entry_data.has_data);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the type identifier of the current element.
|
|
|
|
*/
|
|
|
|
SQInteger GetType() const
|
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID_ELEM(*this)->entry_data.type);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the offset of the current element.
|
|
|
|
*/
|
|
|
|
SQInteger GetOffset() const
|
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID_ELEM(*this)->entry_data.offset);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the offset of the next element.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
SQInteger DataSize() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID_ELEM(*this)->entry_data.data_size);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Retrieve the value from the current element as a boolean.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
bool GetBool() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return GetEntryAsBool(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a native integer.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
SQInteger GetInteger() const
|
|
|
|
{
|
|
|
|
return GetEntryAsInteger(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a floating point.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
SQFloat GetFloat() const
|
|
|
|
{
|
|
|
|
return GetEntryAsFloat(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a long integer.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
Object GetLong() const
|
|
|
|
{
|
|
|
|
return GetEntryAsLong(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a string.
|
|
|
|
*/
|
|
|
|
Object GetString() const
|
|
|
|
{
|
|
|
|
return GetEntryAsString(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Retrieve the value from the current element as a stream of bytes.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
Object GetBytes() const
|
|
|
|
{
|
|
|
|
return GetEntryAsBytes(SQMOD_GET_VALID_ELEM(*this)->entry_data);
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Dumpt the contents of the list to the specified list.
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
void DumpTo(CSStr filepath) const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
DumpTo(filepath, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Dumpt the contents of the list to the specified list.
|
|
|
|
*/
|
|
|
|
void DumpTo(CSStr filepath, Int32 indent) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
2016-11-14 13:06:30 +01:00
|
|
|
#endif // _SQMMDB_ENTRYDATALIST_HPP_
|