Skip to content

Commit

Permalink
[EN-7490] Implement Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ttldtor committed Sep 16, 2023
1 parent 79642d7 commit 1b150c1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 18 deletions.
47 changes: 36 additions & 11 deletions include/dxfeed_graal_cpp_api/internal/utils/CmdArgsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,57 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of symbols.
*
* If the result type is SymbolWrapper, then the symbol "all" or "*" can be passed. This will add WildcardSymbol
* (all symbols).
*
* @tparam R The result type (std::string, SymbolWrapper, CandleSymbol)
* @param symbols The coma-separated list of symbols.
* @return The created set of parsed symbols.
* @return The created set of parsed symbols
*/
static std::unordered_set<std::string> parseSymbols(const std::string &symbols) noexcept;
template <typename R = std::string> static std::unordered_set<R> parseSymbols(const std::string &symbols) noexcept;

/**
* Parses an input string and returns a set of symbols.
*
* If the result type is SymbolWrapper, then the symbol "all" or "*" can be passed. This will add WildcardSymbol
* (all symbols).
*
* @tparam R The result type (std::string, SymbolWrapper, CandleSymbol)
* @param symbols The coma-separated list of symbols.
* @return The created set of parsed symbols.
* @return The created set of parsed symbols
*/
static std::unordered_set<std::string> parseSymbols(const char *symbols) noexcept {
return parseSymbols(std::string(symbols));
template <typename R = std::string> static std::unordered_set<R> parseSymbols(const char *symbols) noexcept {
return parseSymbols<R>(std::string(symbols));
}

/**
* Parses an input string and returns a set of symbols.
*
* If the result type is SymbolWrapper, then the symbol "all" or "*" can be passed. This will add WildcardSymbol
* (all symbols).
*
* @tparam R The result type (std::string, SymbolWrapper, CandleSymbol)
* @param symbols The coma-separated list of symbols.
* @return The created set of parsed symbols.
* @return The created set of parsed symbols
*/
static std::unordered_set<std::string> parseSymbols(std::string_view symbols) noexcept {
return parseSymbols(symbols.data());
template <typename R = std::string> static std::unordered_set<R> parseSymbols(std::string_view symbols) noexcept {
return parseSymbols<R>(symbols.data());
}

/**
* Parses an input string and returns a set of symbols.
*
* If the result type is SymbolWrapper, then the symbol "all" or "*" can be passed. This will add WildcardSymbol
* (all symbols).
*
* @tparam R The result type (std::string, SymbolWrapper, CandleSymbol)
* @param symbols The coma-separated list of symbols.
* @return The created set of parsed symbols.
* @return The created set of parsed symbols
*/
static std::unordered_set<std::string> parseSymbols(std::optional<std::string> symbols) noexcept {
template <typename R = std::string>
static std::unordered_set<R> parseSymbols(std::optional<std::string> symbols) noexcept {
if (symbols.has_value()) {
return parseSymbols(symbols.value());
return parseSymbols<R>(symbols.value());
}

return {};
Expand All @@ -62,6 +79,8 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of event types.
*
* "all" or "*" will be converted to all types.
*
* @param types The comma-separated list of event types.
* @return The created set of parsed types.
*/
Expand All @@ -71,6 +90,8 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of event types.
*
* "all" or "*" will be converted to all types.
*
* @param types The comma-separated list of event types.
* @return The created set of parsed types.
*/
Expand All @@ -81,6 +102,8 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of event types.
*
* "all" or "*" will be converted to all types.
*
* @param types The comma-separated list of event types.
* @return The created set of parsed types.
*/
Expand All @@ -91,6 +114,8 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of event types.
*
* "all" or "*" will be converted to all types.
*
* @param types The comma-separated list of event types.
* @return The created set of parsed types.
*/
Expand Down
39 changes: 35 additions & 4 deletions src/internal/utils/CmdArgsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ decltype(ranges::views::transform([](auto &&s) {
ranges::to<std::string>();
})) transformToUpper{};

std::unordered_set<std::string> CmdArgsUtils::parseSymbols(const std::string &symbols) noexcept {
if (symbols.empty()) {
template <> std::unordered_set<std::string> CmdArgsUtils::parseSymbols(const std::string &symbols) noexcept {
auto trimmedSymbols = trimStr(symbols);

if (trimmedSymbols.empty()) {
return {};
}

Expand Down Expand Up @@ -119,13 +121,42 @@ std::unordered_set<std::string> CmdArgsUtils::parseSymbols(const std::string &sy
return result;
}

template <> std::unordered_set<SymbolWrapper> CmdArgsUtils::parseSymbols(const std::string &symbols) noexcept {
auto trimmedSymbols = trimStr(symbols);

if (trimmedSymbols.empty()) {
return {};
}

if (trimmedSymbols == "*" || iEquals(trimmedSymbols, "all")) {
return {WildcardSymbol::ALL};
}

return parseSymbols(trimmedSymbols) | ranges::to<std::unordered_set<SymbolWrapper>>();
}

template <> std::unordered_set<CandleSymbol> CmdArgsUtils::parseSymbols(const std::string &symbols) noexcept {
auto parsed = parseSymbols(symbols);

return parsed | ranges::views::transform([](auto &&s) {
return CandleSymbol::valueOf(s);
}) |
ranges::to<std::unordered_set<CandleSymbol>>();
}

std::unordered_set<std::reference_wrapper<const EventTypeEnum>>
CmdArgsUtils::parseTypes(const std::string &types) noexcept {
if (types.empty()) {
auto trimmedTypes = trimStr(types);

if (trimmedTypes.empty()) {
return {};
}

auto split = splitAndTrim(types) | filterNonEmpty;
if (trimmedTypes == "*" || iEquals(trimmedTypes, "all")) {
return EventTypeEnum::ALL | ranges::to<std::unordered_set<std::reference_wrapper<const EventTypeEnum>>>();
}

auto split = splitAndTrim(trimmedTypes) | filterNonEmpty;
auto allByName = split | transformToUpper | ranges::views::filter([](const auto &s) {
return EventTypeEnum::ALL_BY_NAME.contains(s);
}) |
Expand Down
6 changes: 3 additions & 3 deletions tools/Tools/src/Connect/ConnectTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ struct ConnectTool {

struct Args {
std::string address;
std::optional<std::string> types;
std::optional<std::string> symbols;
std::string types;
std::string symbols;
std::optional<std::string> fromTime;
std::optional<std::string> source;
std::optional<std::string> properties;
std::optional<std::string> tape;
bool isQuite;
std::optional<bool> isQuite;

static Args parse(const std::vector<std::string> &args) noexcept {
return {};
Expand Down

0 comments on commit 1b150c1

Please sign in to comment.