dxFeed Graal CXX API v8.1.0
Loading...
Searching...
No Matches
StringUtils.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "../Conf.hpp"
7
9
10#include <cstdint>
11#include <iterator>
12#include <locale>
13#include <optional>
14#include <ostream>
15#include <string>
16#include <thread>
17#include <type_traits>
18#include <vector>
19
20#if !defined(_LIBCPP_VERSION)
21# include <charconv>
22#endif
23
25
26/// A lightweight wrapper around strings or string-like inputs.
27/// Stores either a view or an owned string but always exposes a valid view.
29 mutable std::string owned_;
30 mutable std::string_view view_;
31
32 StringLike();
33
34 // ReSharper disable once CppNonExplicitConvertingConstructor
35 StringLike(const char *s);
36
37 // ReSharper disable once CppNonExplicitConvertingConstructor
38 StringLike(std::string_view sv);
39
40 // ReSharper disable once CppNonExplicitConvertingConstructor
41 StringLike(const std::string &s);
42
43 // ReSharper disable once CppNonExplicitConvertingConstructor
44 StringLike(std::string &&s) noexcept;
45
46 StringLike(const StringLike &other);
47
48 StringLike(StringLike &&other) noexcept;
49
50 StringLike &operator=(const StringLike &other);
51
52 StringLike &operator=(StringLike &&other) noexcept;
53
54 // ReSharper disable once CppNonExplicitConvertingConstructor
55 template <std::size_t N> StringLike(const char (&arr)[N]) : view_(arr, N - 1) {
56 }
57
58 // ReSharper disable once CppNonExplicitConversionOperator
59 operator std::string_view() const noexcept;
60
61 // ReSharper disable once CppNonExplicitConversionOperator
62 operator std::string() const;
63
64 const char *data() const noexcept;
65
66 const char *c_str() const;
67
68 std::string_view::const_iterator begin() const noexcept;
69
70 std::string_view::const_iterator end() const noexcept;
71
72 std::string_view::const_iterator cbegin() const noexcept;
73
74 std::string_view::const_iterator cend() const noexcept;
75
76 bool empty() const noexcept;
77
78 std::size_t size() const noexcept;
79
80 std::size_t length() const noexcept;
81
82 bool ends_with(const StringLike &other) const noexcept;
83
84 std::string substr(std::size_t pos = 0, std::size_t count = std::string::npos) const;
85
86 bool operator==(const StringLike &other) const noexcept;
87
88 friend std::string operator+(const StringLike &a, const StringLike &b) {
89 std::string result;
90
91 result.reserve(a.size() + b.size());
92 result.append(a.view_);
93 result.append(b.view_);
94
95 return result;
96 }
97
98 explicit operator double() const;
99
100 std::string toString() const noexcept;
101
102 std::string_view toStringView() const noexcept;
103
104 friend std::ostream &operator<<(std::ostream &os, const StringLike &sl) {
105 return os << sl.view_;
106 }
107};
108
110
111template <> struct DXFCPP_EXPORT std::hash<dxfcpp::StringLike> {
112 std::size_t operator()(const dxfcpp::StringLike &sl) const noexcept {
113 return std::hash<std::string_view>{}(std::string_view(sl));
114 }
115};
116
118
119/// Universal functional object that allows searching std::unordered_map for string-like keys.
121 using HashType = std::hash<std::string_view>;
122 using is_transparent = void;
123
124 std::size_t operator()(const char *str) const;
125 std::size_t operator()(std::string_view sv) const;
126 std::size_t operator()(const std::string &str) const;
127 std::size_t operator()(const StringLike &s) const;
128};
129
130/**
131 * Common string constants used across the library.
132 *
133 * `EMPTY` represents an empty string value.
134 * `NUL` is a textual placeholder for a missing or null string value
135 * and is intended for logging, debugging, and diagnostic output.
136 */
138 /// Empty string constant: `""`.
139 inline static const std::string EMPTY{};
140
141 /// Textual representation of a null / missing string: `"<null>"`.
142 inline static const std::string NUL{"<null>"};
143};
144
145DXFCPP_EXPORT std::string toString(bool b) noexcept; // NOLINT(*-redundant-declaration)
146
147DXFCPP_EXPORT std::string toString(const char *chars) noexcept; // NOLINT(*-redundant-declaration)
148
149DXFCPP_EXPORT std::optional<std::string> toStringOpt(const char *chars) noexcept; // NOLINT(*-redundant-declaration)
150
151DXFCPP_EXPORT std::string toString(std::thread::id theadId); // NOLINT(*-redundant-declaration)
152
153DXFCPP_EXPORT std::string toString(void *ptr); // NOLINT(*-redundant-declaration)
154
155DXFCPP_EXPORT std::string toString(double d); // NOLINT(*-redundant-declaration)
156
157// template <typename T> std::string toStringAny(T &&t);
158
159template <typename T, typename U> std::string toString(const std::pair<T, U> &p) {
160 return "{" + toStringAny(p.first) + ", " + toStringAny(p.second) + "}";
161}
162
163#if __cpp_concepts
164template <typename T> std::string toStringAny(T &&t) {
165 if constexpr (requires { t.toString(); }) {
166 return t.toString();
167 } else if constexpr (requires { t->toString(); }) {
168 return t->toString();
169 } else if constexpr (requires { toString(t); }) {
170 return toString(t);
171 } else if constexpr (requires { std::to_string(t); }) {
172 return std::to_string(t);
173 } else if constexpr (requires { std::string(t); }) {
174 return std::string(t);
175 } else {
176 return "unknown";
177 }
178}
179#else
180namespace to_string_any {
181namespace detail {
182template <typename T, typename = void> struct HasToStringMember : std::false_type {};
183
184template <typename T> struct HasToStringMember<T, decltype(std::declval<T>().toString(), void())> : std::true_type {};
185
186template <typename T, typename = void> struct HasToStringMemberByPointer : std::false_type {};
187
188template <typename T>
189struct HasToStringMemberByPointer<T, decltype(std::declval<T>()->toString(), void())> : std::true_type {};
190
191template <typename T, typename = void> struct HasFreeToString : std::false_type {};
192
193template <typename T> struct HasFreeToString<T, decltype(toString(std::declval<T>()), void())> : std::true_type {};
194
195template <typename T, typename = void> struct HasStdToString : std::false_type {};
196
197template <typename T> struct HasStdToString<T, decltype(std::to_string(std::declval<T>()), void())> : std::true_type {};
198
199template <typename T, typename = void> struct IsConvertibleToString : std::false_type {};
200
201template <typename T>
202struct IsConvertibleToString<T, typename std::enable_if<std::is_convertible<T, std::string>::value>::type>
203 : std::true_type {};
204
205} // namespace detail
206} // namespace to_string_any
207
208template <typename T>
209typename std::enable_if<to_string_any::detail::HasToStringMember<T>::value, std::string>::type toStringAny(T &&t) {
210 return t.toString();
211}
212
213template <typename T>
214typename std::enable_if<to_string_any::detail::HasToStringMemberByPointer<T>::value &&
215 !to_string_any::detail::HasToStringMember<T>::value,
216 std::string>::type
217toStringAny(T &&t) {
218 return t->toString();
219}
220
221template <typename T>
222typename std::enable_if<to_string_any::detail::HasFreeToString<T>::value &&
223 !to_string_any::detail::HasToStringMember<T>::value &&
224 !to_string_any::detail::HasToStringMemberByPointer<T>::value,
225 std::string>::type
226toStringAny(T &&t) {
227 return toString(t);
228}
229
230template <typename T>
231typename std::enable_if<to_string_any::detail::HasStdToString<T>::value &&
232 !to_string_any::detail::HasToStringMember<T>::value &&
233 !to_string_any::detail::HasToStringMemberByPointer<T>::value &&
234 !to_string_any::detail::HasFreeToString<T>::value,
235 std::string>::type
236toStringAny(T &&t) {
237 return std::to_string(t);
238}
239
240template <typename T>
241typename std::enable_if<
242 to_string_any::detail::IsConvertibleToString<T>::value && !to_string_any::detail::HasToStringMember<T>::value &&
243 !to_string_any::detail::HasToStringMemberByPointer<T>::value &&
244 !to_string_any::detail::HasFreeToString<T>::value && !to_string_any::detail::HasStdToString<T>::value,
245 std::string>::type
246toStringAny(T &&t) {
247 return std::string(t);
248}
249
250// Fallback case
251template <typename T>
252typename std::enable_if<!to_string_any::detail::HasToStringMember<T>::value &&
253 !to_string_any::detail::HasToStringMemberByPointer<T>::value &&
254 !to_string_any::detail::HasFreeToString<T>::value &&
255 !to_string_any::detail::HasStdToString<T>::value &&
256 !to_string_any::detail::IsConvertibleToString<T>::value,
257 std::string>::type
258toStringAny(T &&) {
259 return "unknown";
260}
261#endif
262
263/**
264 * Tries to convert UTF16 char to ASCII (part of UTF8) char.
265 *
266 * @param in The UTF16 char
267 * @return ASCII char
268 */
269DXFCPP_EXPORT char utf16to8(std::int16_t in) noexcept; // NOLINT(*-redundant-declaration)
270
271/**
272 * Converts UTF16 char to UTF8 string
273 *
274 * @param in The UTF16 char
275 * @return UTF8 string
276 */
277DXFCPP_EXPORT std::string utf16toUtf8String(std::int16_t in) noexcept; // NOLINT(*-redundant-declaration)
278
279/**
280 * Converts UTF16 string to UTF8 string
281 *
282 * @param in The UTF16 string
283 * @return UTF8 string
284 */
285DXFCPP_EXPORT std::string utf16toUtf8String(const std::u16string &in) noexcept; // NOLINT(*-redundant-declaration)
286
287/**
288 * Converts vector of UTF16 chars to UTF8 string
289 *
290 * @param in The UTF16 string
291 * @return UTF8 string
292 */
293DXFCPP_EXPORT std::string
294utf16toUtf8String(const std::vector<std::int16_t> &in) noexcept; // NOLINT(*-redundant-declaration)
295
296/**
297 * Tries to convert ASCII (part of UTF8) char to UTF16 char.
298 *
299 * @param in The ASCII char
300 * @return The UTF16 char
301 */
302DXFCPP_EXPORT std::int16_t utf8to16(char in) noexcept; // NOLINT(*-redundant-declaration)
303
304DXFCPP_EXPORT std::string formatTimeStamp(std::int64_t timestamp); // NOLINT(*-redundant-declaration)
305
306DXFCPP_EXPORT std::string formatTimeStampWithTimeZone(std::int64_t timestamp); // NOLINT(*-redundant-declaration)
307
308DXFCPP_EXPORT std::string formatTimeStampFast(std::int64_t timestamp); // NOLINT(*-redundant-declaration)
309
310DXFCPP_EXPORT std::string formatTimeStampWithMillis(std::int64_t timestamp); // NOLINT(*-redundant-declaration)
311
312DXFCPP_EXPORT std::string
313formatTimeStampWithMillisWithTimeZone(std::int64_t timestamp); // NOLINT(*-redundant-declaration)
314
315DXFCPP_EXPORT char *createCString(const StringLike &s); // NOLINT(*-redundant-declaration)
316
317template <typename S> char *createCString(const std::optional<S> &s) {
318 if (!s) {
319 return nullptr;
320 }
321
322 return createCString(s.value());
323}
324
325template <typename It>
326 requires requires { std::is_same_v<std::decay_t<decltype(It {} -> getName())>, std::string>; }
327std::string namesToString(It begin, It end) {
328 std::string result{"["};
329
330 for (auto it = begin; it != end; ++it) {
331 result += String::EMPTY + "'" + it->getName() + "'" + (std::next(it) == end ? "" : ", ");
332 }
333
334 return result + "]";
335}
336
337template <typename It>
338 requires requires { std::is_same_v<std::decay_t<decltype(It {} -> get().getName())>, std::string>; }
339std::string namesToString(It begin, It end) {
340 std::string result{"["};
341
342 for (auto it = begin; it != end; ++it) {
343 result += String::EMPTY + "'" + it->get().getName() + "'" + (std::next(it) == end ? "" : ", ");
344 }
345
346 return result + "]";
347}
348
349template <typename It>
350std::string elementsToString(It begin, It end, const std::string &prefix = "[", const std::string &postfix = "[",
351 const std::string &separator = ", ") {
352 std::string result{prefix};
353
354 for (auto it = begin; it != end; ++it) {
355 result += String::EMPTY + toStringAny(*it) + (std::next(it) == end ? "" : separator);
356 }
357
358 return result + postfix;
359}
360
361DXFCPP_EXPORT std::string encodeChar(std::int16_t c); // NOLINT(*-redundant-declaration)
362
363inline std::string encodeChar(char c) {
364 return encodeChar(static_cast<std::int16_t>(static_cast<unsigned char>(c)));
365}
366
367namespace detail {
368
369class IsIEqual {
370 std::locale locale_;
371
372 public:
373 explicit IsIEqual(const std::locale &locale = std::locale());
374
375 template <typename T, typename U> bool operator()(const T &t, const U &u) const {
376 return std::tolower<T>(t, locale_) == std::tolower<U>(u, locale_);
377 }
378};
379
380} // namespace detail
381
382template <typename Range1, typename Range2, typename Predicate>
383bool equals(const Range1 &first, const Range2 &second, Predicate cmp) {
384 auto firstIt = std::begin(first);
385 auto secondIt = std::begin(second);
386
387 for (; firstIt != std::end(first) && secondIt != std::end(second); ++firstIt, ++secondIt) {
388 if (!cmp(*firstIt, *secondIt)) {
389 return false;
390 }
391 }
392
393 return (secondIt == std::end(second)) && (firstIt == std::end(first));
394}
395
396DXFCPP_EXPORT inline bool iEquals(const StringLike &first, const StringLike &second) noexcept {
397 const auto &locale = std::locale();
398
399 return equals(first, second, detail::IsIEqual(locale));
400}
401
402DXFCPP_EXPORT inline std::size_t icHash(const StringLike &s) noexcept {
403 const auto &locale = std::locale();
404 std::string result{};
405
406 for (auto c : s) {
407 result += std::tolower(c, locale);
408 }
409
410 return std::hash<std::string>()(result);
411}
412
413DXFCPP_EXPORT std::string trimStr(const StringLike &s) noexcept; // NOLINT(*-redundant-declaration)
414
415DXFCPP_EXPORT std::vector<std::string> splitStr(const StringLike &s, char sep = ',') noexcept;
416
417DXFCPP_EXPORT std::string joinStr(const std::vector<StringLike> &v, const StringLike &sep = ", ") noexcept;
418
419DXFCPP_EXPORT bool toBool(const StringLike &s) noexcept; // NOLINT(*-redundant-declaration)
420
422
#define DXFCPP_MACRO_CONCAT_INNER(a, b)
Definition Common.hpp:135
#define DXFCPP_MACRO_CONCAT(a, b)
Definition Common.hpp:134
#define DXFCPP_MACRO_UNIQUE_NAME(base)
Definition Common.hpp:136
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:31
#define DXFCXX_DISABLE_CLANG_WARNINGS_PUSH(warnings)
Definition Conf.hpp:65
#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_CLANG_WARNINGS_POP()
Definition Conf.hpp:67
#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:721
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:754
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:1002
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1192
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:781
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:1138
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1053
#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:951
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:1104
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:840
#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:1121
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:737
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:828
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:1019
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:1164
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:74
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:798
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1187
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:1087
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:934
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:688
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:1036
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:968
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:985
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:887
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:863
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:704
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:910
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1197
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:1070
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:866
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:348
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:391
std::shared_ptr< Builder > withExecutor(const std::shared_ptr< Executor > &executor)
Sets the executor that is used for notifications (events, state changes, etc.) of the endpoint to bui...
Definition DXEndpoint.hpp:995
bool supportsProperty(const StringLike &key) const
Checks if a property is supported.
Definition DXEndpoint.cpp:338
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:957
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:380
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:300
std::shared_ptr< Builder > withProperty(const StringLike &key, const StringLike &value)
Sets the specified property.
Definition DXEndpoint.cpp:313
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:179
bool isClosed() const
Definition DXEndpoint.cpp:540
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:552
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:527
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:227
std::shared_ptr< DXEndpoint > password(const StringLike &password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:154
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:147
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:173
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:518
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:548
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:544
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:401
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:209
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:236
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:143
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:200
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:500
static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:265
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:556
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:182
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:218
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:491
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
std::shared_ptr< DXEndpoint > executor(const std::shared_ptr< Executor > &executor)
Changes the executor that is used for notifications (events, state changes, etc.) of this endpoint.
Definition DXEndpoint.hpp:655
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:191
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:536
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:509
std::shared_ptr< DXEndpoint > connect(const StringLike &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:161
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:141
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:37
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
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
Definition InvalidArgumentException.hpp:23
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 runtime axception with stacktrace.
Definition RuntimeException.hpp:26
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
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition StringUtils.hpp:120
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:728
A lightweight wrapper around strings or string-like inputs.
Definition StringUtils.hpp:28
Common string constants used across the library.
Definition StringUtils.hpp:137
static const std::string NUL
Textual representation of a null / missing string: "<null>".
Definition StringUtils.hpp:142
static const std::string EMPTY
Empty string constant: "".
Definition StringUtils.hpp:139
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