Skip to content

Commit

Permalink
[EN-7164] Add candle events
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Aug 9, 2023
1 parent 5587baa commit 5320558
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ project(dxFeedGraalCxxApi)
set(DXFCXX_VERSION "0.0.0" CACHE STRING "The dxFeed Graal CXX API package version")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CXX_EXTENSIONS OFF)
set(C_EXTENSIONS OFF)

Expand Down
44 changes: 26 additions & 18 deletions include/dxfeed_graal_cpp_api/event/market/MarketEventSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct DXFCPP_EXPORT MarketEventSymbols {
* @param key attribute key.
* @return new symbol without the specified key and everything else from the old symbol.
*/
static constexpr std::string removeAttributeStringByKey(const std::string &symbol,
static DXFCPP_CXX20_CONSTEXPR_STRING std::string removeAttributeStringByKey(const std::string &symbol,
const std::string &key) noexcept {
return removeAttributeInternal(symbol, getLengthWithoutAttributesInternal(symbol), key);
}
Expand All @@ -51,7 +51,7 @@ struct DXFCPP_EXPORT MarketEventSymbols {
static constexpr char ATTRIBUTES_SEPARATOR = ',';
static constexpr char ATTRIBUTE_VALUE = '=';

static constexpr bool hasAttributesInternal(const std::string &symbol) noexcept {
static DXFCPP_CXX20_CONSTEXPR_STRING bool hasAttributesInternal(const std::string &symbol) noexcept {
if (symbol.length() >= 3 /* ATTRIBUTES_OPEN + ATTRIBUTES_CLOSE + ATTRIBUTE */ &&
symbol[symbol.length() - 1] == ATTRIBUTES_CLOSE) {
auto attributesOpenPos = symbol.find_last_of(ATTRIBUTES_OPEN, symbol.length() - 2);
Expand All @@ -62,39 +62,47 @@ struct DXFCPP_EXPORT MarketEventSymbols {
return false;
}

static constexpr std::size_t getLengthWithoutAttributesInternal(const std::string &symbol) noexcept {
static DXFCPP_CXX20_CONSTEXPR_STRING std::size_t getLengthWithoutAttributesInternal(const std::string &symbol) noexcept {
return hasAttributesInternal(symbol) ? symbol.find_last_of(ATTRIBUTES_OPEN) : symbol.length();
}

static constexpr std::optional<std::string> getKeyInternal(const std::string &symbol, std::size_t i) noexcept {
if (auto found = symbol.find_first_of(ATTRIBUTE_VALUE, i); found != std::string::npos) {
return symbol.substr(i, found - i);
}
static DXFCPP_CXX20_CONSTEXPR_STRING std::optional<std::string> getKeyInternal(const std::string &symbol, std::size_t i) noexcept {
try {
if (auto found = symbol.find_first_of(ATTRIBUTE_VALUE, i); found != std::string::npos) {
return symbol.substr(i, found - i);
}

return std::nullopt;
return std::nullopt;
} catch (...) {
return std::nullopt;
}
}

static constexpr std::size_t getNextKeyInternal(const std::string &symbol, std::size_t i) noexcept {
static DXFCPP_CXX20_CONSTEXPR_STRING std::size_t getNextKeyInternal(const std::string &symbol, std::size_t i) noexcept {
auto valuePos = symbol.find_first_of(ATTRIBUTE_VALUE, i) + 1;
auto separatorPos = symbol.find_first_of(ATTRIBUTES_SEPARATOR, valuePos);

return separatorPos == std::string::npos ? symbol.length() : separatorPos + 1;
}

static constexpr std::string dropKeyAndValueInternal(const std::string &symbol, std::size_t length, std::size_t i,
static DXFCPP_CXX20_CONSTEXPR_STRING std::string dropKeyAndValueInternal(const std::string &symbol, std::size_t length, std::size_t i,
std::size_t j) noexcept {
if (j == symbol.length()) {
if (i == length + 1) {
return symbol.substr(0, length);
} else {
return symbol.substr(0, i - 1) + symbol.substr(j - 1);
try {
if (j == symbol.length()) {
if (i == length + 1) {
return symbol.substr(0, length);
} else {
return symbol.substr(0, i - 1) + symbol.substr(j - 1);
}
}
}

return symbol.substr(0, i) + symbol.substr(j);
return symbol.substr(0, i) + symbol.substr(j);
} catch (...) {
return symbol;
}
}

static constexpr std::string removeAttributeInternal(std::string symbol, std::size_t lengthWithoutAttributes,
static DXFCPP_CXX20_CONSTEXPR_STRING std::string removeAttributeInternal(std::string symbol, std::size_t lengthWithoutAttributes,
const std::string &key) noexcept {
if (lengthWithoutAttributes == symbol.length()) {
return symbol;
Expand Down
8 changes: 8 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/Conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@
# define DXFCPP_EXPORT
# define DXFCPP_EXPORT_TEMPLATE_DECLARE
# define DXFCPP_EXPORT_TEMPLATE_DEFINE
#endif

#ifndef DXFCPP_CXX20_CONSTEXPR_STRING
# if defined(__cpp_lib_constexpr_string)
# define DXFCPP_CXX20_CONSTEXPR_STRING constexpr
# else
# define DXFCPP_CXX20_CONSTEXPR_STRING
# endif
#endif
4 changes: 2 additions & 2 deletions include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct DXFCPP_EXPORT String {
inline static const std::string EMPTY{};
};

DXFCPP_EXPORT std::string toString(bool b);
DXFCPP_EXPORT std::string toString(bool b) noexcept;

DXFCPP_EXPORT std::string toString(const char *chars);
DXFCPP_EXPORT std::string toString(const char *chars) noexcept;

DXFCPP_EXPORT std::string toString(std::thread::id theadId);

Expand Down
4 changes: 2 additions & 2 deletions src/internal/utils/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

namespace dxfcpp {

std::string toString(bool b) {
std::string toString(bool b) noexcept {
return b ? "true" : "false";
}

std::string toString(const char *chars) {
std::string toString(const char *chars) noexcept {
if (chars == nullptr) {
return "";
}
Expand Down

0 comments on commit 5320558

Please sign in to comment.