-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EN-7412] Implement DXFeedConnect sample
- Loading branch information
1 parent
21e5efc
commit 49c77cb
Showing
6 changed files
with
244 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include "../Conf.hpp" | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <locale> | ||
#include <optional> | ||
#include <set> | ||
#include <string> | ||
#include <thread> | ||
#include <type_traits> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace dxfcpp { | ||
|
||
/** | ||
* Utility class for parsing and formatting dates and times in ISO-compatible format. | ||
*/ | ||
struct DXFCPP_EXPORT TimeFormat { | ||
template <typename Entry, std::size_t maxSize = 256> | ||
requires requires(Entry e) { | ||
{ Entry{typename Entry::KeyType{}, typename Entry::ValueType{}} }; | ||
{ Entry::STUB } -> std::convertible_to<Entry>; | ||
{ e.getKey() } -> std::convertible_to<typename Entry::KeyType>; | ||
{ e.getValue() } -> std::convertible_to<typename Entry::ValueType>; | ||
} | ||
class Cache { | ||
std::vector<Entry> data_{maxSize, Entry::STUB}; | ||
|
||
public: | ||
void add(const Entry &entry) noexcept { | ||
auto index = static_cast<std::size_t>(entry.getKey()) % maxSize; | ||
|
||
data_[index] = entry; | ||
} | ||
|
||
void add(const Entry::KeyType &key, const Entry::ValueType &value) { | ||
add({key, value}); | ||
} | ||
|
||
template <typename Key> const Entry &get(const Key &key) const noexcept { | ||
auto index = static_cast<std::size_t>(key) % maxSize; | ||
|
||
if (data_[index].getKey() == key) { | ||
return data_[index]; | ||
} | ||
|
||
return Entry::STUB; | ||
} | ||
|
||
template <typename Key> | ||
std::optional<std::reference_wrapper<const typename Entry::ValueType>> | ||
getEntryValue(const Key &key) const noexcept { | ||
auto index = static_cast<std::size_t>(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<KeyType>::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<KeyType>::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#include <dxfg_api.h> | ||
|
||
#include <dxfeed_graal_c_api/api.h> | ||
#include <dxfeed_graal_cpp_api/api.hpp> | ||
|
||
namespace dxfcpp { | ||
|
||
const TimeFormat::MinuteCacheEntry TimeFormat::MinuteCacheEntry::STUB{}; | ||
const TimeFormat::CacheEntry TimeFormat::CacheEntry::STUB{}; | ||
|
||
} // namespace dxfcpp |