1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-03 17:27:47 +00:00

Removing boost from common

This commit is contained in:
mordred 2018-10-24 12:53:26 +02:00
parent b23e723ff6
commit b4d0e87909
18 changed files with 85 additions and 89 deletions

View file

@ -45,6 +45,7 @@ add_subdirectory( "src/libraries/sapphire/mysqlConnector" )
add_subdirectory( "src/common" )
add_subdirectory( "src/servers" )
add_subdirectory( "src/dbm" )
add_subdirectory( "src/tools/exd_common_gen" )
add_subdirectory( "src/tools/exd_struct_gen" )

View file

@ -1,6 +1,6 @@
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
else()
add_definitions(-D_WIN32_WINNT=0x601)

View file

@ -4,7 +4,6 @@
#include "Logging/Logger.h"
#include "PreparedStatement.h"
#include <boost/make_shared.hpp>
#include "Framework.h"
extern Core::Framework g_fw;
@ -20,7 +19,7 @@ Core::Db::DbConnection::DbConnection( ConnectionInfo& connInfo ) :
}
Core::Db::DbConnection::DbConnection( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* queue,
Core::Db::DbConnection::DbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* queue,
Core::Db::ConnectionInfo& connInfo ) :
m_reconnecting( false ),
m_prepareError( false ),
@ -29,7 +28,7 @@ Core::Db::DbConnection::DbConnection( Core::LockedWaitQueue< boost::shared_ptr<
m_connectionInfo( connInfo ),
m_connectionFlags( CONNECTION_ASYNC )
{
m_worker = boost::make_shared< DbWorker >( m_queue, this );
m_worker = std::make_shared< DbWorker >( m_queue, this );
}
Core::Db::DbConnection::~DbConnection()
@ -53,7 +52,7 @@ void Core::Db::DbConnection::close()
uint32_t Core::Db::DbConnection::open()
{
boost::shared_ptr< Mysql::MySqlBase > base( new Mysql::MySqlBase() );
std::shared_ptr< Mysql::MySqlBase > base( new Mysql::MySqlBase() );
Mysql::optionMap options;
options[ MYSQL_OPT_RECONNECT ] = "1";
options[ MYSQL_SET_CHARSET_NAME ] = "utf8";
@ -124,7 +123,7 @@ bool Core::Db::DbConnection::execute( const std::string& sql )
}
}
boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( const std::string& sql )
std::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( const std::string& sql )
{
try
{
@ -140,10 +139,10 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( const std::
}
boost::shared_ptr< Mysql::ResultSet >
Core::Db::DbConnection::query( boost::shared_ptr< Core::Db::PreparedStatement > stmt )
std::shared_ptr< Mysql::ResultSet >
Core::Db::DbConnection::query( std::shared_ptr< Core::Db::PreparedStatement > stmt )
{
boost::shared_ptr< Mysql::ResultSet > res( nullptr );
std::shared_ptr< Mysql::ResultSet > res( nullptr );
if( !stmt )
return nullptr;
@ -177,7 +176,7 @@ Core::Db::DbConnection::query( boost::shared_ptr< Core::Db::PreparedStatement >
}
bool Core::Db::DbConnection::execute( boost::shared_ptr< Core::Db::PreparedStatement > stmt )
bool Core::Db::DbConnection::execute( std::shared_ptr< Core::Db::PreparedStatement > stmt )
{
if( !stmt )
return false;
@ -202,7 +201,7 @@ bool Core::Db::DbConnection::execute( boost::shared_ptr< Core::Db::PreparedState
}
}
boost::shared_ptr< Mysql::PreparedStatement > Core::Db::DbConnection::getPreparedStatement( uint32_t index )
std::shared_ptr< Mysql::PreparedStatement > Core::Db::DbConnection::getPreparedStatement( uint32_t index )
{
assert( index < m_stmts.size() );
auto ret = m_stmts[ index ];
@ -225,7 +224,7 @@ void Core::Db::DbConnection::prepareStatement( uint32_t index, const std::string
return;
}
boost::shared_ptr< Mysql::PreparedStatement > pStmt( nullptr );
std::shared_ptr< Mysql::PreparedStatement > pStmt( nullptr );
try
{
@ -237,7 +236,7 @@ void Core::Db::DbConnection::prepareStatement( uint32_t index, const std::string
m_prepareError = true;
}
m_stmts[ index ] = boost::shared_ptr< Mysql::PreparedStatement >( pStmt );
m_stmts[ index ] = std::shared_ptr< Mysql::PreparedStatement >( pStmt );
}

View file

@ -7,8 +7,6 @@
#include <string>
#include <vector>
#include "Util/LockedWaitQueue.h"
#include <boost/scoped_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
namespace Mysql {
class Connection;
@ -30,7 +28,7 @@ class Operation;
class DbWorker;
using PreparedStmtScopedPtr = boost::scoped_ptr< PreparedStatement >;
using PreparedStmtScopedPtr = std::unique_ptr< PreparedStatement >;
enum ConnectionFlags
{
@ -53,14 +51,14 @@ struct ConnectionInfo
using PreparedStatementMap = std::map< uint32_t, std::pair< std::string, ConnectionFlags > >;
class DbConnection :
public boost::enable_shared_from_this< DbConnection >
public std::enable_shared_from_this< DbConnection >
{
public:
// Constructor for synchronous connections.
DbConnection( ConnectionInfo& connInfo );
// Constructor for asynchronous connections.
DbConnection( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* queue, ConnectionInfo& connInfo );
DbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* queue, ConnectionInfo& connInfo );
virtual ~DbConnection();
@ -72,11 +70,11 @@ public:
bool execute( const std::string& sql );
bool execute( boost::shared_ptr< PreparedStatement > stmt );
bool execute( std::shared_ptr< PreparedStatement > stmt );
boost::shared_ptr< Mysql::ResultSet > query( const std::string& sql );
std::shared_ptr< Mysql::ResultSet > query( const std::string& sql );
boost::shared_ptr< Mysql::ResultSet > query( boost::shared_ptr< PreparedStatement > stmt );
std::shared_ptr< Mysql::ResultSet > query( std::shared_ptr< PreparedStatement > stmt );
void beginTransaction();
@ -92,27 +90,27 @@ public:
void unlock();
boost::shared_ptr< Mysql::Connection > getConnection()
std::shared_ptr< Mysql::Connection > getConnection()
{
return m_pConnection;
}
boost::shared_ptr< Mysql::PreparedStatement > getPreparedStatement( uint32_t index );
std::shared_ptr< Mysql::PreparedStatement > getPreparedStatement( uint32_t index );
void prepareStatement( uint32_t index, const std::string& sql, ConnectionFlags flags );
virtual void doPrepareStatements() = 0;
protected:
std::vector< boost::shared_ptr< Mysql::PreparedStatement > > m_stmts;
std::vector< std::shared_ptr< Mysql::PreparedStatement > > m_stmts;
PreparedStatementMap m_queries;
bool m_reconnecting;
bool m_prepareError;
private:
LockedWaitQueue< boost::shared_ptr< Operation > >* m_queue;
boost::shared_ptr< DbWorker > m_worker;
boost::shared_ptr< Mysql::Connection > m_pConnection;
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
std::shared_ptr< DbWorker > m_worker;
std::shared_ptr< Mysql::Connection > m_pConnection;
ConnectionInfo& m_connectionInfo;
ConnectionFlags m_connectionFlags;
std::mutex m_mutex;

View file

@ -2,7 +2,7 @@
#include "Operation.h"
#include "Util/LockedWaitQueue.h"
Core::Db::DbWorker::DbWorker( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* newQueue, DbConnection* pConn )
Core::Db::DbWorker::DbWorker( Core::LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* pConn )
{
m_pConn = pConn;
m_queue = newQueue;
@ -24,7 +24,7 @@ void Core::Db::DbWorker::workerThread()
while( true )
{
boost::shared_ptr< Operation > operation = nullptr;
std::shared_ptr< Operation > operation = nullptr;
m_queue->waitAndPop( operation );

View file

@ -4,7 +4,7 @@
#include <atomic>
#include <thread>
#include "Util/LockedWaitQueue.h"
#include <boost/shared_ptr.hpp>
#include <memory>
namespace Core {
namespace Db {
@ -15,12 +15,12 @@ class Operation;
class DbWorker
{
public:
DbWorker( LockedWaitQueue< boost::shared_ptr< Operation > >* newQueue, DbConnection* connection );
DbWorker( LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* connection );
~DbWorker();
private:
LockedWaitQueue< boost::shared_ptr< Operation > >* m_queue;
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
DbConnection* m_pConn;
void workerThread();

View file

@ -5,7 +5,6 @@
#include "StatementTask.h"
#include "Operation.h"
#include "ZoneDbConnection.h"
#include <boost/make_shared.hpp>
#include "Framework.h"
#include "Logging/Logger.h"
@ -25,7 +24,7 @@ class PingOperation :
template< class T >
Core::Db::DbWorkerPool< T >::DbWorkerPool()
:
m_queue( new Core::LockedWaitQueue< boost::shared_ptr< Operation > >() ),
m_queue( new Core::LockedWaitQueue< std::shared_ptr< Operation > >() ),
m_asyncThreads( 0 ),
m_synchThreads( 0 )
{
@ -103,34 +102,34 @@ bool Core::Db::DbWorkerPool< T >::prepareStatements()
}
template< class T >
boost::shared_ptr< Mysql::ResultSet >
Core::Db::DbWorkerPool< T >::query( const std::string& sql, boost::shared_ptr< T > connection )
std::shared_ptr< Mysql::ResultSet >
Core::Db::DbWorkerPool< T >::query( const std::string& sql, std::shared_ptr< T > connection )
{
if( !connection )
connection = getFreeConnection();
boost::shared_ptr< Mysql::ResultSet > result = connection->query( sql );
std::shared_ptr< Mysql::ResultSet > result = connection->query( sql );
connection->unlock();
return result;
}
template< class T >
boost::shared_ptr< Mysql::PreparedResultSet >
Core::Db::DbWorkerPool< T >::query( boost::shared_ptr< PreparedStatement > stmt )
std::shared_ptr< Mysql::PreparedResultSet >
Core::Db::DbWorkerPool< T >::query( std::shared_ptr< PreparedStatement > stmt )
{
auto connection = getFreeConnection();
auto ret = boost::static_pointer_cast< Mysql::PreparedResultSet >( connection->query( stmt ) );
auto ret = std::static_pointer_cast< Mysql::PreparedResultSet >( connection->query( stmt ) );
connection->unlock();
return ret;
}
template< class T >
boost::shared_ptr< Core::Db::PreparedStatement >
std::shared_ptr< Core::Db::PreparedStatement >
Core::Db::DbWorkerPool< T >::getPreparedStatement( PreparedStatementIndex index )
{
return boost::make_shared< PreparedStatement >( index );
return std::make_shared< PreparedStatement >( index );
}
template< class T >
@ -159,7 +158,7 @@ void Core::Db::DbWorkerPool< T >::keepAlive()
const auto count = m_connections[ IDX_ASYNC ].size();
for( uint8_t i = 0; i < count; ++i )
enqueue( boost::make_shared< PingOperation >() );
enqueue( std::make_shared< PingOperation >() );
}
template< class T >
@ -173,11 +172,11 @@ uint32_t Core::Db::DbWorkerPool< T >::openConnections( InternalIndex type, uint8
switch( type )
{
case IDX_ASYNC:
return boost::make_shared< T >( m_queue.get(), m_connectionInfo );
return std::make_shared< T >( m_queue.get(), m_connectionInfo );
case IDX_SYNCH:
return boost::make_shared< T >( m_connectionInfo );
return std::make_shared< T >( m_connectionInfo );
default:
return boost::shared_ptr< T >( nullptr );
return std::shared_ptr< T >( nullptr );
}
}();
@ -204,17 +203,17 @@ unsigned long Core::Db::DbWorkerPool< T >::escapeString( char* to, const char* f
}
template< class T >
void Core::Db::DbWorkerPool< T >::enqueue( boost::shared_ptr< Operation > op )
void Core::Db::DbWorkerPool< T >::enqueue( std::shared_ptr< Operation > op )
{
m_queue->push( op );
}
template< class T >
boost::shared_ptr< T > Core::Db::DbWorkerPool< T >::getFreeConnection()
std::shared_ptr< T > Core::Db::DbWorkerPool< T >::getFreeConnection()
{
uint8_t i = 0;
const auto numCons = m_connections[ IDX_SYNCH ].size();
boost::shared_ptr< T > connection = nullptr;
std::shared_ptr< T > connection = nullptr;
while( true )
{
@ -236,14 +235,14 @@ const std::string& Core::Db::DbWorkerPool< T >::getDatabaseName() const
template< class T >
void Core::Db::DbWorkerPool< T >::execute( const std::string& sql )
{
auto task = boost::make_shared< StatementTask >( sql );
auto task = std::make_shared< StatementTask >( sql );
enqueue( task );
}
template< class T >
void Core::Db::DbWorkerPool< T >::execute( boost::shared_ptr< PreparedStatement > stmt )
void Core::Db::DbWorkerPool< T >::execute( std::shared_ptr< PreparedStatement > stmt )
{
auto task = boost::make_shared< PreparedStatementTask >( stmt );
auto task = std::make_shared< PreparedStatementTask >( stmt );
enqueue( task );
}
@ -256,7 +255,7 @@ void Core::Db::DbWorkerPool< T >::directExecute( const std::string& sql )
}
template< class T >
void Core::Db::DbWorkerPool< T >::directExecute( boost::shared_ptr< PreparedStatement > stmt )
void Core::Db::DbWorkerPool< T >::directExecute( std::shared_ptr< PreparedStatement > stmt )
{
auto connection = getFreeConnection();
connection->execute( stmt );

View file

@ -52,21 +52,21 @@ public:
// Async execution
void execute( const std::string& sql );
void execute( boost::shared_ptr< PreparedStatement > stmt );
void execute( std::shared_ptr< PreparedStatement > stmt );
// Sync execution
void directExecute( const std::string& sql );
void directExecute( boost::shared_ptr< PreparedStatement > stmt );
void directExecute( std::shared_ptr< PreparedStatement > stmt );
boost::shared_ptr< Mysql::ResultSet >
query( const std::string& sql, boost::shared_ptr< T > connection = nullptr );
std::shared_ptr< Mysql::ResultSet >
query( const std::string& sql, std::shared_ptr< T > connection = nullptr );
boost::shared_ptr< Mysql::PreparedResultSet > query( boost::shared_ptr< PreparedStatement > stmt );
std::shared_ptr< Mysql::PreparedResultSet > query( std::shared_ptr< PreparedStatement > stmt );
using PreparedStatementIndex = typename T::Statements;
boost::shared_ptr< PreparedStatement > getPreparedStatement( PreparedStatementIndex index );
std::shared_ptr< PreparedStatement > getPreparedStatement( PreparedStatementIndex index );
void escapeString( std::string& str );
@ -77,14 +77,14 @@ private:
unsigned long escapeString( char* to, const char* from, unsigned long length );
void enqueue( boost::shared_ptr< Operation > op );
void enqueue( std::shared_ptr< Operation > op );
boost::shared_ptr< T > getFreeConnection();
std::shared_ptr< T > getFreeConnection();
const std::string& getDatabaseName() const;
std::unique_ptr< Core::LockedWaitQueue< boost::shared_ptr< Operation > > > m_queue;
std::array< std::vector< boost::shared_ptr< T > >, IDX_SIZE > m_connections;
std::unique_ptr< Core::LockedWaitQueue< std::shared_ptr< Operation > > > m_queue;
std::array< std::vector< std::shared_ptr< T > >, IDX_SIZE > m_connections;
ConnectionInfo m_connectionInfo;
uint8_t m_asyncThreads;
uint8_t m_synchThreads;

View file

@ -5,6 +5,7 @@
#include <string.h>
#include <sstream>
#include <cassert>
Core::Db::PreparedStatement::PreparedStatement( uint32_t index ) :
m_stmt( nullptr ),
@ -150,7 +151,7 @@ uint32_t Core::Db::PreparedStatement::getIndex() const
return m_index;
}
void Core::Db::PreparedStatement::setMysqlPS( boost::shared_ptr< Mysql::PreparedStatement > pStmt )
void Core::Db::PreparedStatement::setMysqlPS( std::shared_ptr< Mysql::PreparedStatement > pStmt )
{
m_stmt = pStmt;
}

View file

@ -4,7 +4,7 @@
#include <stdint.h>
#include <vector>
#include <string>
#include <boost/shared_ptr.hpp>
#include <memory>
#include "Operation.h"
namespace Mysql {
@ -70,12 +70,12 @@ public:
uint32_t getIndex() const;
void setMysqlPS( boost::shared_ptr< Mysql::PreparedStatement > pStmt );
void setMysqlPS( std::shared_ptr< Mysql::PreparedStatement > pStmt );
void bindParameters();
protected:
boost::shared_ptr< Mysql::PreparedStatement > m_stmt;
std::shared_ptr< Mysql::PreparedStatement > m_stmt;
uint32_t m_index;
std::vector< PreparedStatementData > m_statementData;

View file

@ -38,7 +38,7 @@ bool Core::Db::StatementTask::execute()
}
Core::Db::PreparedStatementTask::PreparedStatementTask( boost::shared_ptr< Core::Db::PreparedStatement > stmt,
Core::Db::PreparedStatementTask::PreparedStatementTask( std::shared_ptr< Core::Db::PreparedStatement > stmt,
bool async ) :
m_stmt( stmt )
//, m_result(nullptr)

View file

@ -2,8 +2,8 @@
#define SAPPHIRE_STATEMENTTASK_H
#include <string>
#include <boost/shared_ptr.hpp>
#include "Operation.h"
#include <memory>
namespace Core {
namespace Db {
@ -35,7 +35,7 @@ class PreparedStatementTask :
public Operation
{
public:
PreparedStatementTask( boost::shared_ptr< PreparedStatement > stmt, bool async = false );
PreparedStatementTask( std::shared_ptr< PreparedStatement > stmt, bool async = false );
~PreparedStatementTask();
@ -43,7 +43,7 @@ public:
//PreparedQueryResultFuture getFuture() { return m_result->get_future(); }
protected:
boost::shared_ptr< PreparedStatement > m_stmt;
std::shared_ptr< PreparedStatement > m_stmt;
bool m_hasResult;
//PreparedQueryResultPromise* m_result;
};

View file

@ -6,7 +6,7 @@ Core::Db::ZoneDbConnection::ZoneDbConnection( ConnectionInfo& connInfo ) :
{
}
Core::Db::ZoneDbConnection::ZoneDbConnection( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* q,
Core::Db::ZoneDbConnection::ZoneDbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* q,
ConnectionInfo& connInfo ) :
DbConnection( q, connInfo )
{

View file

@ -88,7 +88,7 @@ public:
ZoneDbConnection( ConnectionInfo& connInfo );
ZoneDbConnection( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* q, ConnectionInfo& connInfo );
ZoneDbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* q, ConnectionInfo& connInfo );
~ZoneDbConnection();

View file

@ -1,13 +1,13 @@
#ifndef COMMON_FORWARDS_H
#define COMMON_FORWARDS_H
#include <boost/shared_ptr.hpp>
#include <memory>
namespace Core {
class ConfigMgr;
typedef boost::shared_ptr< ConfigMgr > ConfigMgrPtr;
typedef std::shared_ptr< ConfigMgr > ConfigMgrPtr;
namespace Network {
@ -17,17 +17,17 @@ class Acceptor;
class Connection;
typedef boost::shared_ptr< Hive > HivePtr;
typedef boost::shared_ptr< Acceptor > AcceptorPtr;
typedef boost::shared_ptr< Connection > ConnectionPtr;
typedef std::shared_ptr< Hive > HivePtr;
typedef std::shared_ptr< Acceptor > AcceptorPtr;
typedef std::shared_ptr< Connection > ConnectionPtr;
namespace Packets {
class GamePacket;
class FFXIVPacketBase;
typedef boost::shared_ptr< GamePacket > GamePacketPtr;
typedef boost::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr;
typedef std::shared_ptr< GamePacket > GamePacketPtr;
typedef std::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr;
}
}
@ -36,4 +36,4 @@ typedef boost::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr;
}
#endif
#endif

View file

@ -1,4 +1,2 @@
#include "Framework.h"
#include "Logging/Logger.h"
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>

View file

@ -4,27 +4,27 @@
#include <map>
#include <typeindex>
#include <typeinfo>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <cassert>
namespace Core {
class Framework
{
using TypenameToObject = std::map< std::type_index, boost::shared_ptr< void > >;
using TypenameToObject = std::map< std::type_index, std::shared_ptr< void > >;
TypenameToObject ObjectMap;
public:
template< typename T >
boost::shared_ptr< T > get()
std::shared_ptr< T > get()
{
auto iType = ObjectMap.find( typeid( T ) );
assert( !( iType == ObjectMap.end() ) );
return boost::static_pointer_cast< T >( iType->second );
return std::static_pointer_cast< T >( iType->second );
}
template< typename T >
void set( boost::shared_ptr< T > value )
void set( std::shared_ptr< T > value )
{
assert( value ); // why would anyone store nullptrs....
ObjectMap[ typeid( T ) ] = value;

@ -1 +1 @@
Subproject commit b89d9a2dfcca81ab4241e791a0a78bb9ea34036c
Subproject commit 883f4850885634e2366ca82d69a730b1c2e694e7