Skip to content

Commit

Permalink
Got rid of Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Oct 30, 2019
1 parent e40c40b commit 7064cc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ include_guard(GLOBAL)
project(Network LANGUAGES CXX)

find_package(CURL REQUIRED)
find_package(Boost 1.70.0 REQUIRED)

include_directories(include ${Boost_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
include_directories(include ${CURL_INCLUDE_DIR})

add_library(Network SHARED src/Network.cpp)
target_compile_features(Network PUBLIC cxx_std_17)
target_link_libraries(Network PRIVATE ${Boost_LIBRARIES} ${CURL_LIBRARIES})
target_link_libraries(Network PRIVATE ${CURL_LIBRARIES})
target_include_directories(Network PUBLIC ${PROJECT_SOURCE_DIR}/include)

set_property(GLOBAL PROPERTY Network_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(Network PROPERTIES
VERSION 2.0.1
VERSION 2.0.2
PUBLIC_HEADER "include/Network.hpp")

INSTALL(TARGETS Network
Expand Down
2 changes: 2 additions & 0 deletions include/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Network{

static size_t string_writer(char* contents, size_t size, size_t nmemb, std::string* stream);
static size_t file_writer(void* contents, size_t size, size_t nmemb, FILE* stream);

std::string join(const std::vector<std::string> lst, const std::string& delim) const;
};

}
Expand Down
11 changes: 9 additions & 2 deletions src/Network.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <memory>

#include <curl/curl.h>
#include <boost/algorithm/string/join.hpp>

#include "Network.hpp"

Expand Down Expand Up @@ -44,7 +44,7 @@ std::string Network::request(std::string url, const std::map<std::string, std::s
tmp_list.push_back(row.first + "=" + (data ? std::string(data.get()) : row.second));
}

fields = boost::algorithm::join(tmp_list, "&");
fields = join(tmp_list, "&");
}

curl = std::shared_ptr<CURL>(curl_easy_init(), curl_easy_cleanup);
Expand Down Expand Up @@ -160,3 +160,10 @@ size_t Network::file_writer(void* contents, size_t size, size_t nmemb, FILE* str
size_t written = fwrite(contents, size, nmemb, stream);
return written;
}

std::string Network::join(const std::vector<std::string> lst, const std::string& delim) const {
std::ostringstream ss;
for(size_t i = 0; i < lst.size(); i++)
ss << lst[i] << (i + 1 == lst.size() ? "" : delim);
return ss.str();
}

0 comments on commit 7064cc1

Please sign in to comment.