dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
AutoClose< T > Class Template Referencefinal

Closes an entity when it goes out of scope: a subscription, an endpoint, a model, an instrument profile connection or any other entity with a close() method. More...

#include <AutoClose.hpp>

Public Member Functions

 AutoClose () noexcept=default
 Creates an empty AutoClose.
 AutoClose (std::shared_ptr< T > entity) noexcept
 Creates an AutoClose that closes the entity.
 AutoClose (AutoClose &&other) noexcept
 Takes the entity of the other AutoClose, which becomes empty.
AutoClose & operator= (AutoClose &&other) noexcept
 Closes the current entity and takes the entity of the other AutoClose, which becomes empty.
 ~AutoClose () noexcept
 Closes the entity.
void reset () noexcept
 Closes the entity now and makes this AutoClose empty.
std::shared_ptr< T > release () noexcept
 Makes this AutoClose empty without closing the entity.
const std::shared_ptr< T > & get () const noexcept
T * operator-> () const noexcept
T & operator* () const noexcept
 operator bool () const noexcept

Detailed Description

template<typename T>
class AutoClose< T >

Closes an entity when it goes out of scope: a subscription, an endpoint, a model, an instrument profile connection or any other entity with a close() method.

See Lifetime of the entities.

The AutoClose is moved, not copied: one AutoClose closes the entity once. The other pointers to the entity stay valid and point to the closed entity. An exception of close() in the destructor or in reset() is reported to ErrorManager.

Do not wrap a default endpoint (DXEndpoint::getInstance()): closing it closes it for the whole process.

const dxfcpp::AutoClose endpoint{dxfcpp::DXEndpoint::create()->connect("demo.dxfeed.com:7300")};
const dxfcpp::AutoClose subscription{endpoint->getFeed()->createSubscription(dxfcpp::Quote::TYPE)};
subscription->addEventListener<dxfcpp::Quote>([&](const auto &quotes) {
// ...
});
subscription->addSymbols("AAPL");
// ...
// Here the subscription is closed first: its listener is not called after the scope. Then the endpoint is closed.
Template Parameters
TThe type of the entity.

Constructor & Destructor Documentation

◆ AutoClose()

template<typename T>
AutoClose< T >::AutoClose ( std::shared_ptr< T > entity)
inlineexplicitnoexcept

Creates an AutoClose that closes the entity.

Parameters
entityThe entity or an empty pointer.

Member Function Documentation

◆ get()

template<typename T>
const std::shared_ptr< T > & AutoClose< T >::get ( ) const
inlinenodiscardnoexcept
Returns
The entity or an empty pointer.

◆ operator bool()

template<typename T>
AutoClose< T >::operator bool ( ) const
inlineexplicitnoexcept
Returns
true if this AutoClose has an entity.

◆ operator*()

template<typename T>
T & AutoClose< T >::operator* ( ) const
inlinenoexcept
Returns
The entity; this AutoClose must not be empty.

◆ operator->()

template<typename T>
T * AutoClose< T >::operator-> ( ) const
inlinenoexcept
Returns
The entity; this AutoClose must not be empty.

◆ release()

template<typename T>
std::shared_ptr< T > AutoClose< T >::release ( )
inlinenodiscardnoexcept

Makes this AutoClose empty without closing the entity.

Returns
The entity or an empty pointer.