dxFeed Graal CXX API v4.2.0
Loading...
Searching...
No Matches
EventType.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "../internal/Conf.hpp"
7
9
10#include <cstdint>
11#include <memory>
12#include <string>
13
14#include "../entity/EntityModule.hpp"
15
17
18/**
19 * Marks all event types that can be received via dxFeed API.
20 * Events are considered instantaneous, non-persistent, and unconflateable
21 * (each event is individually delivered) unless they implement one of interfaces
22 * defined in this package to further refine their meaning.
23 *
24 * <p>Event types are POCO (plain old cpp objects, not POD) that follow bean naming convention with
25 * getters and setters for their properties.
26 * All event types are serializable, because they are transferred over network from publishers to
27 * data feed consumers. However, they are using custom serialization format for this purpose.
28 *
29 * @see DXFeed
30 */
32 /// The alias to a type of shared pointer to the EventType object.
33 using Ptr = std::shared_ptr<EventType>;
34
35 EventType();
36
37 ~EventType() noexcept override;
38
39 /**
40 * Returns time when event was created or zero when time is not available.
41 *
42 * <p>This event time is available only when the corresponding DXEndpoint is created
43 * with @ref DXEndpoint::DXENDPOINT_EVENT_TIME_PROPERTY "DXENDPOINT_EVENT_TIME_PROPERTY" and
44 * the data source has embedded event times. This is typically true only for data events
45 * that are read from historical tape files and from OnDemandService.
46 * Events that are coming from a network connections do not have an embedded event time information and
47 * this method will return zero for them, meaning that event was received just now.
48 *
49 * Default implementation returns 0.
50 *
51 * @return The difference, measured in milliseconds, between the event creation time and
52 * midnight, January 1, 1970 UTC or zero when time is not available.
53 */
54 virtual std::int64_t getEventTime() const noexcept {
55 return 0;
56 }
57
58 /**
59 * Changes event creation time.
60 *
61 * Default implementation does nothing.
62 *
63 * @param eventTime the difference, measured in milliseconds, between the event creation time and
64 * midnight, January 1, 1970 UTC.
65 */
66 virtual void setEventTime(std::int64_t /*eventTime*/) noexcept {
67 // The default implementation is empty
68 };
69
70 /**
71 * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary).
72 * Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary).
73 * Returns the pointer to the filled structure.
74 *
75 * @return The pointer to the filled dxFeed Graal SDK structure
76 */
77 virtual void *toGraal() const = 0;
78
79 /**
80 * Replaces the contents of the event.
81 *
82 * @param event the event to use as source.
83 */
84 virtual void assign(std::shared_ptr<EventType> event) {
85 ignoreUnused(event);
86 }
87
88 ///
89 std::string toString() const override {
90 return "EventType{}";
91 }
92
93 friend std::ostream &operator<<(std::ostream &os, const EventType &e) {
94 return os << e.toString();
95 }
96
97 friend std::ostream &operator<<(std::ostream &os, const std::shared_ptr<EventType> &e) {
98 return os << e->toString();
99 }
100
101 template <typename EntityType>
102 friend std::ostream &operator<<(std::ostream &os, const std::shared_ptr<EntityType> &e)
103#if __cpp_concepts
104 requires(std::is_base_of_v<EventType, EntityType>)
105#endif
106 {
107 return os << e->toString();
108 }
109};
110
111/**
112 * Event type parametrized by a symbol
113 *
114 * @tparam Symbol The type od symbol
115 */
116template <typename Symbol> struct DXFCPP_EXPORT EventTypeWithSymbol : public EventType {
117 /// The alias to a type of shared pointer to the EventTypeWithSymbol's child object.
118 using Ptr = std::shared_ptr<EventTypeWithSymbol<Symbol>>;
119
120 using SymbolType = Symbol;
121
122 /**
123 * Returns event symbol that identifies this event type in @ref DXFeedSubscription "subscription".
124 *
125 * @return The event symbol.
126 */
127 virtual const Symbol &getEventSymbol() const & noexcept = 0;
128
129 /**
130 * Returns event symbol that identifies this event type in @ref DXFeedSubscription "subscription".
131 *
132 * @return The event symbol or std::nullopt.
133 */
134 virtual const std::optional<Symbol> &getEventSymbolOpt() const & noexcept = 0;
135
136 /**
137 * Changes event symbol that identifies this event type in @ref DXFeedSubscription "subscription".
138 *
139 * @param eventSymbol event symbol.
140 */
141 virtual void setEventSymbol(const Symbol &eventSymbol) noexcept = 0;
142};
143
145
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:22
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:70
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:67
#define DXFCXX_DISABLE_GCC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:38
#define DXFCXX_DISABLE_GCC_WARNINGS_POP()
Definition Conf.hpp:40
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:21
#define DXFCPP_TRACE_ISOLATES
Definition Debug.hpp:19
#define DXFCPP_DEBUG
Definition Debug.hpp:15
#define DXFCPP_TRACE_LISTS
Definition Debug.hpp:22
#define DXFCPP_EXPORT
Definition api.h:35
Base abstract class for all dxFeed C++ API entities.
Definition Entity.hpp:13
virtual ~Entity() noexcept=default
The default virtual d-tor.
Event type parametrized by a symbol.
Definition EventType.hpp:116
virtual const std::optional< Symbol > & getEventSymbolOpt() const &noexcept=0
Returns event symbol that identifies this event type in subscription.
virtual void setEventSymbol(const Symbol &eventSymbol) noexcept=0
Changes event symbol that identifies this event type in subscription.
virtual const Symbol & getEventSymbol() const &noexcept=0
Returns event symbol that identifies this event type in subscription.
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:31
std::string toString() const override
Returns a string representation of the current object.
Definition EventType.hpp:89
virtual std::int64_t getEventTime() const noexcept
Returns time when event was created or zero when time is not available.
Definition EventType.hpp:54
virtual void assign(std::shared_ptr< EventType > event)
Replaces the contents of the event.
Definition EventType.hpp:84
virtual void * toGraal() const =0
Allocates memory for the dxFeed Graal SDK structure (recursively if necessary).
virtual void setEventTime(std::int64_t) noexcept
Changes event creation time.
Definition EventType.hpp:66
A helper class needed to construct smart pointers to objects, and does not allow explicit constructio...
Definition SharedEntity.hpp:89
static auto createShared(Args &&...args)
Creates smart pointer to object.
Definition SharedEntity.hpp:103
Base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:21
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.
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.
Definition SharedEntity.hpp:56
bool is() const noexcept
Checks that pointer to the current type could be converted to type T* In other words: whether type T ...
Definition SharedEntity.hpp:35
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition Common.hpp:911
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:794