dxFeed Graal CXX API v8.0.0
Loading...
Searching...
No Matches
Common.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "./Conf.hpp"
7
8#include "./utils/StringUtils.hpp"
9
11
12#ifdef __cpp_lib_bit_cast
13# include <bit>
14#endif
15#include <climits>
16#include <cstring>
17
18#include <charconv>
19#include <chrono>
20#include <cmath>
21#include <string>
22#include <type_traits>
23#include <utility>
24#include <variant>
25
26#include "utils/debug/Debug.hpp"
27
29
30namespace detail {
31template <typename, template <class...> class> struct IsInstanceImpl : std::false_type {};
32
33template <template <class...> class C, typename... Ts> struct IsInstanceImpl<C<Ts...>, C> : std::true_type {};
34} // namespace detail
35
36template <typename T, template <class...> class C> constexpr bool isInstanceOf = detail::IsInstanceImpl<T, C>::value;
37template <typename T, template <class...> class C>
38concept InstanceOf = isInstanceOf<T, C>;
39
40template <typename T>
41concept Integral = std::is_integral_v<T>;
42
43template <typename T>
44concept EnumConcept = std::is_enum_v<T>;
45
46template <class From, class To>
47concept ConvertibleTo = std::is_convertible_v<From, To> && requires { static_cast<To>(std::declval<From>()); };
48
49template <class T, class U>
50concept Derived = std::is_base_of_v<U, T>;
51
52template <class T, class U>
53concept Extends = Derived<T, U>;
54
55template <class T, class U>
56concept BaseOf = Derived<U, T>;
57
58template <typename T>
59concept PairLike = requires(T t) {
60 t.first;
61 t.second;
62};
63
64template <typename T>
65concept MapLike = requires(T t) {
66 { std::begin(t) } -> std::input_iterator;
67 { std::end(t) } -> std::sentinel_for<decltype(std::begin(t))>;
68} && PairLike<std::remove_cvref_t<decltype(*std::begin(std::declval<T &>()))>>;
69
70namespace detail {
71template <typename T>
72struct RemoveAllPointers
73 : std::conditional_t<std::is_pointer_v<T>, RemoveAllPointers<std::remove_pointer_t<T>>, std::type_identity<T>> {};
74} // namespace detail
75
76template <typename T> using RemoveAllPointers = typename detail::RemoveAllPointers<T>::type;
77
78template <class... Ts> struct Overloads : Ts... {
79 using Ts::operator()...;
80};
81
82template <class... Ts> Overloads(Ts...) -> Overloads<Ts...>;
83
84struct DXFeedEventListener {};
85
86struct DXEndpointStateChangeListener {};
87
88struct IpfPropertyChangeListener {};
89
90struct InstrumentProfileUpdateListener {};
91
92template <typename... T> constexpr void ignoreUnused(const T &...) {
93}
94
95constexpr inline auto is_constant_evaluated(bool default_value = false) noexcept -> bool {
96#ifdef __cpp_lib_is_constant_evaluated
97 ignoreUnused(default_value);
98 return std::is_constant_evaluated();
99#else
100 return default_value;
101#endif
102}
103
104// Implementation of std::bit_cast for pre-C++20.
105template <typename To, typename From>
106constexpr To bit_cast(const From &from)
107#if __cpp_concepts
108 requires(sizeof(To) == sizeof(From))
109#endif
110{
111#ifdef __cpp_lib_bit_cast
112 if (is_constant_evaluated())
113 return std::bit_cast<To>(from);
114#endif
115 auto to = To();
116 // The cast suppresses a bogus -Wclass-memaccess on GCC.
117 std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
118 return to;
119}
120
121/// Lightweight implementation of "nullable bool"
122enum class Tristate : std::uint8_t {
123 FALSE = 0,
124 TRUE = 1,
125 NONE = 2,
126};
127
128#define DXFCPP_MACRO_CONCAT(a, b) DXFCPP_MACRO_CONCAT_INNER(a, b)
129#define DXFCPP_MACRO_CONCAT_INNER(a, b) a##b
130#define DXFCPP_MACRO_UNIQUE_NAME(base) DXFCPP_MACRO_CONCAT(base, __LINE__)
131
132namespace detail {
133template <typename Func> struct OnScopeExit {
134 Func func;
135
136 // ReSharper disable once CppNonExplicitConvertingConstructor
137 OnScopeExit(const Func &f) : func(static_cast<Func &&>(f)) { // NOLINT(*-explicit-constructor)
138 }
139
140 // ReSharper disable once CppNonExplicitConvertingConstructor
141 OnScopeExit(Func &&f) : func(f) { // NOLINT(*-explicit-constructor)
142 }
143
144 OnScopeExit(const OnScopeExit &) = delete;
145
146 ~OnScopeExit() {
147 func();
148 }
149};
150} // namespace detail
151
152#define DXFCPP_FINALLY(...) detail::OnScopeExit DXFCPP_MACRO_UNIQUE_NAME(ose__) = __VA_ARGS__
153
154template <typename GraalList, typename ElementWrapper> struct GraalListUtils {
155 static std::ptrdiff_t calculateSize(std::ptrdiff_t initSize) noexcept {
156 using ListType = GraalList;
157 using SizeType = decltype(ListType::size);
158
159 if (initSize < 0) {
160 return 0;
161 }
162
163 if (initSize > std::numeric_limits<SizeType>::max()) {
164 return std::numeric_limits<SizeType>::max();
165 }
166
167 return initSize;
168 }
169
170 static void *newList(std::ptrdiff_t size) {
171 using ListType = GraalList;
172 using SizeType = decltype(ListType::size);
173 using ElementType = std::remove_pointer_t<decltype(ListType::elements)>;
174
175 auto *list = new ListType{static_cast<SizeType>(size), nullptr};
176
177 if (size == 0) {
178 return static_cast<void *>(list);
179 }
180
181 list->elements = new ElementType[size]{nullptr};
182
183 return list;
184 }
185
186 static bool setElement(void *graalList, std::ptrdiff_t elementIdx, void *element) noexcept {
187 using ListType = GraalList;
188 using SizeType = decltype(ListType::size);
189 using ElementType = std::remove_pointer_t<decltype(ListType::elements)>;
190
191 if (graalList == nullptr || elementIdx < 0 || elementIdx >= std::numeric_limits<SizeType>::max() ||
192 element == nullptr) {
193 return false;
194 }
195
196 static_cast<ListType *>(graalList)->elements[elementIdx] = static_cast<ElementType>(element);
197
198 return true;
199 }
200
201 static bool freeElements(void *graalList, std::ptrdiff_t count) {
202 using ListType = GraalList;
203 using SizeType = decltype(ListType::size);
204
205 if (graalList == nullptr || count < 0 || count >= std::numeric_limits<SizeType>::max()) {
206 return false;
207 }
208
209 auto *list = static_cast<ListType *>(graalList);
210
211 for (SizeType i = 0; i < count; i++) {
212 if (list->elements[i]) {
213 ElementWrapper::freeGraal(static_cast<void *>(list->elements[i]));
214 }
215 }
216
217 delete[] list->elements;
218 delete list;
219
220 return true;
221 }
222
223 static void freeList(void *graalList) {
224 using ListType = GraalList;
225 using SizeType = decltype(ListType::size);
226
227 if (graalList == nullptr) {
228 return;
229 }
230
231 auto list = static_cast<ListType *>(graalList);
232
233 if (list->size > 0 && list->elements != nullptr) {
234 for (SizeType elementIndex = 0; elementIndex < list->size; elementIndex++) {
235 if (list->elements[elementIndex]) {
236 ElementWrapper::freeGraal(static_cast<void *>(list->elements[elementIndex]));
237 }
238 }
239
240 delete[] list->elements;
241 }
242
243 delete list;
244 }
245
246 static std::vector<ElementWrapper> fromList(void *graalList) {
247 using ListType = GraalList;
248 using SizeType = decltype(ListType::size);
249
250 if (!graalList) {
251 return {};
252 }
253
254 std::vector<ElementWrapper> result{};
255
256 auto list = static_cast<ListType *>(graalList);
257
258 if (list->size > 0 && list->elements != nullptr) {
259 for (SizeType elementIndex = 0; elementIndex < list->size; elementIndex++) {
260 if (list->elements[elementIndex]) {
261 result.emplace_back(ElementWrapper::fromGraal(static_cast<void *>(list->elements[elementIndex])));
262 }
263 }
264 }
265
266 return result;
267 }
268};
269
270/**
271 * @return The number of milliseconds that have passed since the start of the Unix epoch (1970-01-01).
272 */
273inline auto now() {
274 return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
275 .count();
276}
277
278namespace math {
279static constexpr std::int64_t floorDiv(std::int64_t x, std::int64_t y) {
280 std::int64_t r = x / y;
281
282 // if the signs are different and modulo not zero, round down
283 if ((x < 0) != (y < 0) && (r * y != x)) {
284 r--;
285 }
286
287 return r;
288}
289
290static constexpr std::int64_t floorMod(std::int64_t x, std::int64_t y) {
291 return x - (floorDiv(x, y) * y);
292}
293
294static const double NaN = std::numeric_limits<double>::quiet_NaN();
295
296/**
297 * Compares two double values using Java @c Double.equals semantics.
298 * All NaN values are considered equal, while positive and negative zero are considered different.
299 *
300 * @param a The first value.
301 * @param b The second value.
302 * @return @c true if the values are equal; @c false otherwise.
303 */
304inline bool doubleEquals(double a, double b) noexcept {
305 if (std::isnan(a) || std::isnan(b)) {
306 return std::isnan(a) && std::isnan(b);
307 }
308
309 if (a != b) {
310 return false;
311 }
312
313 return a != 0.0 || std::signbit(a) == std::signbit(b);
314}
315
316/**
317 * Checks whether a double value can be safely converted to @c std::int64_t without losing its fractional part.
318 *
319 * @param value The value to check.
320 * @return @c true if the value is finite, integral, and within the range of @c std::int64_t;
321 * @c false otherwise.
322 */
323inline bool isInt64(double value) noexcept {
324 return std::isfinite(value) && value >= static_cast<double>(std::numeric_limits<std::int64_t>::min()) &&
325 value < -static_cast<double>(std::numeric_limits<std::int64_t>::min()) && value == std::trunc(value);
326}
327
328inline bool equals(double a, double b, double eps = std::numeric_limits<double>::epsilon()) {
329 if (std::isnan(a) || std::isnan(b)) {
330 return false;
331 }
332
333 return std::abs(a - b) < eps;
334}
335
336template <typename T, typename U> static bool equals(T a, U b, double eps = std::numeric_limits<double>::epsilon()) {
337 if (std::isnan(static_cast<double>(a)) || std::isnan(static_cast<double>(b))) {
338 return false;
339 }
340
341 return std::abs(static_cast<double>(a) - static_cast<double>(b)) < eps;
342}
343
344} // namespace math
345
346namespace time_nanos_util {
347static constexpr std::int64_t NANOS_IN_MILLIS = 1'000'000LL;
348
349/**
350 * Returns time measured in nanoseconds since epoch from the time in milliseconds and its nano part.
351 * The result of this method is `timeMillis * 1'000'000 + timeNanoPart`.
352 *
353 * @param timeMillis time in milliseconds since epoch.
354 * @param timeNanoPart nanoseconds part that shall lie within [0..999999] interval.
355 * @return time measured in nanoseconds since epoch.
356 */
357static constexpr std::int64_t getNanosFromMillisAndNanoPart(std::int64_t timeMillis, std::int32_t timeNanoPart) {
358 return (timeMillis * NANOS_IN_MILLIS) + timeNanoPart;
359}
360
361/**
362 * Returns time measured in milliseconds since Java epoch from the time in nanoseconds.
363 * Idea is that nano part of time shall be within [0..999999] interval
364 * so that the following equation always holds
365 * `getMillisFromNanos(timeNanos) * 1'000'000 + getNanoPartFromNanos(timeNanos) == timeNanos`.
366 *
367 * @param timeNanos time measured in nanoseconds since epoch
368 * @return time measured in milliseconds since epoch.
369 * @see ::getNanoPartFromNanos()
370 */
371static constexpr std::int64_t getMillisFromNanos(std::int64_t timeNanos) {
372 return math::floorDiv(timeNanos, NANOS_IN_MILLIS);
373}
374
375/**
376 * Returns nano part of time.
377 * Idea is that nano part of time shall be within [0..999999] interval
378 * so that the following equation always holds
379 * `getMillisFromNanos(timeNanos) * 1'000'000 + getNanoPartFromNanos(timeNanos) == timeNanos`.
380 *
381 * @param timeNanos time measured in nanoseconds since epoch
382 * @return time measured in milliseconds since epoch.
383 * @see ::getMillisFromNanos()
384 */
385static constexpr std::int32_t getNanoPartFromNanos(std::int64_t timeNanos) {
386 return static_cast<std::int32_t>(math::floorMod(timeNanos, NANOS_IN_MILLIS));
387}
388
389} // namespace time_nanos_util
390
391namespace time_util {
392/// Number of milliseconds in a second.
393static constexpr std::int64_t SECOND = 1000LL;
394
395/// Number of milliseconds in a minute.
396static constexpr std::int64_t MINUTE = 60LL * SECOND;
397
398/// Number of milliseconds in an hour.
399static constexpr std::int64_t HOUR = 60LL * MINUTE;
400
401/// Number of milliseconds in an day.
402static constexpr std::int64_t DAY = 24LL * HOUR;
403
404/**
405 * Returns correct number of milliseconds with proper handling negative values.
406 * Idea is that number of milliseconds shall be within [0..999] interval
407 *
408 * @param timeMillis The timestamp in milliseconds
409 * @return a correct number of milliseconds
410 */
411static constexpr std::int32_t getMillisFromTime(std::int64_t timeMillis) {
412 return static_cast<std::int32_t>(math::floorMod(timeMillis, SECOND));
413}
414
415/**
416 * Returns correct number of seconds with proper handling negative values and overflows.
417 * Idea is that number of milliseconds shall be within [0..999] interval
418 *
419 * @param timeMillis The timestamp in milliseconds
420 * @return a correct number of second
421 */
422static constexpr std::int32_t getSecondsFromTime(std::int64_t timeMillis) {
423 if (timeMillis >= 0) {
424 return static_cast<std::int32_t>(
425 std::min(timeMillis / SECOND, static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max())));
426 }
427
428 return static_cast<std::int32_t>(
429 std::max((timeMillis + 1) / SECOND - 1, static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::min())));
430}
431} // namespace time_util
432
433namespace math_util {
434
435/**
436 * Returns quotient according to number theory - i.e. when remainder is zero or positive.
437 *
438 * @tparam T The dividend's and divisor's type
439 * @param a dividend
440 * @param b divisor
441 * @return quotient according to number theory
442 */
443template <Integral T> constexpr static T div(T a, T b) {
444 if (a >= 0) {
445 return a / b;
446 }
447
448 if (b >= 0) {
449 return ((a + 1) / b) - 1;
450 }
451
452 return ((a + 1) / b) + 1;
453}
454
455template <Integral T> constexpr static T abs(T a) {
456 return a < 0 ? -a : a;
457}
458
459} // namespace math_util
460
461namespace day_util {
462
463DXFCXX_DISABLE_GCC_WARNINGS_PUSH("-Wunused-variable")
464static std::int32_t DAY_OF_YEAR[] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
466
467/**
468 * Returns yyyymmdd integer in Gregorian calendar for a specified day identifier.
469 * The day identifier is defined as the number of days since Unix epoch of January 1, 1970.
470 * The result is equal to `yearSign * (abs(year) * 10000 + month * 100 + day)`, where year,
471 * month, and day are in Gregorian calendar, month is between 1 and 12 inclusive, and day is counted from 1.
472 *
473 * @param dayId The day id
474 * @return integer date
475 */
476constexpr static std::int32_t getYearMonthDayByDayId(std::int32_t dayId) {
477 std::int32_t j = dayId + 2472632; // this shifts the epoch back to astronomical year -4800
478 std::int32_t g = math_util::div(j, 146097);
479 std::int32_t dg = j - g * 146097;
480 std::int32_t c = (dg / 36524 + 1) * 3 / 4;
481 std::int32_t dc = dg - c * 36524;
482 std::int32_t b = dc / 1461;
483 std::int32_t db = dc - b * 1461;
484 std::int32_t a = (db / 365 + 1) * 3 / 4;
485 std::int32_t da = db - a * 365;
486 std::int32_t y = g * 400 + c * 100 + b * 4 +
487 a; // this is the integer number of full years elapsed since March 1, 4801 BC at 00:00 UTC
488 std::int32_t m = (da * 5 + 308) / 153 -
489 2; // this is the integer number of full months elapsed since the last March 1 at 00:00 UTC
490 std::int32_t d =
491 da - (m + 4) * 153 / 5 + 122; // this is the number of days elapsed since day 1 of the month at 00:00 UTC
492 std::int32_t yyyy = y - 4800 + (m + 2) / 12;
493 std::int32_t mm = (m + 2) % 12 + 1;
494 std::int32_t dd = d + 1;
495 std::int32_t yyyymmdd = math_util::abs(yyyy) * 10000 + mm * 100 + dd;
496
497 return yyyy >= 0 ? yyyymmdd : -yyyymmdd;
498}
499
500std::int32_t getDayIdByYearMonthDay(std::int32_t year, std::int32_t month, std::int32_t day);
501
502} // namespace day_util
503
504namespace detail {
505template <typename...> struct MaxImpl;
506
507template <typename T> struct MaxImpl<T> {
508 using Type = T;
509};
510
511template <typename T, typename U> struct MaxImpl<T, U> {
512 using Type = std::conditional_t<sizeof(T) >= sizeof(U), T, U>;
513};
514
515template <typename T, typename U, typename V, typename... Ws> struct MaxImpl<T, U, V, Ws...> {
516 using Type = typename MaxImpl<T, typename MaxImpl<U, typename MaxImpl<V, Ws...>::Type>::Type>::Type;
517};
518} // namespace detail
519
520/**
521 * Returns max type by size (first is better)
522 */
523template <typename... Ts> using Max = typename detail::MaxImpl<Ts...>::Type;
524
525/**
526 * Performs a right arithmetic bit shift operation (>> in Java, C, etc). The sign bit is extended to preserve the
527 * signedness of the number.
528 *
529 * The result of the shift will be of the same type as the `value` being shifted.
530 * If the shift is a negative number of bits, then a @ref ::sal() "left arithmetic shift" will be performed.
531 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then if the `value` is
532 * negative (signed integer type), `-1` will be returned, and if positive, then `0` will be returned.
533 *
534 * @tparam V The type of `value`
535 * @tparam S The type of `shift`
536 * @param value The value to be shifted.
537 * @param shift The shift in bits
538 * @return The shifted `value`
539 */
540template <Integral V, Integral S> static constexpr V sar(V value, S shift) noexcept;
541
542/**
543 * Performs a left arithmetic bit shift operation (<< in Java, C, etc).
544 *
545 * The result of the shift will be of the same type as the `value` being shifted.
546 * If the shift is a negative number of bits, then a @ref ::sar() "right arithmetic shift" will be performed.
547 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
548 * returned.
549 *
550 * @tparam V The type of `value`
551 * @tparam S The type of `shift`
552 * @param value The value to be shifted
553 * @param shift The shift in bits
554 * @return The shifted `value`
555 */
556template <Integral V, Integral S> static constexpr V leftArithmeticShift(V value, S shift) noexcept {
557 if constexpr (std::is_signed_v<S>) {
558 if (shift < 0) {
559 return sar(value, -shift);
560 }
561 }
562
563 if (shift == 0 || value == 0) {
564 return value;
565 }
566
567 auto unsignedShift = static_cast<std::make_unsigned_t<S>>(shift);
568
569 if (unsignedShift >= sizeof(V) * CHAR_BIT) {
570 return 0;
571 }
572
573 return value << unsignedShift;
574}
575
576/**
577 * Performs a left arithmetic bit shift operation (<< in Java, C, etc).
578 *
579 * The result of the shift will be of the same type as the `value` being shifted.
580 * If the shift is a negative number of bits, then a @ref ::sar() "right arithmetic shift" will be performed.
581 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
582 * returned.
583 *
584 * @tparam V The type of `value`
585 * @tparam S The type of `shift`
586 * @param value The value to be shifted.
587 * @param shift The shift in bits
588 * @return The shifted `value`
589 */
590template <Integral V, Integral S> static constexpr V sal(V value, S shift) noexcept {
591 return leftArithmeticShift(value, shift);
592}
593
594/**
595 * Performs a right arithmetic bit shift operation (>> in Java, C, etc). The sign bit is extended to preserve the
596 * signedness of the number.
597 *
598 * The result of the shift will be of the same type as the `value` being shifted.
599 * If the shift is a negative number of bits, then a @ref ::sal() "left arithmetic shift" will be performed.
600 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then if the `value` is
601 * negative (signed integer type), `-1` will be returned, and if positive, then `0` will be returned.
602 *
603 * @tparam V The type of `value`
604 * @tparam S The type of `shift`
605 * @param value The value to be shifted
606 * @param shift The shift in bits
607 * @return The shifted `value`
608 */
609template <Integral V, Integral S> static constexpr V rightArithmeticShift(V value, S shift) noexcept {
610 if constexpr (std::is_signed_v<S>) {
611 if (shift < 0) {
612 return sal(value, -shift);
613 }
614 }
615
616 if (shift == 0 || value == 0) {
617 return value;
618 }
619
620 auto unsignedShift = static_cast<std::make_unsigned_t<S>>(shift);
621
622 if (unsignedShift >= sizeof(V) * CHAR_BIT) {
623 return value < 0 ? -1 : 0;
624 }
625
626 return value >> unsignedShift;
627}
628
629/**
630 * Performs a right arithmetic bit shift operation (>> in Java, C, etc). The sign bit is extended to preserve the
631 * signedness of the number.
632 *
633 * The result of the shift will be of the same type as the `value` being shifted.
634 * If the shift is a negative number of bits, then a @ref ::sal() "left arithmetic shift" will be performed.
635 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then if the `value` is
636 * negative (signed integer type), `-1` will be returned, and if positive, then `0` will be returned.
637 *
638 * @tparam V The type of `value`
639 * @tparam S The type of `shift`
640 * @param value The value to be shifted.
641 * @param shift The shift in bits
642 * @return The shifted `value`
643 */
644template <Integral V, Integral S> static constexpr V sar(V value, S shift) noexcept {
645 return rightArithmeticShift(value, shift);
646}
647
648/**
649 * Performs a right logical bit shift operation (>>> in Java). Fills the left bits by zero.
650 *
651 * The result of the shift will be of the same type as the `value` being shifted.
652 * If the shift is a negative number of bits, then a @ref ::shl() "left logical shift" will be performed.
653 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
654 * returned.
655 *
656 * @tparam V The type of `value`
657 * @tparam S The type of `shift`
658 * @param value The value to be shifted.
659 * @param shift The shift in bits
660 * @return The shifted `value`
661 */
662template <Integral V, Integral S> static constexpr V shr(V value, S shift) noexcept;
663
664/**
665 * Performs a left logical bit shift operation.
666 *
667 * The result of the shift will be of the same type as the `value` being shifted.
668 * If the shift is a negative number of bits, then a @ref ::shr() "right logical shift" will be performed.
669 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
670 * returned.
671 *
672 * @tparam V The type of `value`
673 * @tparam S The type of `shift`
674 * @param value The value to be shifted
675 * @param shift The shift in bits
676 * @return The shifted `value`
677 */
678template <Integral V, Integral S> static constexpr V leftLogicalShift(V value, S shift) noexcept {
679 if constexpr (std::is_signed_v<S>) {
680 if (shift < 0) {
681 return shr(value, -shift);
682 }
683 }
684
685 if (shift == 0 || value == 0) {
686 return value;
687 }
688
689 auto unsignedShift = static_cast<std::make_unsigned_t<S>>(shift);
690
691 if (unsignedShift >= sizeof(V) * CHAR_BIT) {
692 return 0;
693 }
694
695 return value << unsignedShift;
696}
697
698/**
699 * Performs a left logical bit shift operation.
700 *
701 * The result of the shift will be of the same type as the `value` being shifted.
702 * If the shift is a negative number of bits, then a @ref ::shr() "right logical shift" will be performed.
703 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
704 * returned.
705 *
706 * @tparam V The type of `value`
707 * @tparam S The type of `shift`
708 * @param value The value to be shifted.
709 * @param shift The shift in bits
710 * @return The shifted `value`
711 */
712template <Integral V, Integral S> static constexpr V shl(V value, S shift) noexcept {
713 return leftLogicalShift(value, shift);
714}
715
716/**
717 * Performs a right logical bit shift operation (>>> in Java). Fills the left bits by zero.
718 *
719 * The result of the shift will be of the same type as the `value` being shifted.
720 * If the shift is a negative number of bits, then a @ref ::shl() "left logical shift" will be performed.
721 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
722 * returned.
723 *
724 * @tparam V The type of `value`
725 * @tparam S The type of `shift`
726 * @param value The value to be shifted
727 * @param shift The shift in bits
728 * @return The shifted `value`
729 */
730template <Integral V, Integral S> static constexpr V rightLogicalShift(V value, S shift) noexcept {
731 if constexpr (std::is_signed_v<S>) {
732 if (shift < 0) {
733 return shl(value, -shift);
734 }
735 }
736
737 if (shift == 0 || value == 0) {
738 return value;
739 }
740
741 auto unsignedShift = static_cast<std::make_unsigned_t<S>>(shift);
742
743 if (unsignedShift >= sizeof(V) * CHAR_BIT) {
744 return 0;
745 }
746
747 return static_cast<V>(static_cast<std::make_unsigned_t<V>>(value) >> unsignedShift);
748}
749
750/**
751 * Performs a right logical bit shift operation (>>> in Java). Fills the left bits by zero.
752 *
753 * The result of the shift will be of the same type as the `value` being shifted.
754 * If the shift is a negative number of bits, then a @ref ::shl() "left logical shift" will be performed.
755 * If the shift size is greater than or equal to the number of bits in the shifted `value`, then `0` will be
756 * returned.
757 *
758 * @tparam V The type of `value`
759 * @tparam S The type of `shift`
760 * @param value The value to be shifted.
761 * @param shift The shift in bits
762 * @return The shifted `value`
763 */
764template <Integral V, Integral S> static constexpr V shr(V value, S shift) noexcept {
765 return rightLogicalShift(value, shift);
766}
767
768template <Integral A, Integral B> static constexpr A andOp(A a, B b) noexcept {
769 using Common = std::make_unsigned_t<Max<A, B>>;
770
771 return static_cast<A>(static_cast<Common>(a) & static_cast<Common>(b));
772}
773
774template <Integral A, Integral B> static constexpr A orOp(A a, B b) noexcept {
775 using Common = std::make_unsigned_t<Max<A, B>>;
776
777 return static_cast<A>(static_cast<Common>(a) | static_cast<Common>(b));
778}
779
780template <Integral A, Integral B> static constexpr A xorOp(A a, B b) noexcept {
781 using Common = std::make_unsigned_t<Max<A, B>>;
782
783 return static_cast<A>(static_cast<Common>(a) ^ static_cast<Common>(b));
784}
785
786template <Integral F, Integral M, Integral S> static constexpr F getBits(F flags, M mask, S shift) noexcept {
787 return static_cast<F>(andOp(shr(flags, shift), mask));
788}
789
790template <Integral T> static constexpr T setBits(T flags, T mask, T shift, T bits) noexcept {
791 if constexpr (std::is_signed_v<T>) {
792 using U = std::make_unsigned_t<T>;
793
794 return static_cast<T>((static_cast<U>(flags) & ~(static_cast<U>(mask) << static_cast<U>(shift))) |
795 ((static_cast<U>(bits) & static_cast<U>(mask)) << static_cast<U>(shift)));
796 } else {
797 return (flags & ~(mask << shift)) | ((bits & mask) << shift);
798 }
799}
800
801template <Integral F, Integral M, Integral S, Integral B>
802static constexpr F setBits(F flags, M mask, S shift, B bits) noexcept {
803 if constexpr (std::is_signed_v<F> || std::is_signed_v<M> || std::is_signed_v<S> || std::is_signed_v<B>) {
804 using U = std::make_unsigned_t<Max<F, M, S, B>>;
805
806 return static_cast<F>((static_cast<U>(flags) & ~(static_cast<U>(mask) << static_cast<U>(shift))) |
807 ((static_cast<U>(bits) & static_cast<U>(mask)) << static_cast<U>(shift)));
808 } else {
809 return (flags & ~(mask << shift)) | ((bits & mask) << shift);
810 }
811}
812
813template <std::size_t Bits> struct hashMixImpl;
814
815template <> struct hashMixImpl<64> {
816 constexpr static std::uint64_t fn(std::uint64_t x) noexcept {
817 std::uint64_t const m = (static_cast<std::uint64_t>(0xe9846af) << 32) + 0x9b1a615d;
818
819 x ^= x >> 32;
820 x *= m;
821 x ^= x >> 32;
822 x *= m;
823 x ^= x >> 28;
824
825 return x;
826 }
827};
828
829template <> struct hashMixImpl<32> {
830 constexpr static std::uint32_t fn(std::uint32_t x) noexcept {
831 std::uint32_t const m1 = 0x21f0aaad;
832 std::uint32_t const m2 = 0x735a2d97;
833
834 x ^= x >> 16;
835 x *= m1;
836 x ^= x >> 15;
837 x *= m2;
838 x ^= x >> 15;
839
840 return x;
841 }
842};
843
844constexpr static std::size_t hashMix(std::size_t v) noexcept {
845 return hashMixImpl<sizeof(std::size_t) * CHAR_BIT>::fn(v);
846}
847
848template <class T> constexpr void hashCombine(std::size_t &seed, const T &v) noexcept {
849 seed = hashMix(seed + 0x9e3779b9 + std::hash<T>()(v));
850}
851
852template <Integral T, Integral U> constexpr std::size_t pack(T t, U u) noexcept {
853 constexpr auto sizeOfSize = sizeof(std::size_t) * CHAR_BIT;
854
855 return orOp(shl(t, sizeOfSize / 2), u);
856}
857
858constexpr std::pair<std::size_t, std::size_t> unpack(std::size_t v) noexcept {
859 constexpr auto sizeOfSize = sizeof(std::size_t) * CHAR_BIT;
860
861 return {shr(v, sizeOfSize / 2), andOp(v, shr(~std::size_t{}, sizeOfSize / 2))};
862}
863
864template <typename T, typename U> T fitToType(const U &size) {
865 static_assert(sizeof(T) <= sizeof(U));
866
867 return static_cast<T>(static_cast<U>(std::numeric_limits<T>::max()) < size ? std::numeric_limits<T>::max() : size);
868}
869
870/**
871 * A simple wrapper around strings or something similar to strings to reduce the amount of code for methods that take
872 * strings as input.
873 */
876
877 private:
878 DataType data_{};
879
880 public:
881 StringLikeWrapperOld(std::string_view sv) : data_{sv} {
882 }
883
884 StringLikeWrapperOld(const char *chars) : data_{chars == nullptr ? std::string_view{} : std::string_view{chars}} {
885 }
886
887 StringLikeWrapperOld(const std::string &s) : data_{s} {
888 }
889
890 StringLikeWrapperOld(std::string &&s) : data_{std::move(s)} {
891 }
892
893 template <auto N>
894 StringLikeWrapperOld(const char (&chars)[N]) : StringLikeWrapperOld{std::string_view{chars, chars + N}} {
895 }
896
897 operator std::string() const {
898 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
899 return {sv->data(), sv->size()};
900 } else {
901 return std::get<std::string>(data_);
902 }
903 }
904
905 operator std::string_view() const & {
906 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
907 return *sv;
908 } else {
909 return std::get<std::string>(data_);
910 }
911 }
912
913 const char *data() const {
914 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
915 return sv->data();
916 } else {
917 return std::get<std::string>(data_).c_str();
918 }
919 }
920
921 const char *c_str() const {
922 return data();
923 }
924
925 bool empty() const {
926 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
927 return sv->empty();
928 } else {
929 return std::get<std::string>(data_).empty();
930 }
931 }
932
933 std::size_t size() const {
934 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
935 return sv->size();
936 } else {
937 return std::get<std::string>(data_).size();
938 }
939 }
940
941 std::size_t length() const {
942 return size();
943 }
944
945 bool ends_with(const StringLikeWrapperOld &sw) const {
946 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
947 return sv->ends_with(sw);
948 } else {
949 return std::get<std::string>(data_).ends_with(sw);
950 }
951 }
952
954 if (auto sv = std::get_if<std::string_view>(&data_); sv) {
955 auto sv2 = sv->substr(pos, count);
956
957 return {sv2.data(), sv2.size()};
958 } else {
959 return std::get<std::string>(data_).substr(pos, count);
960 }
961 }
962
963 bool operator==(const StringLikeWrapperOld &sw) const {
964 return sw.operator std::string_view() == this->operator std::string_view();
965 }
966
968 return sw1.operator std::string() + sw2.operator std::string();
969 }
970
971 explicit operator double() const {
972 double result{};
973
974 // At the moment, clang\apple clang's std lib does not support a version of the `from_chars` function (needed
975 // for `std::string_view`) for the `double` type.
976#ifdef _LIBCPP_VERSION
977 auto s = this->operator std::string();
978
979 result = std::stod(s);
980#else
981 auto sw = this->operator std::string_view();
982
983 std::from_chars(sw.data(), sw.data() + sw.size(), result);
984#endif
985
986 return result;
987 }
988};
989
990namespace util {
991
992void throwInvalidChar(char c, const std::string &name);
993
994inline void checkChar(char c, std::uint32_t mask, const std::string &name) {
995 if ((andOp(c, ~mask)) != 0) {
996 throwInvalidChar(c, name);
997 }
998}
999
1000} // namespace util
1001
1002namespace math {
1003
1004template <Integral Type, typename ResultType = int> ResultType compare(Type v1, Type v2) {
1005 if (v1 < v2) {
1006 return -1;
1007 }
1008
1009 if (v2 < v1) {
1010 return 1;
1011 }
1012
1013 return 0;
1014}
1015
1016inline int compare(double d1, double d2) {
1017 if (std::isnan(d1) || std::isnan(d2)) {
1018 return std::isnan(d1) ? (std::isnan(d2) ? 0 : -1) : 1;
1019 }
1020
1021 if (d1 < d2) {
1022 return -1;
1023 }
1024
1025 if (d1 > d2) {
1026 return 1;
1027 }
1028
1029 return 0;
1030}
1031
1032} // namespace math
1033
1035
#define DXFCPP_MACRO_CONCAT_INNER(a, b)
Definition Common.hpp:129
#define DXFCPP_MACRO_CONCAT(a, b)
Definition Common.hpp:128
#define DXFCPP_MACRO_UNIQUE_NAME(base)
Definition Common.hpp:130
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:31
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:97
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:94
#define DXFCXX_DISABLE_GCC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:47
#define DXFCXX_DISABLE_GCC_WARNINGS_POP()
Definition Conf.hpp:49
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:30
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_name(dxfc_dxendpoint_builder_t builderHandle, const char *name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:692
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_properties(dxfc_dxendpoint_builder_t builder, const dxfc_dxendpoint_property_t **properties, size_t size)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.cpp:725
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:973
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1163
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_supports_property(dxfc_dxendpoint_builder_t builder, const char *key, DXFC_OUT int *supports)
Checks if a property is supported.
Definition DXEndpoint.cpp:752
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_add_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Adds a listener notified about changes in state property.
Definition DXEndpoint.cpp:1109
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1024
#define DXFCPP_EXPORT
Definition api.h:35
void * dxfc_dxendpoint_builder_t
The dxFeed endpoint's builder handle.
Definition api.h:207
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close_and_await_termination(dxfc_dxendpoint_t endpoint)
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:922
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_not_connected(dxfc_dxendpoint_t endpoint)
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:1075
dxfc_dxendpoint_state_t
Represents the current state of endpoint.
Definition api.h:149
@ DXFC_DXENDPOINT_STATE_CLOSED
Endpoint was closed.
Definition api.h:169
@ DXFC_DXENDPOINT_STATE_NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition api.h:153
@ DXFC_DXENDPOINT_STATE_CONNECTING
The connect function was called to establish connection to remove endpoint, but the connection is not...
Definition api.h:159
@ DXFC_DXENDPOINT_STATE_CONNECTED
The connection to the remote endpoint is established.
Definition api.h:164
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of dxFeed endpoint with a FEED role.
Definition DXEndpoint.cpp:811
#define DXFC_OUT
Definition api.h:17
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_state(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_state_t *state)
Returns the state of this endpoint.
Definition DXEndpoint.cpp:1092
void * dxfc_dxendpoint_t
The dxFeed endpoint handle.
Definition api.h:198
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_property(dxfc_dxendpoint_builder_t builder, const char *key, const char *value)
Sets the specified property.
Definition DXEndpoint.cpp:708
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:799
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_connect(dxfc_dxendpoint_t endpoint, const char *address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:990
dxfc_error_code_t
List of error codes.
Definition api.h:49
@ DXFC_EC_ERROR
The error returned if the current operation cannot be completed.
Definition api.h:60
@ DXFC_EC_SUCCESS
OK.
Definition api.h:53
@ DXFC_EC_G_ERR
dxFeed Graal Native API error.
Definition api.h:57
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_remove_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:1135
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_set_property(const char *key, const char *value)
Sets the system property indicated by the specified key.
Definition System.cpp:73
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_build(dxfc_dxendpoint_builder_t builder, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Builds the new dxFeed endpoint instance.
Definition DXEndpoint.cpp:769
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1158
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_processed(dxfc_dxendpoint_t endpoint)
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:1058
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:905
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_new_builder(DXFC_OUT dxfc_dxendpoint_builder_t *builder)
Creates a new dxFeed endpoint's builder instance.
Definition DXEndpoint.cpp:659
void(* dxfc_dxendpoint_state_change_listener)(dxfc_dxendpoint_state_t old_state, dxfc_dxendpoint_state_t new_state, void *user_data)
The endpoint current state change listener.
Definition api.h:178
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_reconnect(dxfc_dxendpoint_t endpoint)
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:1007
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_role(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_role_t *role)
Returns the role of this endpoint.
Definition DXEndpoint.cpp:939
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:956
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_get_property(const char *key, DXFC_OUT char *buffer, size_t buffer_size)
Gets the system property indicated by the specified key.
dxfc_dxendpoint_role_t
Represents the role of an endpoint that was specified during its creation.
Definition api.h:89
@ DXFC_DXENDPOINT_ROLE_PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition api.h:127
@ DXFC_DXENDPOINT_ROLE_STREAM_FEED
STREAM_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED and also connects to the remote data fee...
Definition api.h:116
@ DXFC_DXENDPOINT_ROLE_FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition api.h:99
@ DXFC_DXENDPOINT_ROLE_STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXFC_DXENDPOINT_ROLE_PUBLISHER and also connects to the remot...
Definition api.h:136
@ DXFC_DXENDPOINT_ROLE_LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition api.h:143
@ DXFC_DXENDPOINT_ROLE_ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED, but it is designed to be used with d...
Definition api.h:107
void * dxfc_dxpublisher_t
The dxFeed publisher handle.
Definition api.h:217
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:858
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:834
void * dxfc_dxfeed_t
The dxFeed handle.
Definition api.h:212
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_role(dxfc_dxendpoint_builder_t builder, dxfc_dxendpoint_role_t role)
Sets role for the created dxFeed endpoint.
Definition DXEndpoint.cpp:675
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:881
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1168
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect_and_clear(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:1041
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:850
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:335
std::shared_ptr< Builder > withName(const StringLike &name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:378
bool supportsProperty(const StringLike &key) const
Checks if a property is supported.
Definition DXEndpoint.cpp:325
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:939
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:367
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:297
std::shared_ptr< Builder > withProperty(const StringLike &key, const StringLike &value)
Sets the specified property.
Definition DXEndpoint.cpp:310
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:179
bool isClosed() const
Definition DXEndpoint.cpp:511
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:523
static const std::string DXFEED_PASSWORD_PROPERTY
"dxfeed.password"
Definition DXEndpoint.hpp:246
static std::shared_ptr< DXEndpoint > create(Role role)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:498
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:224
std::shared_ptr< DXEndpoint > password(const StringLike &password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:151
State
Represents the current state of endpoint.
Definition DXEndpoint.hpp:444
@ CLOSED
Endpoint was closed.
Definition DXEndpoint.hpp:464
@ CONNECTING
The connect method was called to establish connection to remove endpoint, but the connection is not e...
Definition DXEndpoint.hpp:454
@ CONNECTED
The connection to the remote endpoint is established.
Definition DXEndpoint.hpp:459
@ NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition DXEndpoint.hpp:448
std::shared_ptr< DXEndpoint > user(const StringLike &user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:144
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:170
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:489
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:519
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:515
Role
Represents the role of an endpoint that was specified during its creation.
Definition DXEndpoint.hpp:373
@ PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition DXEndpoint.hpp:418
@ STREAM_FEED
STREAM_FEED endpoint is similar to DXEndpoint::FEED and also connects to the remote data feed provide...
Definition DXEndpoint.hpp:406
@ LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition DXEndpoint.hpp:434
@ ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXEndpoint::FEED, but it is designed to be used with OnDemandSe...
Definition DXEndpoint.hpp:397
@ STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXEndpoint::PUBLISHER and also connects to the remote publish...
Definition DXEndpoint.hpp:427
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition DXEndpoint.hpp:384
std::string toString() const override
Returns a string representation of the current object.
Definition DXEndpoint.cpp:388
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:206
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:233
static const std::string DXFEED_WILDCARD_ENABLE_PROPERTY
"dxfeed.wildcard.enable"
Definition DXEndpoint.hpp:274
std::size_t addStateChangeListener(std::function< void(State, State)> listener) noexcept
Adds a listener notified about changes in state property.
Definition DXEndpoint.hpp:619
static const std::string DXENDPOINT_EVENT_TIME_PROPERTY
"dxendpoint.eventTime"
Definition DXEndpoint.hpp:319
static const std::string DXPUBLISHER_THREAD_POOL_SIZE_PROPERTY
"dxpublisher.threadPoolSize"
Definition DXEndpoint.hpp:302
State getState() const
Returns the state of this endpoint.
Definition DXEndpoint.cpp:140
static const std::string DXENDPOINT_STORE_EVERYTHING_PROPERTY
"dxendpoint.storeEverything"
Definition DXEndpoint.hpp:332
void awaitNotConnected() const
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:197
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:471
static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:265
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:527
static const std::string DXFEED_THREAD_POOL_SIZE_PROPERTY
"dxfeed.threadPoolSize"
Definition DXEndpoint.hpp:255
void disconnect() const
Terminates all remote network connections.
Definition DXEndpoint.cpp:179
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:215
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:462
static const std::string DXPUBLISHER_ADDRESS_PROPERTY
"dxpublisher.address"
Definition DXEndpoint.hpp:293
static const std::string DXFEED_USER_PROPERTY
"dxfeed.user"
Definition DXEndpoint.hpp:236
static const std::string NAME_PROPERTY
"name"
Definition DXEndpoint.hpp:196
static const std::string DXSCHEME_ENABLED_PROPERTY_PREFIX
"dxscheme.enabled."
Definition DXEndpoint.hpp:366
static const std::string DXPUBLISHER_PROPERTIES_PROPERTY
"dxpublisher.properties"
Definition DXEndpoint.hpp:283
static const std::string DXSCHEME_NANO_TIME_PROPERTY
"dxscheme.nanoTime"
Definition DXEndpoint.hpp:352
static const std::string DXFEED_ADDRESS_PROPERTY
"dxfeed.address"
Definition DXEndpoint.hpp:226
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:188
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:507
static const std::string DXFEED_PROPERTIES_PROPERTY
"dxfeed.properties"
Definition DXEndpoint.hpp:207
static std::shared_ptr< Builder > newBuilder()
Creates a new Builder instance.
Definition DXEndpoint.cpp:480
std::shared_ptr< DXEndpoint > connect(const StringLike &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:158
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:119
Provides API for publishing of events to local or remote DXFeed.
Definition DXPublisher.hpp:60
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:36
std::string toString() const override
Returns a string representation of the current object.
Definition api.cpp:67
virtual std::int64_t getEventTime() const noexcept
Returns time when an event was created or zero when time is not available.
Definition api.cpp:54
virtual void assign(std::shared_ptr< EventType > event)
Replaces the contents of the event.
Definition api.cpp:63
virtual void setEventTime(std::int64_t eventTime) noexcept
Changes event creation time.
Definition api.cpp:58
Provides on-demand historical tick data replay controls.
Definition OnDemandService.hpp:77
A helper class needed to construct smart pointers to objects and does not allow explicit construction...
Definition SharedEntity.hpp:89
static auto createShared(Args &&...args)
Creates a smart pointer to an object.
Definition SharedEntity.hpp:104
A base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:25
virtual std::string toString() const
Returns a string representation of the current object.
Definition SharedEntity.hpp:78
std::shared_ptr< T > sharedAs() const noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nu...
Definition SharedEntity.hpp:69
std::shared_ptr< T > sharedAs() noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nu...
Definition SharedEntity.hpp:58
bool is() const noexcept
Checks that the pointer to the current type could be converted to type T* In other words: whether typ...
Definition SharedEntity.hpp:39
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:874
A lightweight wrapper around strings or string-like inputs.
Definition StringUtils.hpp:27
The simple key-value structure that represents an endpoint's property.
Definition api.h:184
const char * key
The property's key.
Definition api.h:186
const char * value
The property's value.
Definition api.h:188