From 80c49c35375204797cab7141c36a55cebc2ad6d8 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Fri, 26 Oct 2018 21:00:50 +1100 Subject: [PATCH] remove boost, its gone --- cmake/boost.cmake | 39 ---------- src/servers/sapphire_api/SapphireAPI.cpp | 51 ++++++------- src/servers/sapphire_api/main.cpp | 2 - src/servers/sapphire_lobby/RestConnector.cpp | 78 +++++++------------- 4 files changed, 52 insertions(+), 118 deletions(-) delete mode 100644 cmake/boost.cmake diff --git a/cmake/boost.cmake b/cmake/boost.cmake deleted file mode 100644 index 3e1c37ef..00000000 --- a/cmake/boost.cmake +++ /dev/null @@ -1,39 +0,0 @@ - -if(UNIX) - - find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system) - if(Boost_FOUND) - set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR}) - else() - if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}) - set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}) - set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib) - else() - message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!") - endif() - endif() -else() - - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}) - message(STATUS "Using boost in /libraries/external") - set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}) - set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0) - else() - find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system) - if(Boost_FOUND) - set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR}) - elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR})) - set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR}) - set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR}) - else() - message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!") - endif() - endif() -endif() - -set(Boost_USE_STATIC_LIBS ON) - -find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system) -include_directories(${Boost_INCLUDE_DIR}) -link_directories(${BOOST_LIBRARYDIR}) - diff --git a/src/servers/sapphire_api/SapphireAPI.cpp b/src/servers/sapphire_api/SapphireAPI.cpp index 90b02d2c..33602b13 100644 --- a/src/servers/sapphire_api/SapphireAPI.cpp +++ b/src/servers/sapphire_api/SapphireAPI.cpp @@ -4,12 +4,7 @@ #include "PlayerMinimal.h" #include -#define BOOST_SPIRIT_THREADSAFE - -#include -#include -#include -#include +#include #include @@ -122,15 +117,8 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st newPlayer.setContentId( getNextContentId() ); newPlayer.setName( name.c_str() ); - boost::property_tree::ptree pt; - auto json = nlohmann::json::parse( infoJson ); - std::stringstream ss; - ss << infoJson; - - boost::property_tree::read_json( ss, pt ); - const char* ptr = infoJson.c_str() + 50; std::string lookPart( ptr ); @@ -143,18 +131,31 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st std::vector< int32_t > tmpVector; std::vector< int32_t > tmpVector2; - BOOST_FOREACH( boost::property_tree::ptree::value_type& v, pt.get_child( "content" ) ) - { - boost::property_tree::ptree subtree1 = v.second; - BOOST_FOREACH( boost::property_tree::ptree::value_type& vs, subtree1 ) - { - boost::property_tree::ptree subtree2 = vs.second; - //std::cout << vs.second.data(); - tmpVector.push_back( std::stoi( vs.second.data() ) ); - } - if( !v.second.data().empty() ) - tmpVector2.push_back( std::stoi( v.second.data() ) ); - } + for( auto& v : json["content"] ) + { + for( auto& vs : v ) + { + tmpVector.push_back( vs.get< int >() ); + } + + if( !v.empty() ) + tmpVector2.push_back( v.get< int >() ); + } + + // leaving this in for now for reference + // BOOST_FOREACH( boost::property_tree::ptree::value_type& v, pt.get_child( "content" ) ) + // { + // boost::property_tree::ptree subtree1 = v.second; + // BOOST_FOREACH( boost::property_tree::ptree::value_type& vs, subtree1 ) + // { + // boost::property_tree::ptree subtree2 = vs.second; + // //std::cout << vs.second.data(); + // tmpVector.push_back( std::stoi( vs.second.data() ) ); + // } + // if( !v.second.data().empty() ) + // tmpVector2.push_back( std::stoi( v.second.data() ) ); + // } + std::vector< int32_t >::iterator it = tmpVector.begin(); for( int32_t i = 0; it != tmpVector.end(); ++it, i++ ) { diff --git a/src/servers/sapphire_api/main.cpp b/src/servers/sapphire_api/main.cpp index 4f3d0231..baf1f56b 100644 --- a/src/servers/sapphire_api/main.cpp +++ b/src/servers/sapphire_api/main.cpp @@ -1,8 +1,6 @@ #include "server_http.hpp" #include "client_http.hpp" -#define BOOST_SPIRIT_THREADSAFE - #include #include diff --git a/src/servers/sapphire_lobby/RestConnector.cpp b/src/servers/sapphire_lobby/RestConnector.cpp index cfbafc1d..ac1727b1 100644 --- a/src/servers/sapphire_lobby/RestConnector.cpp +++ b/src/servers/sapphire_lobby/RestConnector.cpp @@ -6,13 +6,11 @@ #include #include -#define BOOST_SPIRIT_THREADSAFE - #include extern Core::Logger g_log; -typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string>> CharList; +typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string > > CharList; Core::Network::RestConnector::RestConnector() { @@ -97,15 +95,11 @@ bool Core::Network::RestConnector::checkNameTaken( std::string name ) std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -113,7 +107,7 @@ bool Core::Network::RestConnector::checkNameTaken( std::string name ) return true; } - if( pt.get< std::string >( "result" ) != "invalid" && pt.get< std::string >( "result" ) == "false" ) + if( json["result"] != "invalid" && json["result"] == "false" ) return false; return true; } @@ -135,15 +129,11 @@ uint32_t Core::Network::RestConnector::getNextCharId() std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -153,7 +143,7 @@ uint32_t Core::Network::RestConnector::getNextCharId() if( content.find( "invalid" ) == std::string::npos ) { - return pt.get< uint32_t >( "result" ); + return json["result"].get< uint32_t >(); } else { @@ -178,15 +168,11 @@ uint64_t Core::Network::RestConnector::getNextContentId() std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -196,7 +182,7 @@ uint64_t Core::Network::RestConnector::getNextContentId() if( content.find( "invalid" ) == std::string::npos ) { - return pt.get< uint64_t >( "result" ); + return json["result"].get< uint64_t >(); } else { @@ -223,15 +209,11 @@ CharList Core::Network::RestConnector::getCharList( char* sId ) g_log.debug( content ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -239,18 +221,19 @@ CharList Core::Network::RestConnector::getCharList( char* sId ) return list; } - if( pt.get< std::string >( "result" ).find( "invalid" ) == std::string::npos ) + if( json["result"].get< std::string >().find( "invalid" ) == std::string::npos ) { - g_log.debug( pt.get_value< std::string >( "result" ) ); + g_log.debug( json["result"] ); - for( auto& child : pt.get_child( "charArray" ) ) + for( auto& child : json["charArray"] ) { - g_log.debug( child.second.get< std::string >( "contentId" ) ); - list.push_back( std::make_tuple( child.second.get< std::string >( "name" ), - atoi( child.second.get< std::string >( "charId" ).c_str() ), - child.second.get< uint64_t >( "contentId" ), - child.second.get< std::string >( "infoJson" ) ) ); + g_log.debug( child["contentId"] ); + //std::string, uint32_t, uint64_t, std::string + list.push_back( std::make_tuple( child["name"].get< std::string >() ), + child["charId"].get< uint32_t >(), + child["contentId"].get< uint64_t >(), + child["infoJson"].get< std::string >() ); } return list; @@ -280,15 +263,10 @@ bool Core::Network::RestConnector::deleteCharacter( char* sId, std::string name std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; - + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -321,15 +299,11 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name, g_log.debug( content ); if( r->status_code.find( "200" ) != std::string::npos ) { - using namespace boost::property_tree; - ptree pt; + auto json = nlohmann::json(); try { - std::stringstream ss; - ss << content; - - read_json( ss, pt ); + json.parse( content ); } catch( std::exception& e ) { @@ -338,7 +312,7 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name, } if( content.find( "invalid" ) == std::string::npos ) - return atoi( pt.get< std::string >( "result" ).c_str() ); + return json["result"].get< int >(); return -1; } else