2016-11-14 13:06:30 +01:00
|
|
|
#ifndef _SQMMDB_ENTRYDATA_HPP_
|
|
|
|
#define _SQMMDB_ENTRYDATA_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Handle/Database.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Class that can hold and be used to inspect entry data values.
|
|
|
|
*/
|
|
|
|
class EntryData
|
|
|
|
{
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
2016-11-14 13:06:30 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MMDB_entry_data_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-11-14 13:06:30 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void Validate(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
void Validate() const;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
2016-11-15 05:34:10 +01:00
|
|
|
ConstRef GetValid(CCStr file, Int32 line) const;
|
2016-11-14 13:06:30 +01:00
|
|
|
#else
|
2016-11-15 05:34:10 +01:00
|
|
|
ConstRef GetValid() const;
|
2016-11-14 13:06:30 +01:00
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
DbRef m_Handle; // The database from which this result comes from.
|
|
|
|
Type m_Entry; // The managed entry-data structure.
|
|
|
|
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor. (null)
|
|
|
|
*/
|
|
|
|
EntryData();
|
|
|
|
|
2016-11-14 13:06:30 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Construct and take ownership of a certain entry data.
|
|
|
|
*/
|
|
|
|
EntryData(const DbRef & db, Reference entry)
|
|
|
|
: m_Handle(db), m_Entry(entry)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
EntryData(const EntryData &) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
EntryData(EntryData &&) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
|
|
|
EntryData & operator = (const EntryData &) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
EntryData & operator = (EntryData &&) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
2016-11-14 13:06:30 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
CSStr ToString() const
|
2016-11-14 13:06:30 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return AsTypeStr(m_Entry.type);
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Used by the script engine to retrieve the name from instances of this type.
|
2016-11-14 13:06:30 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
static SQInteger Typename(HSQUIRRELVM vm);
|
2016-11-14 13:06:30 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* See whether this instance references a valid database and entry structure.
|
2016-11-14 13:06:30 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
bool IsValid() const
|
2016-11-14 13:06:30 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return m_Handle && m_Entry.has_data;
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Release the manages handles/pointers and become a null instance.
|
2016-11-14 13:06:30 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
void Release();
|
2016-11-14 13:06:30 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:44:01 +01:00
|
|
|
* Retrieve the database associated with the managed handle/pointer.
|
2016-11-14 13:06:30 +01:00
|
|
|
*/
|
2016-11-14 13:44:01 +01:00
|
|
|
Database GetDatabase() const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Return the number of active references to the managed database instance.
|
|
|
|
*/
|
|
|
|
Uint32 GetRefCount() const
|
2016-11-14 13:06:30 +01:00
|
|
|
{
|
2016-11-14 13:44:01 +01:00
|
|
|
return m_Handle.Count();
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used to retrieve the type of the current element as a string.
|
|
|
|
*/
|
|
|
|
CSStr TypeName() const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
|
|
|
SQMOD_VALIDATE(*this);
|
|
|
|
// Return the requested information
|
|
|
|
return AsTypeStr(m_Entry.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether a valid element is currently processed.
|
|
|
|
*/
|
|
|
|
bool HasData() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return ConvTo< bool >::From(SQMOD_GET_VALID(*this).has_data);
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the type identifier of the current element.
|
|
|
|
*/
|
|
|
|
SQInteger GetType() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID(*this).type);
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the offset of the current element.
|
|
|
|
*/
|
|
|
|
SQInteger GetOffset() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID(*this).offset);
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the offset of the next element.
|
|
|
|
*/
|
|
|
|
SQInteger DataSize() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return ConvTo< SQInteger >::From(SQMOD_GET_VALID(*this).data_size);
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a boolean.
|
|
|
|
*/
|
|
|
|
bool GetBool() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsBool(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a native integer.
|
|
|
|
*/
|
|
|
|
SQInteger GetInteger() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsInteger(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a floating point.
|
|
|
|
*/
|
|
|
|
SQFloat GetFloat() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsFloat(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a long integer.
|
|
|
|
*/
|
|
|
|
Object GetLong() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsLong(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a string.
|
|
|
|
*/
|
|
|
|
Object GetString() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsString(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value from the current element as a stream of bytes.
|
|
|
|
*/
|
|
|
|
Object GetBytes() const
|
|
|
|
{
|
2016-11-15 05:34:10 +01:00
|
|
|
return GetEntryAsBytes(SQMOD_GET_VALID(*this));
|
2016-11-14 13:06:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMMDB_ENTRYDATA_HPP_
|