diff --git a/src/app_sparkd/sparkd/md/MarketDataListenerID.h b/src/app_sparkd/sparkd/md/MarketDataListenerID.h index 207cf4a66..7f2a10318 100644 --- a/src/app_sparkd/sparkd/md/MarketDataListenerID.h +++ b/src/app_sparkd/sparkd/md/MarketDataListenerID.h @@ -1,13 +1,13 @@ #pragma once #ifndef _WIN32 -#include "spark/core/ValueWrapper.h" #include "system/FMT_IMPL.h" +#include "system/value_wrapper.h" namespace bts::md { using MarketDataListenerID = - core::ValueWrapper; + utils::ValueWrapper; } // namespace bts::md diff --git a/src/app_sparkd/sparkd/md/ccapi/CCApiCorrelationID.h b/src/app_sparkd/sparkd/md/ccapi/CCApiCorrelationID.h index e168bc16d..88def1dfc 100644 --- a/src/app_sparkd/sparkd/md/ccapi/CCApiCorrelationID.h +++ b/src/app_sparkd/sparkd/md/ccapi/CCApiCorrelationID.h @@ -1,9 +1,9 @@ #pragma once -#include "spark/core/StringFinder.h" -#include "spark/core/StringJoiner.h" #include "spark/utils/bts_assert.h" #include "system/FMT_IMPL.h" +#include "system/string_finder.h" +#include "system/string_joiner.h" #include #include diff --git a/src/app_sparkd/sparkd/md/ccapi/CCApiMessageLogger.cpp b/src/app_sparkd/sparkd/md/ccapi/CCApiMessageLogger.cpp index 3fe95665b..da91c3579 100644 --- a/src/app_sparkd/sparkd/md/ccapi/CCApiMessageLogger.cpp +++ b/src/app_sparkd/sparkd/md/ccapi/CCApiMessageLogger.cpp @@ -1,6 +1,5 @@ #include "CCApiMessageLogger.h" -#include "spark/core/StringJoiner.h" -#include "system/time_stamp.h" +#include "system/string_joiner.h" #include #include diff --git a/src/app_sparkd/sparkd/md/ccapi/CCApiTradeRecord.h b/src/app_sparkd/sparkd/md/ccapi/CCApiTradeRecord.h index abbb02696..ac278ba51 100644 --- a/src/app_sparkd/sparkd/md/ccapi/CCApiTradeRecord.h +++ b/src/app_sparkd/sparkd/md/ccapi/CCApiTradeRecord.h @@ -1,8 +1,7 @@ #pragma once -#include "spark/core/NaN.h" - #include +#include #include #include @@ -24,8 +23,8 @@ namespace bts::md { class CCApiTradeRecord { public: bool is_buyer_maker = false; - double last_price = core::NaN::value(); - double last_size = core::NaN::value(); + double last_price = std::numeric_limits::quiet_NaN(); + double last_size = std::numeric_limits::quiet_NaN(); std::uint64_t trade_id = 0; static std::vector parse(const ccapi::Message &source); diff --git a/src/app_sparkd/sparkd/md/ftx/FTXFuture.cpp b/src/app_sparkd/sparkd/md/ftx/FTXFuture.cpp index 9f9878ca6..8be83cddc 100644 --- a/src/app_sparkd/sparkd/md/ftx/FTXFuture.cpp +++ b/src/app_sparkd/sparkd/md/ftx/FTXFuture.cpp @@ -1,11 +1,10 @@ #include "FTXFuture.h" #include "domain/future_security.h" -#include "domain/protobufs/currency.pb.h" #include "domain/protobufs/venue.pb.h" #include "domain/security.h" -#include "spark/core/TableFormatter.h" #include "spark/logging/logging.h" #include "system/json/json_reader.h" +#include "system/table_formatter.h" #include #include @@ -18,7 +17,6 @@ namespace bts::md::ftx { using bts::core::TableFormatter; using bts::domain::FutureSecurity; using bts::domain::Security; -using bts::domain::protobufs::Currency; using bts::io::JsonReader; using std::string; using std::stringstream; diff --git a/src/app_sparkd/sparkd/md/ftx/FTXMarket.cpp b/src/app_sparkd/sparkd/md/ftx/FTXMarket.cpp index ccc7caaa5..875aff60b 100644 --- a/src/app_sparkd/sparkd/md/ftx/FTXMarket.cpp +++ b/src/app_sparkd/sparkd/md/ftx/FTXMarket.cpp @@ -1,16 +1,17 @@ #include "FTXMarket.h" #include "domain/protobufs/venue.pb.h" #include "domain/security.h" -#include "spark/core/NaN.h" -#include "spark/core/TableFormatter.h" #include "spark/logging/logging.h" #include "spark/utils/bts_fatal.h" #include "sparkd/md/ftx/FTXSecurityType.h" #include "system/json/json_reader.h" +#include "system/nan.h" +#include "system/table_formatter.h" #include #include #include +#include #include #include @@ -133,11 +134,11 @@ void from_json(const nlohmann::json &j, FTXMarket &mkt) { jr.read("minProvideSize", mkt.min_provide_size); jr.read("enabled", mkt.enabled); - jr.read_or("ask", mkt.ask, NaN::value()); - jr.read_or("bid", mkt.bid, NaN::value()); - jr.read_or("last", mkt.last, NaN::value()); + jr.read_or("ask", mkt.ask, std::numeric_limits::quiet_NaN()); + jr.read_or("bid", mkt.bid, std::numeric_limits::quiet_NaN()); + jr.read_or("last", mkt.last, std::numeric_limits::quiet_NaN()); jr.read("postOnly", mkt.post_only); - jr.read_or("price", mkt.price, NaN::value()); + jr.read_or("price", mkt.price, std::numeric_limits::quiet_NaN()); jr.read("priceIncrement", mkt.price_increment); jr.read("sizeIncrement", mkt.size_increment); jr.read("restricted", mkt.restricted); diff --git a/src/lib_spark/spark/core/AllSameType.h b/src/lib_spark/spark/core/AllSameType.h deleted file mode 100644 index 46bc52269..000000000 --- a/src/lib_spark/spark/core/AllSameType.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -namespace bts::core { - -template -using AllSameType = - std::enable_if_t...>>; - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/HashPhaser.h b/src/lib_spark/spark/core/HashPhaser.h deleted file mode 100644 index 7d0fd56ef..000000000 --- a/src/lib_spark/spark/core/HashPhaser.h +++ /dev/null @@ -1,224 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace bts::core { - -#ifndef __CHAR_BIT__ -#define __CHAR_BIT__ 8 -#endif - -/** - * Provides facilities to combine multiple hash codes into a single hash code. - * - * @remarks Employs techniques, such as modular arithmetic and bitwise shifts, - * to minimize and evenly distribute information loss to the [multiple] input - * hash codes in the [singular] output hash code. - */ -class HashPhaser { - public: - /** - * Combines the hash codes of several parameters into a single hash code. - * - * @param value One of the parameters whose hash to store - * @param next The other parameters whose hash to store - * - * @remarks A well-chosen modulus of each parameter's hash is stored in - * equally sized blocks of bits. - */ - template - static std::size_t auto_phase(T value, NextT... next); - - /** - * Combines the hash codes of a limited number of elements into a single hash - * code. - * - * @param first Iterator pointing to the first element whose hash to store - * @param last Iterator pointing just after the last element whose hash to - * store - * - * @remarks A well-chosen modulus of each value's hash is stored in equally - * sized blocks of bits - */ - template - static std::size_t auto_phase_range(Iter first, Iter last); - - /** - * Combines the hash codes of a limited number of elements into a single hash - * code. - * - * @param first Iterator pointing to the first element whose hash to store - * @param last Iterator pointing just after the last element whose hash to - * store - * @param hash The hash op to use - * - * @overload - */ - template - static std::size_t auto_phase_range(Iter first, Iter last, Hash hash); - - /** - * Combines the hash codes of several parameters into a single composite hash - * code. - * - * @param value One of the parameters whose hash to store - * @param hash_op The hash code operator to use for the 'value' parameter - * @param next The other parameters whose hash to store - * - * @remarks A well-chosen modulus of each parameter's hash is stored in - * equally sized blocks of bits. - */ - template - static std::size_t custom_phase(T value, HashOp hash_op, NextT... next); - - private: - template - static void _auto_phase( - std::size_t &hash, std::uint16_t &depth, T value, NextT... next); - - template - static void _auto_phase(std::size_t &hash, std::uint16_t &depth, T value); - - template - static void _custom_phase( - std::size_t &hash, std::uint16_t &depth, T value, HashOp, NextT... next); - - template - static void _custom_phase( - std::size_t &hash, std::uint16_t &depth, T value, HashOp); - - /** - * Get the result of std::hash()(value) without having to declare the - * template parameter T explicitly (helpful when using 'auto' variables). - */ - template - static std::size_t _default_hash(T value); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -template -std::size_t HashPhaser::custom_phase(T value, HashOp hash_op, NextT... next) { - std::size_t res = 0; - std::uint16_t depth = 0; - HashPhaser::_custom_phase(res, depth, value, hash_op, next...); - return res; -} - -template -std::size_t HashPhaser::auto_phase(T value, NextT... next) { - std::size_t res = 0; - std::uint16_t depth = 0; - HashPhaser::_auto_phase(res, depth, value, next...); - return res; -} - -template -inline std::size_t HashPhaser::_default_hash(T value) { - return std::hash()(value); -} - -template -std::size_t HashPhaser::auto_phase_range(Iter first, Iter last) { - if (first == last) { - return 0; - } - const std::uint16_t max_els = 8; - auto num_vals = std::distance(first, last); - std::uint16_t el_count = - num_vals > (std::numeric_limits::max)() - ? max_els - : std::max(static_cast(num_vals), max_els); - auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / el_count; - std::size_t phase = 1U << (bits_per_hash - 1); - std::size_t composite_hash = 0; - auto el_rem = el_count; - while (first != last) { - std::size_t val_hash = _default_hash(*first); - composite_hash |= (val_hash % phase) << ((el_count - 1) * bits_per_hash); - if (--el_rem == 0) { - break; - } - } - return composite_hash; -} - -template -std::size_t HashPhaser::auto_phase_range(Iter first, Iter last, Hash hash) { - if (first == last) { - return 0; - } - const std::uint16_t max_els = 8; - auto num_vals = std::distance(first, last); - std::uint16_t el_count = - num_vals > (std::numeric_limits::max)() - ? max_els - : std::max(static_cast(num_vals), max_els); - auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / el_count; - std::size_t phase = 1U << (bits_per_hash - 1); - std::size_t composite_hash = 0; - auto el_rem = el_count; - while (first != last) { - std::size_t val_hash = hash(*first); - composite_hash |= (val_hash % phase) << ((el_count - 1) * bits_per_hash); - if (--el_rem == 0) { - break; - } - } - return composite_hash; -} - -template -void HashPhaser::_auto_phase( - std::size_t &composite_hash, std::uint16_t &depth, T value, NextT... next) { - auto m_depth = depth++; - _auto_phase(composite_hash, depth, next...); - auto val_hash = std::hash()(value); - std::size_t bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth; - std::size_t phase = std::size_t(1) << static_cast(bits_per_hash - 1); - composite_hash |= (val_hash % phase) << (m_depth * bits_per_hash); -} - -template -void HashPhaser::_auto_phase( - std::size_t &composite_hash, std::uint16_t &depth, T value) { - depth++; - std::size_t val_hash = std::hash()(value); - std::size_t bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth; - std::size_t phase = std::size_t(1) << static_cast(bits_per_hash - 1); - composite_hash |= (val_hash % phase) << ((depth - 1) * bits_per_hash); -} - -template -void HashPhaser::_custom_phase( - std::size_t &composite_hash, - std::uint16_t &depth, - T value, - HashOp hash_op, - NextT... next) { - auto m_depth = depth++; - _custom_phase(composite_hash, depth, next...); - auto val_hash = hash_op(value); - auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth; - std::size_t phase = 1U << (bits_per_hash - 1); - composite_hash |= (val_hash % phase) << (m_depth * bits_per_hash); -} - -template -void HashPhaser::_custom_phase( - std::size_t &composite_hash, - std::uint16_t &depth, - T value, - HashOp hash_op) { - depth++; - std::size_t val_hash = hash_op(value); - auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth; - std::size_t phase = 1U << (bits_per_hash - 1); - composite_hash |= (val_hash % phase) << ((depth - 1) * bits_per_hash); -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/LockGuard.h b/src/lib_spark/spark/core/LockGuard.h deleted file mode 100644 index 313618e07..000000000 --- a/src/lib_spark/spark/core/LockGuard.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define LOCK_GUARD(lockable) \ - std::lock_guard __lock_guard_##lockable { lockable } diff --git a/src/lib_spark/spark/core/NaN.h b/src/lib_spark/spark/core/NaN.h deleted file mode 100644 index e9a46102e..000000000 --- a/src/lib_spark/spark/core/NaN.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -namespace bts::core { - -class NaN { - public: - static constexpr double value(); - static constexpr float valuef(); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -constexpr double NaN::value() { - return std::numeric_limits::quiet_NaN(); -} - -constexpr float NaN::valuef() { - return std::numeric_limits::quiet_NaN(); -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/StringContains.h b/src/lib_spark/spark/core/StringContains.h deleted file mode 100644 index 30fae9f7e..000000000 --- a/src/lib_spark/spark/core/StringContains.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once -#include -#include -#include - -namespace bts::core { - -class StringContains { - public: - template - using AllSame = std::enable_if_t...>>; - - template - using AllString = AllSame; - - constexpr bool contains(const std::string &str, const std::string &substr); - constexpr bool contains(const std::string &str, const char *substr); - constexpr bool contains(const char *str, const char *substr); - - template - constexpr bool contains( - const std::string &str, const std::string &substr, Ts... substrs); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -constexpr bool StringContains::contains( - const std::string &str, const std::string &substr) { - return str.find(substr) != std::string::npos; -} - -constexpr bool StringContains::contains( - const std::string &str, const char *substr) { - return str.find(substr) != std::string::npos; -} - -constexpr bool StringContains::contains(const char *str, const char *substr) { - if (str[0] == '\0') { - return false; - } - if (substr[0] == '\0') { - return false; - } - - for (std::size_t i = 0; str[i] != '\0'; i++) { - bool is_match = true; - for (std::size_t j = 0; substr[j] < '\0'; j++) { - if (str[i + j] != substr[j]) { - is_match = false; - break; - } - } - if (is_match) { - return true; - } - } - return false; -} - -template -constexpr bool StringContains::contains( - const std::string &str, const std::string &substr, Ts... substrs) { - return contains(str, substr) || contains(str, substrs...); -} - -#define STRING_CONTAINS(x, ...) (bts::StringContains(x, __VA_ARGS__)) - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/StringFiller.h b/src/lib_spark/spark/core/StringFiller.h deleted file mode 100644 index 58f0c17e0..000000000 --- a/src/lib_spark/spark/core/StringFiller.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -namespace bts::core { - -class StringFiller { - public: - static bool fill_if_empty(std::string &target, const std::string &fill); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -inline bool StringFiller::fill_if_empty( - std::string &target, const std::string &fill) { - if (!target.empty()) { - return false; - } - target = fill; - return true; -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/StringFinder.h b/src/lib_spark/spark/core/StringFinder.h deleted file mode 100644 index 7a709dc11..000000000 --- a/src/lib_spark/spark/core/StringFinder.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include -#include - -namespace bts::core { - -class StringFinder { - public: - static std::size_t find(std::string str, char ch, int occurrence = 1); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -inline std::size_t StringFinder::find( - std::string str, char ch, int occurrence) { - int occur = 0; - - // Loop to find the Nth - // occurrence of the character - for (std::size_t i = 0; i < str.length(); i++) { - if (str[i] == ch) { - occur += 1; - } - if (occur == occurrence) - return i; - } - return std::string::npos; -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/StringJoiner.h b/src/lib_spark/spark/core/StringJoiner.h deleted file mode 100644 index 76a8a1d85..000000000 --- a/src/lib_spark/spark/core/StringJoiner.h +++ /dev/null @@ -1,178 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace bts::core { - -class StringJoiner { - public: - template - static std::ostream &join( - const std::string &delimiter, std::ostream &out, Arg arg); - - template - static std::string join(const std::string &delimiter, Arg arg); - - template - static std::ostream &join( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args); - - template - static std::string join(const std::string &delimiter, Arg arg, Args... args); - - template - static std::ostream &join( - Iter first, Iter last, const std::string &delimiter, std::ostream &out); - - template - static std::string join(Iter first, Iter last, const std::string &delimiter); - - /** - * Converts the args to strings (using the standard output operator), then - * joins the non-empty ones with the specified delimiter. - */ - template - static std::string join_non_empties(const std::string &delimiter, Arg arg); - - /** - * Converts the args to strings (using the standard output operator), then - * joins the non-empty ones with the specified delimiter. - */ - template - static std::string join_non_empties( - const std::string &delimiter, Arg arg, Args... args); - - /** - * Converts the args to strings (using the standard output operator), then - * joins the non-empty ones with the specified delimiter. - */ - template - static std::ostream &join_non_empties( - const std::string &delimiter, std::ostream &out, Arg arg); - - /** - * Converts the args to strings (using the standard output operator), then - * joins the non-empty ones with the specified delimiter. - */ - template - static std::ostream &join_non_empties( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args); - - private: - template - static std::ostream &join_non_empties_( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -template -std::ostream &StringJoiner::join( - const std::string & /*delimiter*/, std::ostream &out, Arg arg) { - // special case for single item (don't use delimiter) - out << arg; - return out; -} - -template -std::string StringJoiner::join(const std::string & /*delimiter*/, Arg arg) { - // special case for single item (don't use delimiter) - std::stringstream out; - out << arg; - return out.str(); -} - -template -std::ostream &StringJoiner::join( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args) { - out << arg << delimiter; - return join(delimiter, out, args...); -} - -template -std::string StringJoiner::join( - const std::string &delimiter, Arg arg, Args... args) { - std::stringstream out; - out << arg << delimiter; - join(delimiter, out, args...); - return out.str(); -} - -template -std::ostream &StringJoiner::join( - Iter it, Iter last, const std::string &delimiter, std::ostream &out) { - if (it == last) { - return out; - } - out << *it; - it++; - for (; it != last; it++) { - out << delimiter << *it; - } - return out; -} - -template -std::string StringJoiner::join( - Iter it, Iter last, const std::string &delimiter) { - std::stringstream out; - join(it, last, delimiter, out); - return out.str(); -} - -template -std::string StringJoiner::join_non_empties( - const std::string & /*delimiter*/, Arg arg) { - std::stringstream ss; - ss << arg; - return ss.str(); -} - -template -std::string StringJoiner::join_non_empties( - const std::string &delimiter, Arg arg, Args... args) { - std::stringstream ss; - std::ostream &out = ss; - join_non_empties(delimiter, out, arg, args...); - return ss.str(); -} - -template -std::ostream &StringJoiner::join_non_empties( - const std::string & /*delimiter*/, std::ostream &out, Arg arg) { - out << arg; - return out; -} - -template -std::ostream &StringJoiner::join_non_empties( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args) { - std::stringstream ss; - ss << arg; - auto arg_str = ss.str(); - if (arg_str.empty()) { - return join_non_empties(delimiter, out, args...); - } - out << arg; - return join_non_empties_(delimiter, out, args...); -} - -template -std::ostream &StringJoiner::join_non_empties_( - const std::string &delimiter, std::ostream &out, Arg arg, Args... args) { - std::stringstream ss; - ss << arg; - auto arg_str = ss.str(); - if (arg_str.empty()) { - return join_non_empties_(delimiter, out, args...); - } - out << delimiter << arg_str; - join(delimiter, out, args...); - return out; -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/TableFormatter.h b/src/lib_spark/spark/core/TableFormatter.h deleted file mode 100644 index eb557feaa..000000000 --- a/src/lib_spark/spark/core/TableFormatter.h +++ /dev/null @@ -1,172 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -namespace bts::core { - -class TableFormatter { - public: - template - using Schema = - std::vector>>; - - template - static std::ostream &format( - std::ostream &out, const Range &range, const Schema &schema); - - template - static std::ostream &format( - std::ostream &out, TIter first, TIter last, const Schema &schema); - - template - static std::ostream &format_record( - std::ostream &out, - const T &record, - const Schema &schema, - bool headers = false); - - template - class SchemaBuilder { - public: - Schema result; - - template - void add(std::string name, GetCell get_cell, int width = 0); - }; -}; - -template -template -inline void TableFormatter::SchemaBuilder::add( - std::string name, GetCell get_cell, int width) { - std::function get_cell_str = [&get_cell](const TRow &r) { - std::stringstream ss; - ss << get_cell(r); - return ss.str(); - }; - result.emplace_back(std::move(name), width, get_cell_str); -} - -template -std::ostream &TableFormatter::format( - std::ostream &out, const Range &range, const Schema &schema) { - return format(out, range.begin(), range.end(), schema); -} - -template -inline std::ostream &TableFormatter::format( - std::ostream &out, - TIter first, - TIter last, - const typename TableFormatter::Schema &schema) { - if (first == last || schema.size() == 0) - return out; - int total_width = 0; - for (auto col : schema) { - total_width += std::get<1>(col); - } - // top border of table - for (int i = 0; i < total_width + static_cast(schema.size()); i++) { - out << "-"; - } - out << std::endl; - // column headers themselves - out << "|"; - for (auto col : schema) { - out << std::setw(std::get<1>(col)) << std::get<0>(col) << "|"; - } - // line between column headers and rows - out << std::endl; - for (int i = 0; i < total_width + static_cast(schema.size()); i++) { - out << "-"; - } - // rows - while (first != last) { - out << std::endl; - out << "|"; - for (uint32_t i = 0; i < schema.size(); i++) { - out << std::setw(std::get<1>(schema[i])) - << std::get<2>(schema[i])(*first) << "|"; - } - first++; - } - // bottom border of table - out << std::endl; - for (int i = 0; i < total_width + static_cast(schema.size()); i++) - out << "-"; - return out; -} - -template -inline std::ostream &TableFormatter::format_record( - std::ostream &out, - const T &record, - const typename TableFormatter::Schema &schema, - bool headers) { - constexpr const char *const field_header = "Field"; - constexpr const char *const value_header = "Value"; - - int ulabel_width = headers ? strlen(field_header) : 0; - for (const auto &field : schema) { - auto label_width = std::get<1>(field); - if (label_width == 0) { - label_width = static_cast(std::get<0>(field).size()); - } - if (label_width > ulabel_width) { - ulabel_width = label_width; - } - } - - std::vector field_vals; - for (const auto &field : schema) { - field_vals.push_back(std::get<2>(field)(record)); - } - - int uvalue_width = headers ? strlen(value_header) : 0; - for (const auto &v : field_vals) { - auto value_width = static_cast(v.size()); - if (value_width > uvalue_width) { - uvalue_width = value_width; - } - } - - int table_width = ulabel_width + uvalue_width + 4; - if (headers) { - // top border of table - for (int i = 0; i < table_width + 3; i++) { - out << "-"; - } - out << std::endl; - // column headers - out << "| " << std::setw(ulabel_width) << field_header << " | " - << std::setw(uvalue_width) << value_header << " |\n"; - } - - // border between col headers and rows (or top border of table, if 'headers' - // is false) - for (int i = 0; i < table_width + 3; i++) { - out << "-"; - } - - // rows - for (std::size_t i = 0; i < field_vals.size(); i++) { - out << "\n"; - const auto &label = std::get<0>(schema.at(i)); - const auto &val = field_vals.at(i); - out << "| " << std::setw(ulabel_width) << label << " | " - << std::setw(uvalue_width) << val << " |"; - } - out << "\n"; - - // bottom border of table - for (int i = 0; i < table_width + 3; i++) { - out << "-"; - } - return out; -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/ValueWrapper.h b/src/lib_spark/spark/core/ValueWrapper.h deleted file mode 100644 index 7fdf00e2a..000000000 --- a/src/lib_spark/spark/core/ValueWrapper.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "system/value_wrapper.h" - -namespace bts::core { - -template -using ValueWrapper = utils::ValueWrapper; - -} // namespace bts::core diff --git a/src/lib_spark/spark/core/VectorAdapter.h b/src/lib_spark/spark/core/VectorAdapter.h deleted file mode 100644 index 481eb4cb3..000000000 --- a/src/lib_spark/spark/core/VectorAdapter.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once -#include -#include - -namespace bts::core { - -class VectorAdapter { - public: - template - static std::vector to(const std::vector &source, Op op); - - template - static std::vector to_const_pointers( - const std::vector &source); - - template - static std::vector copy_values(const std::unordered_map &source); -}; - -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -template -std::vector VectorAdapter::to(const std::vector &source, Op op) { - std::vector result; - result.reserve(source.size()); - for (const auto &value : source) { - result.push_back(op(value)); - } - return result; -} - -template -std::vector VectorAdapter::to_const_pointers( - const std::vector &source) { - std::vector ptrs; - ptrs.reserve(source.size()); - for (const auto &value : source) { - ptrs.push_back(&value); - } - return ptrs; -} - -template -std::vector VectorAdapter::copy_values( - const std::unordered_map &source) { - std::vector values; - values.reserve(source.size()); - for (const auto &p : source) { - values.push_back(p.second); - } - return values; -} - -} // namespace bts::core diff --git a/src/lib_spark/spark/io/URL.h b/src/lib_spark/spark/io/URL.h index 4fdbd8f8a..f9bf8fbed 100644 --- a/src/lib_spark/spark/io/URL.h +++ b/src/lib_spark/spark/io/URL.h @@ -1,6 +1,7 @@ #pragma once #include "QueryParams.h" -#include "spark/core/HashPhaser.h" +#include "system/hash_phaser.h" + #include #include #include diff --git a/src/lib_spark/spark/logging/ccapi_logger.h b/src/lib_spark/spark/logging/ccapi_logger.h index 6b281cd8a..49d78e239 100644 --- a/src/lib_spark/spark/logging/ccapi_logger.h +++ b/src/lib_spark/spark/logging/ccapi_logger.h @@ -1,8 +1,7 @@ -#include "logging.h" - -#include "LoggerHub.h" -#include "spark/core/LockGuard.h" +#include "spark/logging/LoggerHub.h" +#include "spark/logging/logging.h" #include "spark/utils/bts_assert.h" +#include "system/lock_guard.h" #include #include