Skip to content

Commit 23a7fc1

Browse files
committed
fmt eliminated
1 parent 6733703 commit 23a7fc1

4 files changed

Lines changed: 50 additions & 46 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2929
# Prefer Conan packages over system packages for reproducibility
3030
# Don't search system directories unless explicitly told to
3131
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
32-
# Make -isystem happen AFTER our includes
33-
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem" CACHE STRING "Flag to force system includes to be treated as system" FORCE)
32+
# Make -isystem happen AFTER our includes (not for MSVC - it doesn't support -isystem)
33+
if(NOT MSVC)
34+
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem" CACHE STRING "Flag to force system includes to be treated as system" FORCE)
35+
endif()
3436

3537
# Build options
3638
option(BUILD_TESTING "Build tests" ON)
@@ -114,7 +116,6 @@ if(USE_CONAN AND CONAN_TOOLCHAIN_FOUND)
114116
# These should be in the generators directory
115117
find_package(Catch2 QUIET)
116118
find_package(cpprestsdk REQUIRED)
117-
find_package(fmt REQUIRED)
118119
find_package(rxcpp QUIET)
119120
find_package(OpenSSL REQUIRED)
120121

@@ -125,12 +126,11 @@ if(USE_CONAN AND CONAN_TOOLCHAIN_FOUND)
125126
message(STATUS "Catch2 from Conan not found - tests will fail if it's not available")
126127
endif()
127128

128-
if(TARGET fmt::fmt AND TARGET cpprestsdk::cpprestsdk)
129+
if(TARGET cpprestsdk::cpprestsdk)
129130
set(CONAN_LIBS
130131
cpprestsdk::cpprestsdk
131-
fmt::fmt
132132
)
133-
message(STATUS "Using Conan packages: fmt::fmt, cpprestsdk::cpprestsdk")
133+
message(STATUS "Using Conan packages: cpprestsdk::cpprestsdk")
134134
# Add rxcpp if found from Conan
135135
if(TARGET RxCpp::RxCpp)
136136
list(APPEND CONAN_LIBS RxCpp::RxCpp)
@@ -143,9 +143,6 @@ if(USE_CONAN AND CONAN_TOOLCHAIN_FOUND)
143143
endif()
144144
else()
145145
message(FATAL_ERROR "Required Conan packages not found as targets")
146-
if(NOT TARGET fmt::fmt)
147-
message(FATAL_ERROR " - fmt::fmt target not found")
148-
endif()
149146
if(NOT TARGET cpprestsdk::cpprestsdk)
150147
message(FATAL_ERROR " - cpprestsdk::cpprestsdk target not found")
151148
endif()
@@ -165,7 +162,7 @@ list(FILTER INFLUXDB_CPP_REST_SOURCES EXCLUDE REGEX ".*\\.h$")
165162
add_library(influxdb-cpp-rest STATIC
166163
${INFLUXDB_CPP_REST_SOURCES}
167164
)
168-
target_include_directories(influxdb-cpp-rest PUBLIC
165+
target_include_directories(influxdb-cpp-rest PUBLIC
169166
src/influxdb-cpp-rest
170167
)
171168
target_link_libraries(influxdb-cpp-rest
@@ -175,23 +172,29 @@ target_link_libraries(influxdb-cpp-rest
175172
# Workaround: Conan OpenSSL CMakeDeps doesn't set include directories
176173
if(TARGET OpenSSL::SSL)
177174
# Read openssl package folder from the data file
178-
file(GLOB _OPENSSL_DATA_FILES "${CMAKE_CURRENT_LIST_DIR}/OpenSSL-*-data.cmake")
175+
file(GLOB _OPENSSL_DATA_FILES "${CMAKE_BINARY_DIR}/OpenSSL-*-data.cmake")
179176
if(_OPENSSL_DATA_FILES)
180177
list(GET _OPENSSL_DATA_FILES 0 _OPENSSL_DATA_FILE)
181-
endif()
182-
if(_OPENSSL_DATA_FILE)
178+
message(STATUS "Found OpenSSL data file: ${_OPENSSL_DATA_FILE}")
183179
file(READ "${_OPENSSL_DATA_FILE}" _OPENSSL_DATA_CONTENT)
184180
string(REGEX MATCH "set\\(openssl_PACKAGE_FOLDER_RELEASE \"([^\"]+)\"\\)" _MATCH "${_OPENSSL_DATA_CONTENT}")
185181
if(_MATCH)
186182
string(REGEX REPLACE ".*openssl_PACKAGE_FOLDER_RELEASE \"([^\"]+)\".*" "\\1" OPENSSL_PKG_FOLDER "${_MATCH}")
187183
set(OPENSSL_INCLUDE_DIR "${OPENSSL_PKG_FOLDER}/include")
184+
message(STATUS "OpenSSL pkg folder: ${OPENSSL_PKG_FOLDER}, include: ${OPENSSL_INCLUDE_DIR}")
188185
if(EXISTS "${OPENSSL_INCLUDE_DIR}")
189186
set_target_properties(OpenSSL::SSL OpenSSL::Crypto PROPERTIES
190187
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}"
191188
)
192189
message(STATUS "Set OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
190+
else()
191+
message(WARNING "OpenSSL include dir does not exist: ${OPENSSL_INCLUDE_DIR}")
193192
endif()
193+
else()
194+
message(WARNING "Could not extract OpenSSL package folder from data file")
194195
endif()
196+
else()
197+
message(WARNING "Could not find OpenSSL data file")
195198
endif()
196199
endif()
197200

conanfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def configure(self):
2626

2727
def requirements(self):
2828
self.requires("cpprestsdk/2.10.19") # Latest stable version
29-
self.requires("fmt/12.1.0") # Latest stable version with C++20 support
3029
self.requires("rxcpp/4.1.1") # Latest stable version
3130

3231
def build_requirements(self):

src/influxdb-cpp-rest/influxdb_line.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@
1010
#include <utility>
1111
#include <chrono>
1212
#include <type_traits>
13+
#include <iterator>
14+
#include <format>
1315
#include "input_sanitizer.h"
14-
#include <fmt/format.h>
1516

1617
namespace influxdb {
1718

1819
namespace api {
1920

2021
// https://docs.influxdata.com/influxdb/v1.0/write_protocols/line_protocol_tutorial/
2122
class key_value_pairs {
22-
fmt::memory_buffer res;
23+
std::string res;
2324

2425
public:
2526

2627
key_value_pairs() {};
2728
~key_value_pairs() {};
2829

2930
key_value_pairs(key_value_pairs const& other) {
30-
format_to(res, "{}", other.get());
31+
std::format_to(std::back_inserter(res), "{}", other.get());
3132
}
3233

3334
key_value_pairs& operator=(key_value_pairs const& other) {
34-
format_to(res, "{}", other.get());
35+
std::format_to(std::back_inserter(res), "{}", other.get());
3536
return *this;
3637
}
3738

@@ -57,7 +58,7 @@ namespace influxdb {
5758

5859
add_comma_if_necessary();
5960

60-
format_to(res, "{}={}i", key, value);
61+
std::format_to(std::back_inserter(res), "{}={}i", key, value);
6162

6263
return *this;
6364
}
@@ -74,7 +75,7 @@ namespace influxdb {
7475

7576
add_comma_if_necessary();
7677

77-
format_to(res, "{}={}", key, value);
78+
std::format_to(std::back_inserter(res), "{}={}", key, value);
7879

7980
return *this;
8081
}
@@ -90,7 +91,7 @@ namespace influxdb {
9091

9192
add_comma_if_necessary();
9293

93-
format_to(res, "{}={}", key, value);
94+
std::format_to(std::back_inserter(res), "{}={}", key, value);
9495

9596
return *this;
9697
}
@@ -100,23 +101,23 @@ namespace influxdb {
100101

101102
add_comma_if_necessary();
102103

103-
format_to(res, "{}=\"{}\"", key, value);
104+
std::format_to(std::back_inserter(res), "{}=\"{}\"", key, value);
104105

105106
return *this;
106107
}
107108

108109
inline std::string get() const {
109-
return std::string(res.data(),res.size());
110+
return res;
110111
}
111112

112113
inline bool empty() const {
113-
return !res.size();
114+
return res.empty();
114115
}
115116

116117
private:
117118
inline void add_comma_if_necessary() {
118119
if (!this->empty())
119-
format_to(res, ",");
120+
std::format_to(std::back_inserter(res), ",");
120121
}
121122
};
122123

@@ -131,68 +132,68 @@ namespace influxdb {
131132

132133
/// simplest, probably slow implementation
133134
class line {
134-
fmt::memory_buffer res;
135+
std::string res;
135136

136137
public:
137138
line() {};
138139
~line() {};
139140

140141
line& operator=(line const& other) {
141-
format_to(res, "{}", other.get());
142+
std::format_to(std::back_inserter(res), "{}", other.get());
142143
return *this;
143144
}
144145

145146
line(line const& other) {
146-
format_to(res, "{}", other.get());
147+
std::format_to(std::back_inserter(res), "{}", other.get());
147148
}
148149

149150
line(line && other) {
150151
res = std::move(other.res);
151152
}
152153

153154
explicit line(std::string const& raw) {
154-
format_to(res, "{}", raw);
155+
std::format_to(std::back_inserter(res), "{}", raw);
155156
}
156157

157158
template<typename TTimestamp>
158159
explicit line(std::string const& raw, TTimestamp const& timestamp) {
159-
format_to(res, "{} {}", raw, timestamp.now());
160+
std::format_to(std::back_inserter(res), "{} {}", raw, timestamp.now());
160161
}
161162

162163
template<typename TMap>
163164
inline line(std::string const& measurement, TMap const& tags, TMap const& values) {
164165
::influxdb::utility::throw_on_invalid_identifier(measurement);
165166

166-
format_to(res, "{}", measurement);
167+
std::format_to(std::back_inserter(res), "{}", measurement);
167168
if (!tags.empty()) {
168-
format_to(res, ",{}", tags.get());
169+
std::format_to(std::back_inserter(res), ",{}", tags.get());
169170
}
170171

171172
if (!values.empty()) {
172-
format_to(res, " {}", values.get());
173+
std::format_to(std::back_inserter(res), " {}", values.get());
173174
}
174175
}
175176

176177
template<typename TMap,typename TTimestamp>
177178
inline line(std::string const& measurement, TMap const& tags, TMap const& values, TTimestamp const& timestamp):
178179
line(measurement, tags, values) {
179-
format_to(res, " {}", timestamp.now());
180+
std::format_to(std::back_inserter(res), " {}", timestamp.now());
180181
}
181182

182183
template<typename TMap>
183184
inline line& operator()(std::string const& measurement, TMap const& tags, TMap const& values) {
184-
format_to(res, "\n{}", line(measurement, tags, values).get());
185+
std::format_to(std::back_inserter(res), "\n{}", line(measurement, tags, values).get());
185186
return *this;
186187
}
187188

188189
template<typename TMap, typename TTimestamp>
189190
inline line& operator()(std::string const& measurement, TMap const& tags, TMap const& values, TTimestamp const& timestamp) {
190-
format_to(res, "\n{}", line(measurement, tags, values, timestamp).get());
191+
std::format_to(std::back_inserter(res), "\n{}", line(measurement, tags, values, timestamp).get());
191192
return *this;
192193
}
193194
public:
194195
inline std::string get() const {
195-
return std::string(res.data(),res.size());
196+
return res;
196197
}
197198
};
198199

src/influxdb-cpp-rest/influxdb_simple_async_api.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
#include "input_sanitizer.h"
1414
#include "influxdb_line.h"
1515

16-
#include <rx.hpp>
16+
#include <rxcpp/rx.hpp>
1717
#include <chrono>
1818
#include <atomic>
19-
#include <fmt/format.h>
19+
#include <format>
20+
#include <iterator>
2021

2122
using namespace influxdb::utility;
2223

@@ -57,18 +58,18 @@ struct influxdb::async_api::simple_db::impl {
5758
.subscribe(
5859
[this](rxcpp::observable<std::string> window) {
5960
window.scan(
60-
std::make_shared<fmt::memory_buffer>(),
61-
[this](std::shared_ptr<fmt::memory_buffer> const& w, std::string const& v) {
62-
format_to(*w, "{}\n", v);
61+
std::make_shared<std::string>(),
62+
[this](std::shared_ptr<std::string> const& w, std::string const& v) {
63+
std::format_to(std::back_inserter(*w), "{}\n", v);
6364
return w;
6465
})
65-
.start_with(std::make_shared<fmt::memory_buffer>())
66+
.start_with(std::make_shared<std::string>())
6667
.last()
6768
.observe_on(rxcpp::synchronize_new_thread())
68-
.subscribe([this](std::shared_ptr<fmt::memory_buffer> const& w) {
69-
if (w->size() > 0u) {
69+
.subscribe([this](std::shared_ptr<std::string> const& w) {
70+
if (!w->empty()) {
7071
try {
71-
db.insert_async(std::string(w->data(),w->size()));
72+
db.insert_async(*w);
7273
} catch (const std::runtime_error& e) {
7374
throw std::runtime_error(std::string("async_api::insert failed: ") + e.what() + " -> Dropping " + std::to_string(w->size()) + " bytes");
7475
}

0 commit comments

Comments
 (0)