2016-03-10 04:57:13 +01:00
|
|
|
#ifndef _SQMMDB_LOOKUPRESULT_HPP_
|
|
|
|
#define _SQMMDB_LOOKUPRESULT_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
#include "Handle/Database.hpp"
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Class that can hold and be used to work with lookup results.
|
|
|
|
*/
|
|
|
|
class LookupResult
|
|
|
|
{
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MMDB_lookup_result_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
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed database handle and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
const DbRef & GetValid(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
const DbRef & GetValid() 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 from which this result comes from.
|
|
|
|
Type m_Result; // The managed result structure.
|
2016-03-10 04:57:13 +01:00
|
|
|
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor. (null)
|
|
|
|
*/
|
|
|
|
LookupResult();
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Construct and take ownership of a certain result.
|
|
|
|
*/
|
|
|
|
LookupResult(const DbRef & db, Reference result)
|
2016-11-14 13:06:30 +01:00
|
|
|
: m_Handle(db), m_Result(result)
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
LookupResult(const LookupResult &) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
LookupResult(LookupResult &&) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
|
|
|
LookupResult & operator = (const LookupResult &) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
LookupResult & operator = (LookupResult &&) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
|
|
|
CSStr ToString() const
|
|
|
|
{
|
|
|
|
return FmtStr("%u", m_Result.entry.offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* 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 result structure.
|
|
|
|
*/
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
2016-11-14 13:06:30 +01:00
|
|
|
return m_Handle && m_Result.found_entry;
|
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.
|
|
|
|
*/
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the database associated with the managed handle/pointer.
|
|
|
|
*/
|
|
|
|
Database GetDatabase() const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Return the number of active references to the managed database instance.
|
|
|
|
*/
|
|
|
|
Uint32 GetRefCount() const
|
|
|
|
{
|
|
|
|
return m_Handle.Count();
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the result contains a valid entry in the associated database.
|
|
|
|
*/
|
|
|
|
bool FoundEntry() const
|
|
|
|
{
|
|
|
|
// Validate the database handle
|
2016-11-14 13:06:30 +01:00
|
|
|
SQMOD_VALIDATE(*this);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
|
|
|
return m_Result.found_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the net-mask from the result structure.
|
|
|
|
*/
|
|
|
|
SQInteger GetNetMask() const
|
|
|
|
{
|
|
|
|
// Validate the database handle
|
2016-11-14 13:06:30 +01:00
|
|
|
SQMOD_VALIDATE(*this);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
|
|
|
return static_cast< SQInteger >(m_Result.netmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Retrieve the entire entry data list.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
Object GetEntryDataList();
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Lookup data in the associated result using the specified path.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
static SQInteger GetValue(HSQUIRRELVM vm);
|
2016-03-10 04:57:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMMDB_LOOKUPRESULT_HPP_
|