-
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.
[DXFC-402] Implement adding multiple symbols and removing symbols
- Loading branch information
AnatolyKalin
committed
May 24, 2023
1 parent
78eca87
commit f0d06fc
Showing
10 changed files
with
194 additions
and
96 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
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,40 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include <atomic> | ||
#include <cstdint> | ||
|
||
namespace dxfcpp { | ||
|
||
template <typename T> struct Id { | ||
using ValueType = std::size_t; | ||
|
||
private: | ||
const ValueType value_{}; | ||
|
||
explicit Id(ValueType value) : value_{value} {} | ||
|
||
public: | ||
static Id<T> getNext() { | ||
static std::atomic<ValueType> value{}; | ||
|
||
return Id<T>{value++}; | ||
} | ||
|
||
[[nodiscard]] ValueType getValue() const { return value_; } | ||
|
||
explicit operator ValueType() const { return value_; } | ||
|
||
static Id<T> from(ValueType value) { return Id<T>{value}; } | ||
|
||
template <typename U> bool operator==(const Id<U> &id) const { return getValue() == id.getValue(); } | ||
|
||
template <typename U> auto operator<=>(const Id<U> &id) const { return getValue() <=> id.getValue(); } | ||
}; | ||
} // namespace dxfcpp | ||
|
||
template <typename T> struct std::hash<dxfcpp::Id<T>> { | ||
std::size_t operator()(const dxfcpp::Id<T> &id) const noexcept { return id.getValue(); } | ||
}; |
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,18 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
namespace dxfcpp { | ||
|
||
template <class T> class NonCopyable { | ||
public: | ||
NonCopyable(const NonCopyable &) = delete; | ||
T &operator=(const T &) = delete; | ||
|
||
protected: | ||
NonCopyable() = default; | ||
~NonCopyable() = default; | ||
}; | ||
|
||
} |
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,56 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <utility> | ||
|
||
namespace dxfcpp { | ||
|
||
struct SymbolList { | ||
template <typename SymbolIt> static std::unique_ptr<SymbolList> create(SymbolIt begin, SymbolIt end) noexcept { | ||
auto size = std::distance(begin, end); | ||
|
||
if (size <= 0) { | ||
return {}; | ||
} | ||
|
||
auto list = create(size); | ||
|
||
if (list->isEmpty()) { | ||
return {}; | ||
} | ||
|
||
std::size_t i = 0; | ||
|
||
for (auto it = begin; it != end; it++, i++) { | ||
list->set(i, *it); | ||
} | ||
|
||
return list; | ||
} | ||
|
||
template <typename Symbol> | ||
void set(std::size_t index, Symbol&& symbol) noexcept; | ||
|
||
[[nodiscard]] bool isEmpty() const noexcept; | ||
|
||
[[nodiscard]] std::size_t size() const noexcept; | ||
|
||
void *getHandler() noexcept; | ||
|
||
~SymbolList() noexcept; | ||
|
||
private: | ||
static std::unique_ptr<SymbolList> create(std::size_t size) noexcept; | ||
|
||
SymbolList() noexcept; | ||
|
||
struct Impl; | ||
|
||
std::unique_ptr<Impl> impl_; | ||
}; | ||
|
||
} |
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,63 @@ | ||
// 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 { | ||
|
||
// TODO: StringSymbol, WildcardSymbol, CandleSymbol, indexed_event_subscription_symbol, time_series_subscription_symbol, | ||
// ::toGraal | ||
|
||
struct SymbolList::Impl | ||
: public RawListWrapper<dxfg_symbol_list, | ||
[]<typename Symbol>(dxfg_symbol_list &list, std::size_t index, Symbol &&symbol) { | ||
dxfg_symbol_t *dxfgSymbol; | ||
|
||
if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) { | ||
dxfg_string_symbol_t s{{STRING}, symbol.c_str()}; | ||
|
||
dxfgSymbol = bit_cast<dxfg_symbol_t *>(&s); | ||
} | ||
#if __cpp_lib_string_view | ||
else if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string_view>) { | ||
dxfg_string_symbol_t s{{STRING}, symbol.data()}; | ||
|
||
dxfgSymbol = bit_cast<dxfg_symbol_t *>(&s); | ||
} | ||
#endif | ||
else { | ||
dxfg_string_symbol_t s{{STRING}, symbol}; | ||
|
||
dxfgSymbol = bit_cast<dxfg_symbol_t *>(&s); | ||
} | ||
|
||
list.elements[index] = dxfgSymbol; | ||
}> { | ||
}; | ||
|
||
SymbolList::SymbolList() noexcept : impl_(std::make_unique<SymbolList::Impl>()) {} | ||
|
||
std::unique_ptr<SymbolList> SymbolList::create(std::size_t size) noexcept { | ||
auto result = std::unique_ptr<SymbolList>(new SymbolList{}); | ||
|
||
result->impl_->init(static_cast<std::uint32_t>(size)); | ||
|
||
return result; | ||
} | ||
|
||
template <typename Symbol> void SymbolList::set(std::size_t index, Symbol &&symbol) noexcept { | ||
impl_->set(index, symbol); | ||
} | ||
|
||
bool SymbolList::isEmpty() const noexcept { return impl_->isEmpty(); } | ||
|
||
std::size_t SymbolList::size() const noexcept { return impl_->size(); } | ||
|
||
void *SymbolList::getHandler() noexcept { return impl_->getHandler(); } | ||
|
||
SymbolList::~SymbolList() noexcept = default; | ||
|
||
} // namespace dxfcpp |