refactor: Add lib_system proj for common utils
Migrates the following: * Delegate.h * bts_array_size.h * string_utils.h Note: File names in the new lib are snake_case (this seems to be the standard naming convention for c++).
This commit is contained in:
1 parent
427974f9cb
commit
b58be00de0
28 files changed
+151
-23
No files matched your search
@@ -104,6 +104,7 @@ else()
|
||||
|
||||
# subdirs
|
||||
if (BUILD_SPARKD)
|
||||
add_subdirectory(src/lib_system)
|
||||
add_subdirectory(src/app_sparkd)
|
||||
add_subdirectory(src/data_files)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "sparkd/md/ccapi/CCApiCorrelationID.h"
|
||||
#include "sparkd/md/ccapi/ICCApiMessageHandler.h"
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <ccapi_cpp/ccapi_event.h>
|
||||
#include <ccapi_cpp/ccapi_message.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "sparkd/md/ccapi/CCApiCorrelationID.h"
|
||||
#include "sparkd/md/ccapi/ICCApiMessageHandler.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "sparkd/md/ccapi/ICCApiMessageHandler.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <string>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "sparkd/md/ccapi/CCApiCorrelationID.h"
|
||||
#include "sparkd/md/ccapi/ICCApiMessageHandler.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function(get_link_libraries dest)
|
||||
set(${dest}
|
||||
system
|
||||
protobuf
|
||||
double-conversion
|
||||
boost_system
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include "spark/core/FMT.h"
|
||||
#include "spark/io/ProtoPrinter.h"
|
||||
#include "spark/os/os.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/defer.h"
|
||||
#include "spark/utils/is_unittest_environment.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
|
||||
@@ -113,7 +113,7 @@ string ConfigurationState::settings_path() {
|
||||
|
||||
void ConfigurationState::initialize_defaults(ConfigLog &log) {
|
||||
initialize_defaults(
|
||||
log, {"lib/config/protos/", "lib/api/domain/", "lib/api/md/"});
|
||||
log, {"spark/config/protos/", "spark/api/domain/", "spark/api/md/"});
|
||||
}
|
||||
|
||||
void ConfigurationState::initialize_defaults(
|
||||
@@ -226,8 +226,15 @@ void ConfigurationState::initialize_builtins(ConfigLog *log) {
|
||||
|
||||
//
|
||||
// Add the System value to the defaults
|
||||
const proto::Descriptor *defaults_desc = _defaults->GetDescriptor();
|
||||
bts_assert_msg(
|
||||
defaults_desc != nullptr,
|
||||
"Failed to get descriptor for config defaults");
|
||||
const proto::FieldDescriptor *field_desc =
|
||||
_defaults->GetDescriptor()->FindFieldByName("SystemConfig");
|
||||
defaults_desc->FindFieldByName("SystemConfig");
|
||||
bts_assert_msg(
|
||||
field_desc != nullptr,
|
||||
"Failed to get descriptor for config defaults field SystemConfig");
|
||||
const proto::Descriptor *message_desc = field_desc->message_type();
|
||||
|
||||
// Create a meta message
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "spark/io/websocket/JsonRpcError.h"
|
||||
#include "spark/io/websocket/JsonRpcRequest.h"
|
||||
#include "spark/io/websocket/JsonRpcResponse.h"
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "spark/io/websocket/JsonRpcError.h"
|
||||
#include "spark/io/websocket/JsonRpcRequest.h"
|
||||
#include "spark/io/websocket/JsonRpcResponse.h"
|
||||
#include "spark/utils/Delegate.h"
|
||||
#include "system/delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "spark/os/os.h"
|
||||
#include "spark/utils/Optimistic.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "spark/utils/warn_ctrl.h"
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
#include "spark/io/JsonDumper.h"
|
||||
#include "spark/io/JsonReader.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_export.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "spark/utils/warn_ctrl.h"
|
||||
#include "spark/domain_model/SecurityKey.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/os/app_data_dir.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_debugger.h"
|
||||
#include "spark/utils/helper_macros.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "spark/config/protos/perflog_cfg.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/persistence/persistence_utils.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "spark/utils/stats.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/utils/SharedMemory.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "spark/utils/defer.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "Uuid.h"
|
||||
|
||||
#include "bts_array_size.h"
|
||||
#include "bts_assert.h"
|
||||
#include "spark/os/os.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "bts_array_size.h"
|
||||
#include "bts_export.h"
|
||||
#include "system/bts_array_size.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(system)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/InstallBasic.cmake)
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
install_basic()
|
||||
@@ -0,0 +1,5 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
check_required_components(@PROJECT_NAME@)
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,108 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::system::string_utils {
|
||||
|
||||
void snake_to_pascal_case(std::string &str);
|
||||
|
||||
template <class Range>
|
||||
std::vector<std::string> split(Range range, const std::string &delimiter);
|
||||
|
||||
template <class Iterator>
|
||||
std::vector<std::string> split(
|
||||
Iterator first, Iterator last, const std::string &delimiter);
|
||||
|
||||
template <class Iterator>
|
||||
void split(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
const std::string &delimiter,
|
||||
std::vector<std::string> &parts);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
inline void snake_to_pascal_case(std::string &str) {
|
||||
std::size_t n = 0;
|
||||
// Remove leading '_'
|
||||
while (!str.empty() && str[0] == '_') {
|
||||
n++;
|
||||
}
|
||||
if (n > 0) {
|
||||
str.erase(0, n);
|
||||
}
|
||||
std::size_t pos = 0;
|
||||
// Remove middle '_' (word delimiter), capitalize first letter of words
|
||||
for (n = 0; n < str.size();) {
|
||||
str[n] = toupper(str[n]);
|
||||
pos = ++n;
|
||||
while (n < str.size() && str[n] == '_') {
|
||||
n++;
|
||||
}
|
||||
if (n > pos) {
|
||||
str.erase(pos, n - pos);
|
||||
}
|
||||
}
|
||||
// Remove trailing '_'
|
||||
while (!str.empty() && str.back() == '_') {
|
||||
n++;
|
||||
}
|
||||
if (n > 0) {
|
||||
str.erase(str.size() - n);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Range>
|
||||
std::vector<std::string> split(Range range, const std::string &delimiter) {
|
||||
std::vector<std::string> parts;
|
||||
split(range.begin(), range.end(), delimiter, parts);
|
||||
return parts;
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
std::vector<std::string> split(
|
||||
Iterator first, Iterator last, const std::string &delimiter) {
|
||||
std::vector<std::string> parts;
|
||||
split(first, last, delimiter, parts);
|
||||
return parts;
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
void split(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
const std::string &delimiter,
|
||||
std::vector<std::string> &parts) {
|
||||
|
||||
auto cursor = first;
|
||||
auto curr_end = first;
|
||||
auto curr_start = first;
|
||||
|
||||
auto find_delim = [&cursor, &delimiter, &last]() {
|
||||
for (auto it = cursor; it != last; it++) {
|
||||
if (*it == delimiter[0]) {
|
||||
if (std::equal(
|
||||
it + 1, it + delimiter.size(), delimiter.begin() + 1,
|
||||
delimiter.end())) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
}
|
||||
return last;
|
||||
};
|
||||
|
||||
while ((curr_end = find_delim()) != last) {
|
||||
parts.push_back(std::string(curr_start, curr_end));
|
||||
curr_start = curr_end + delimiter.size();
|
||||
cursor = curr_end + delimiter.size();
|
||||
}
|
||||
if (cursor != last) {
|
||||
parts.push_back(std::string(cursor, last));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bts::system::string_utils
|
||||
Reference in new issue
Block a user