Skip to content

Commit 61ee4ae

Browse files
committed
removing boost dependency
1 parent 07f9db3 commit 61ee4ae

File tree

15 files changed

+136
-50
lines changed

15 files changed

+136
-50
lines changed

.clang-tidy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Checks: "*,
1111
-cppcoreguidelines-pro-type-reinterpret-cast,
1212
-altera-struct-pack-align,
1313
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
14-
-hicpp-no-array-decay
15-
-readability-identifier-naming
14+
-hicpp-no-array-decay,
15+
-readability-identifier-naming,
1616
"
1717
CheckOptions:
1818
misc-non-private-member-variables-in-classes: IgnoreClassesWithAllMemberVariablesBeingPublic

libtokamap/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# LANGUAGES CXX
66
# )
77

8-
find_package( Boost REQUIRED )
9-
108
# Specify C++ standard for all targets
119
set( CMAKE_CXX_STANDARD 20 )
1210
set( CMAKE_CXX_STANDARD_REQUIRED ON )
@@ -73,7 +71,6 @@ configure_file(
7371
)
7472

7573
add_library( libtokamap ${SOURCES} )
76-
target_link_libraries( libtokamap PUBLIC Boost::boost )
7774
target_include_directories( libtokamap
7875
PRIVATE
7976
${CMAKE_CURRENT_SOURCE_DIR}/src

libtokamap/TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
- [ ] Add C++20 template constraints
1313
- [ ] Replace std::string{} with string_literals
1414
- [ ] Fix logging
15+
- [ ] Add tests for parse_slices
16+
- [ ] Replace gsl::span with std::span

libtokamap/examples/simple_mapper/src/json_data_source.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#include "json_data_source.hpp"
22
#include "map_types/map_arguments.hpp"
3+
#include "utils/algorithm.hpp"
34

45
#include <algorithm>
5-
#include <boost/algorithm/string.hpp>
66
#include <cstddef>
77
#include <cstdlib>
8+
#include <ctre/ctre.hpp>
89
#include <deque>
910
#include <filesystem>
1011
#include <fstream>
1112
#include <libtokamap.hpp>
1213
#include <nlohmann/json.hpp>
14+
#include <ranges>
1315
#include <stdexcept>
1416
#include <string>
17+
#include <string_view>
1518
#include <vector>
16-
#include <ctre/ctre.hpp>
1719

1820
namespace
1921
{
@@ -84,7 +86,7 @@ libtokamap::TypedDataArray JSONDataSource::get(const libtokamap::DataSourceArgs&
8486
std::string signal = map_args.at("signal");
8587

8688
std::deque<std::string> tokens;
87-
boost::split(tokens, signal, boost::is_any_of("/"));
89+
libtokamap::split(tokens, signal, "/");
8890

8991
nlohmann::json& value = data;
9092
while (!tokens.empty()) {

libtokamap/src/handlers/mapping_handler.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "mapping_handler.hpp"
22

3-
#include <boost/algorithm/string.hpp>
4-
#include <boost/algorithm/string/case_conv.hpp>
3+
#include <algorithm>
4+
#include <cctype>
55
#include <cstddef>
66
#include <cstdint>
77
#include <cxxabi.h>
@@ -15,9 +15,11 @@
1515
#include <nlohmann/json.hpp>
1616
#include <optional>
1717
#include <ostream>
18+
#include <ranges>
1819
#include <sstream>
1920
#include <stdexcept>
2021
#include <string>
22+
#include <string_view>
2123
#include <type_traits>
2224
#include <typeindex>
2325
#include <unordered_map>
@@ -32,6 +34,7 @@
3234
#include "map_types/expr_mapping.hpp"
3335
#include "map_types/map_arguments.hpp"
3436
#include "map_types/value_mapping.hpp"
37+
#include "utils/algorithm.hpp"
3538
#include "utils/indices.hpp"
3639
#include "utils/ram_cache.hpp"
3740
#include "utils/syntax_parser.hpp"
@@ -176,8 +179,8 @@ libtokamap::TypedDataArray libtokamap::MappingHandler::map(const std::string& ma
176179
std::type_index data_type, int rank,
177180
const nlohmann::json& extra_attributes)
178181
{
179-
std::deque<std::string> path_tokens;
180-
boost::split(path_tokens, path, boost::is_any_of("/"));
182+
std::deque<std::string_view> path_tokens;
183+
libtokamap::split(path_tokens, path, "/");
181184
if (path_tokens.empty()) {
182185
throw std::runtime_error{"IDS path could not be split"};
183186
}
@@ -189,7 +192,7 @@ libtokamap::TypedDataArray libtokamap::MappingHandler::map(const std::string& ma
189192

190193
// Use lowercase machine name for find mapping files
191194
std::string machine_string = mapping;
192-
boost::to_lower(machine_string);
195+
to_lower(machine_string);
193196

194197
// Load mappings based off IDS name
195198
// Returns a reference to IDS map objects and corresponding globals
@@ -456,7 +459,7 @@ std::string find_mapping(libtokamap::IDSMapRegister& mappings, const std::string
456459
}
457460

458461
// Check for last # replaced with index
459-
std::string new_path = boost::replace_last_copy(path, "#", std::to_string(indices.back()));
462+
std::string new_path = libtokamap::replace_last_copy(path, "#", std::to_string(indices.back()));
460463
if (mappings.contains(new_path)) {
461464
return new_path;
462465
}
@@ -477,8 +480,8 @@ void init_data_source_mapping(libtokamap::IDSMapRegister& map_reg, const std::st
477480
if (!value.contains("DATA_SOURCE")) {
478481
throw std::runtime_error{"required DATA_SOURCE argument not provided in DATA_SOURCE mapping '" + key + "'"};
479482
}
480-
auto data_source_name = value["DATA_SOURCE"].get<std::string>();
481-
boost::to_upper(data_source_name);
483+
std::string data_source_name = value["DATA_SOURCE"].get<std::string>();
484+
libtokamap::to_upper(data_source_name);
482485

483486
if (!value.contains("ARGS")) {
484487
throw std::runtime_error{"required ARGS argument not provided in DATA_SOURCE mapping '" + key + "'"};
@@ -565,13 +568,13 @@ std::string libtokamap::generate_map_path(std::deque<std::string>& path_tokens,
565568
return {}; // Don't throw, go gentle into that good night
566569
}
567570

568-
std::string map_path = boost::algorithm::join(path_tokens, "/");
571+
std::string map_path = libtokamap::join(path_tokens, "/");
569572
std::string found_path;
570573

571574
if (!mappings.contains(map_path)) {
572575
if (sig_type == SignalType::TIME or sig_type == SignalType::DATA) {
573576
path_tokens.pop_back();
574-
map_path = boost::algorithm::join(path_tokens, "/");
577+
map_path = libtokamap::join(path_tokens, "/");
575578
}
576579
found_path = find_mapping(mappings, map_path, indices, full_path);
577580
} else {

libtokamap/src/map_types/map_arguments.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "map_arguments.hpp"
22

3-
#include <boost/algorithm/string.hpp>
43
#include <string>
54
#include <string_view>
65
#include <cstddef>

libtokamap/src/utils/algorithm.hpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#pragma once
2+
3+
#include <algorithm>
4+
#include <cctype>
5+
#include <cstddef>
6+
#include <functional>
7+
#include <iterator>
8+
#include <numeric>
9+
#include <ranges>
10+
#include <string>
11+
#include <string_view>
12+
#include <type_traits>
13+
14+
namespace libtokamap
15+
{
16+
17+
inline void to_lower(std::string& string) { std::ranges::transform(string, string.begin(), ::tolower); }
18+
inline void to_upper(std::string& string) { std::ranges::transform(string, string.begin(), ::toupper); }
19+
20+
template <typename T>
21+
concept StringCollection = std::ranges::random_access_range<T> && std::is_same_v<typename T::value_type, std::string>;
22+
23+
template <StringCollection Coll>
24+
inline void split(Coll& collection, const std::string& input, const std::string& delimiter)
25+
{
26+
for (const auto& token : std::views::split(input, delimiter)) {
27+
collection.emplace_back(&*token.begin(), token.size());
28+
}
29+
}
30+
31+
template <typename T>
32+
concept StringViewCollection =
33+
std::ranges::random_access_range<T> && std::is_same_v<typename T::value_type, std::string_view>;
34+
35+
template <StringViewCollection Coll>
36+
inline void split(Coll& collection, const std::string& input, const std::string& delimiter)
37+
{
38+
for (const auto& token : std::views::split(input, delimiter)) {
39+
collection.emplace_back(&*token.begin(), token.size());
40+
}
41+
}
42+
43+
template <StringCollection Coll> inline std::string join(Coll& collection, const std::string& delimiter)
44+
{
45+
if (collection.empty()) {
46+
return std::string{};
47+
}
48+
return std::accumulate(
49+
std::next(collection.begin()), collection.end(), collection[0],
50+
[&delimiter](const std::string& lhs, const std::string& rhs) { return lhs + delimiter + rhs; });
51+
}
52+
53+
template <typename T>
54+
concept NumericCollection = std::ranges::forward_range<T> && std::is_arithmetic_v<typename T::value_type>;
55+
56+
template <NumericCollection Coll> inline void iota(Coll& collection, typename Coll::value_type initial)
57+
{
58+
std::iota(collection.begin(), collection.end(), initial);
59+
}
60+
61+
inline std::string replace_last_copy(const std::string& input, const std::string& search,
62+
const std::string& replace_with)
63+
{
64+
if (search.empty()) {
65+
return input; // Avoid infinite loops
66+
}
67+
68+
std::string result = input;
69+
std::size_t pos = result.rfind(search);
70+
if (pos != std::string::npos) {
71+
result.replace(pos, search.length(), replace_with);
72+
}
73+
return result;
74+
}
75+
76+
template <NumericCollection Coll> void transform_inplace(Coll& collection, std::function<float(float)> func)
77+
{
78+
std::ranges::copy(std::views::transform(collection, func), collection.begin());
79+
}
80+
81+
template <NumericCollection Coll> void transform(Coll& collection, Coll& out, std::function<float(float)> func)
82+
{
83+
std::ranges::copy(std::views::transform(collection, func), std::back_inserter(out));
84+
}
85+
86+
} // namespace libtokamap

libtokamap/src/utils/indices.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <deque>
66
#include <string>
7+
#include <string_view>
78
#include <ctre/ctre.hpp>
89

910
static constexpr auto indices_re = ctll::fixed_string{ R"(\[(\d+)\])" };
@@ -15,18 +16,18 @@ static constexpr auto indices_re = ctll::fixed_string{ R"(\[(\d+)\])" };
1516
* @return {indices, processed_tokens} pair of the indices vector and tokens
1617
*/
1718
std::pair<std::vector<int>, std::deque<std::string>>
18-
libtokamap::extract_indices(const std::deque<std::string>& path_tokens)
19+
libtokamap::extract_indices(const std::deque<std::string_view>& path_tokens)
1920
{
2021
std::vector<int> indices;
2122
std::deque<std::string> processed_tokens;
2223

2324
for (const auto& token : path_tokens) {
2425
std::string result;
25-
auto last_pos = token.begin();
26+
const auto* last_pos = token.begin();
2627

2728
for (auto match : ctre::search_all<indices_re>(token)) {
28-
auto start = match.get<0>().begin();
29-
auto end = match.get<0>().end();
29+
const auto* start = match.get<0>().begin();
30+
const auto* end = match.get<0>().end();
3031

3132
auto num = match.get<1>().to_string();
3233
indices.push_back(std::stoi(num));

libtokamap/src/utils/indices.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#include <vector>
55
#include <deque>
66
#include <string>
7+
#include <string_view>
78

89
namespace libtokamap {
910

1011
std::pair<std::vector<int>, std::deque<std::string>>
11-
extract_indices(const std::deque<std::string>& path_tokens);
12+
extract_indices(const std::deque<std::string_view>& path_tokens);
1213

1314
} // namespace libtokamap

libtokamap/src/utils/ram_cache.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <boost/range/algorithm/find.hpp>
43
#include <cstdint>
54
#include <cstdlib>
65
#include <ctime>

0 commit comments

Comments
 (0)