mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-16 07:07:13 +02:00
Initial implementation of the MaxmindDB module.
This commit is contained in:
32
modules/mmdb/Handle/Database.cpp
Normal file
32
modules/mmdb/Handle/Database.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Handle/Database.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DbHnd::DbHnd(CSStr filepath, Uint32 flags)
|
||||
: mDb()
|
||||
{
|
||||
// Validate the specified file path
|
||||
if (!filepath || *filepath == '\0')
|
||||
{
|
||||
STHROWF("Invalid database file path");
|
||||
}
|
||||
// Let's attempt to open the specified database
|
||||
const Int32 status = MMDB_open(filepath, flags, &mDb);
|
||||
// Validate the result of the operation
|
||||
if (status != MMDB_SUCCESS)
|
||||
{
|
||||
STHROWF("Unable to open the specified database [%s]", MMDB_strerror(status));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DbHnd::~DbHnd()
|
||||
{
|
||||
// We don't need the database handle anymore
|
||||
MMDB_close(&mDb);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
69
modules/mmdb/Handle/Database.hpp
Normal file
69
modules/mmdb/Handle/Database.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef _SQMMDB_HANDLE_DATABASE_HPP_
|
||||
#define _SQMMDB_HANDLE_DATABASE_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a reference counted INI document instance.
|
||||
*/
|
||||
class DbHnd
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Database;
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef MMDB_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.
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
MMDB_s mDb; // The managed database handle.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DbHnd(CSStr filepath, Uint32 flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
DbHnd(const DbHnd & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
DbHnd(DbHnd && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DbHnd();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
DbHnd & operator = (const DbHnd & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
DbHnd & operator = (DbHnd && o) = delete;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _SQMMDB_HANDLE_DATABASE_HPP_
|
Reference in New Issue
Block a user