Skip to content

Commit 69c4e03

Browse files
authored
Remove boost (#3)
* Remove boost::string dependency A bit silly for simple string manipulations, especially now that AMQP support does not require boost::asio * CMake: Remove boost
1 parent b8a9b45 commit 69c4e03

5 files changed

Lines changed: 18 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11/"
2222
DESTINATION "include"
2323
FILES_MATCHING PATTERN "*.hpp")
2424

25-
# Boost
26-
set(Boost_USE_STATIC_LIBS ON)
27-
find_package(Boost COMPONENTS REQUIRED system)
28-
29-
# libev
25+
# libev, used by AMQP
3026
find_path(libev_INCLUDE_DIRECTORY ev.h)
3127
find_library(libev_LIB ev)
3228

@@ -47,8 +43,6 @@ add_library(msgflo src/msgflo.cpp src/mqtt_support.cpp src/mqtt_support.h ${JSON
4743
target_include_directories(msgflo
4844
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
4945
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11>
50-
# Boost could made private with little effort, migth be worth.
51-
PUBLIC ${Boost_INCLUDE_DIR}
5246
PRIVATE ${libev_INCLUDE_DIRECTORY}
5347
PRIVATE ${amqp_install}/include
5448
PRIVATE ${mosquitto_INCLUDE_DIRECTORY}
@@ -58,7 +52,6 @@ target_include_directories(msgflo
5852
target_compile_options(msgflo PRIVATE -Wall -Wextra -Wno-unused-parameter)
5953

6054
target_link_libraries(msgflo
61-
PRIVATE ${Boost_LIBRARIES}
6255
PRIVATE ${amqp_install}/lib/libamqpcpp.a
6356
PRIVATE ${mosquitto_LIB}
6457
PRIVATE ${libev_LIB})

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ MIT, see [./LICENSE](./LICENSE)
3434
0.1
3535

3636
* Fix missing port identifier in process()
37-
* Remove boost dependency
3837
* AMQP: Implement NACK

examples/repeat.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <algorithm>
44
#include <chrono>
55
#include <thread>
6-
#include <boost/algorithm/string.hpp>
76

87
#include "msgflo.h"
98

include/msgflo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <string>
44
#include <memory>
5-
#include <boost/algorithm/string.hpp>
65
#include "json11.hpp"
76

87
namespace msgflo {

src/msgflo.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ using namespace trygvis::mqtt_support;
1111

1212
namespace msgflo {
1313

14+
std::string string_to_upper_copy(const std::string &str) {
15+
std::string ret;
16+
ret.resize(str.size());
17+
for (uint i=0; i<str.size(); i++) {
18+
ret[i] = toupper(str[i]);
19+
}
20+
return ret;
21+
}
22+
23+
bool string_starts_with(const std::string &str, const std::string &prefix) {
24+
return str.substr(0, prefix.size()) == prefix;
25+
}
26+
1427
class DiscoveryMessage {
1528
public:
1629
DiscoveryMessage(const Definition &def)
@@ -179,7 +192,7 @@ class AmqpEngine final : public Engine, protected AbstractEngine<AmqpEngine> {
179192

180193
protected:
181194
string generateQueueName(const Definition &d, const Definition::Port &port) override {
182-
return d.role + "." + boost::to_upper_copy<std::string>(port.id);
195+
return d.role + "." + string_to_upper_copy(port.id);
183196
}
184197

185198
private:
@@ -281,7 +294,7 @@ class MosquittoEngine final : public Engine, protected mqtt_event_listener, prot
281294

282295
protected:
283296
string generateQueueName(const Definition &d, const Definition::Port &port) override {
284-
return "/" + d.role + "." + boost::to_upper_copy<std::string>(port.id);
297+
return "/" + d.role + "." + string_to_upper_copy(port.id);
285298
}
286299

287300
virtual void on_msg(const string &msg) override {
@@ -335,7 +348,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
335348
}
336349
}
337350

338-
if (boost::starts_with(url, "mqtt://")) {
351+
if (string_starts_with(url, "mqtt://")) {
339352
string host, username, password;
340353
int port = 1883;
341354
int keep_alive = 180;
@@ -431,7 +444,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
431444
}
432445

433446
return make_shared<MosquittoEngine>(config, host, port, keep_alive, client_id, clean_session);
434-
} else if (boost::starts_with(url, "amqp://")) {
447+
} else if (string_starts_with(url, "amqp://")) {
435448
return make_shared<AmqpEngine>(url);
436449
}
437450

0 commit comments

Comments
 (0)