diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e4d3200..753cda2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ set(dxFeedGraalCxxApi_Internal_Sources set(dxFeedGraalCxxApi_InternalUtils_Sources src/internal/utils/StringUtils.cpp src/internal/utils/EnumUtils.cpp + src/internal/utils/TimeFormat.cpp src/internal/utils/CmdArgsUtils.cpp ) diff --git a/include/dxfeed_graal_cpp_api/api.hpp b/include/dxfeed_graal_cpp_api/api.hpp index efc47a3b..1d4aa441 100644 --- a/include/dxfeed_graal_cpp_api/api.hpp +++ b/include/dxfeed_graal_cpp_api/api.hpp @@ -23,6 +23,7 @@ #include "internal/utils/StringUtils.hpp" #include "internal/utils/CmdArgsUtils.hpp" #include "internal/utils/EnumUtils.hpp" +#include "internal/utils/TimeFormat.hpp" #include "internal/utils/debug/Debug.hpp" #include "api/ApiModule.hpp" diff --git a/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp b/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp new file mode 100644 index 00000000..2f41a1d8 --- /dev/null +++ b/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp @@ -0,0 +1,142 @@ +// Copyright (c) 2023 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "../Conf.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dxfcpp { + +/** + * Utility class for parsing and formatting dates and times in ISO-compatible format. + */ +struct DXFCPP_EXPORT TimeFormat { + template + requires requires(Entry e) { + { Entry{typename Entry::KeyType{}, typename Entry::ValueType{}} }; + { Entry::STUB } -> std::convertible_to; + { e.getKey() } -> std::convertible_to; + { e.getValue() } -> std::convertible_to; + } + class Cache { + std::vector data_{maxSize, Entry::STUB}; + + public: + void add(const Entry &entry) noexcept { + auto index = static_cast(entry.getKey()) % maxSize; + + data_[index] = entry; + } + + void add(const Entry::KeyType &key, const Entry::ValueType &value) { + add({key, value}); + } + + template const Entry &get(const Key &key) const noexcept { + auto index = static_cast(key) % maxSize; + + if (data_[index].getKey() == key) { + return data_[index]; + } + + return Entry::STUB; + } + + template + std::optional> + getEntryValue(const Key &key) const noexcept { + auto index = static_cast(key) % maxSize; + + if (data_[index].getKey() == key) { + return data_[index].getValue(); + } + + return std::nullopt; + } + }; + + private: + struct DXFCPP_EXPORT MinuteCacheEntry { + using KeyType = std::int64_t; + using ValueType = std::string; + + static const MinuteCacheEntry STUB; + + private: + KeyType minute_{}; + ValueType template_{}; + + public: + MinuteCacheEntry(KeyType minute, const ValueType &templat) noexcept : minute_{minute}, template_{templat} { + } + + MinuteCacheEntry() noexcept : MinuteCacheEntry(std::numeric_limits::min(), "") { + } + + KeyType getKey() const noexcept { + return minute_; + } + + const ValueType &getValue() const noexcept { + return template_; + } + + KeyType getMinute() const { + return minute_; + } + + const ValueType &getTemplate() const { + return template_; + } + + bool operator==(const MinuteCacheEntry &minuteCacheEntry) const noexcept { + return minute_ == minuteCacheEntry.minute_ && template_ == minuteCacheEntry.template_; + } + }; + + struct DXFCPP_EXPORT CacheEntry { + using KeyType = std::int64_t; + using ValueType = std::string; + + static const CacheEntry STUB; + + private: + KeyType key_{}; + ValueType value_{}; + + public: + CacheEntry(KeyType key, const ValueType &value) noexcept : key_{key}, value_{value} { + } + + CacheEntry() noexcept : CacheEntry(std::numeric_limits::min(), "") { + } + + KeyType getKey() const noexcept { + return key_; + } + + const ValueType &getValue() const noexcept { + return value_; + } + + bool operator==(const CacheEntry &cacheEntry) const noexcept { + return key_ == cacheEntry.key_ && value_ == cacheEntry.value_; + } + }; + + class Format {}; +}; + +} // namespace dxfcpp \ No newline at end of file diff --git a/samples/cpp/DxFeedConnect/src/main.cpp b/samples/cpp/DxFeedConnect/src/main.cpp index 5397097f..474a83a4 100644 --- a/samples/cpp/DxFeedConnect/src/main.cpp +++ b/samples/cpp/DxFeedConnect/src/main.cpp @@ -13,18 +13,83 @@ using namespace std::literals; void printUsage() { auto usageString = R"( Usage: -DxFeedFileParser +DxFeedConnect
[