10#ifndef IPCQ_WRITER_HPP_
11#define IPCQ_WRITER_HPP_
68template <
class T,
class ConditionPolicy,
class ShmTraits=detail::BoostInterprocessTraits>
97 std::optional<numapp::MemPolicy>
const& mempolicy = std::nullopt)
98 : m_ctl{topic_name, capacity, mempolicy} {
107 return m_ctl.TopicName();
115 [[nodiscard]]
constexpr size_t Capacity() const noexcept {
116 return m_ctl.Capacity();
124 [[nodiscard]]
constexpr size_t Size() noexcept {
133 [[nodiscard]]
constexpr bool IsClosed() const noexcept {
134 return m_ctl.IsClosed();
151 m_ctl.AtomicStoreState();
165 [[nodiscard]] std::error_code
Write(T
const& data,
Notify notify_readers)
noexcept {
166 return Write(&data, 1, notify_readers);
177 constexpr void Pop() noexcept {
180 m_ctl.AtomicStoreState();
194 [[nodiscard]] std::error_code
195 Write(
const T* data,
size_t count,
Notify notify_readers)
noexcept {
199 size_t num_free =
static_cast<size_t>(m_ctl.Capacity() - m_ctl.Size());
200 if (count > num_free) {
201 int num_to_pop = count - num_free;
202 while (num_to_pop--) {
206 m_ctl.AtomicStoreState();
209 if (
auto err = m_ctl.Push(data, count); err) {
214 m_ctl.AtomicStoreState();
constexpr bool IsClosed() const noexcept
Query whether queue is closed or not.
char const * TopicName() const noexcept
Get queue topic name.
constexpr void Pop() noexcept
Remove single element from queue.
constexpr size_t Capacity() const noexcept
Query queue capacity, which is the number of elements the queue can hold.
constexpr void Close() noexcept
Close queue for further writing.
std::error_code Write(const T *data, size_t count, Notify notify_readers) noexcept
Write count elements to queue.
BasicWriter(char const *topic_name, size_t capacity, std::optional< numapp::MemPolicy > const &mempolicy=std::nullopt)
Creates a writer and allocates shared memory to have room for capacity Ts.
constexpr size_t Size() noexcept
Query number of elements in the queue.
std::error_code Write(T const &data, Notify notify_readers) noexcept
Append single element to queue, possibly overwriting the front element.
static std::error_code RemoveShmObject(char const *topic_name) noexcept
Remove shared memory object from the system.
ShmControl provides the basic data model for the queue and low level operations on the shared memory ...
static std::error_code RemoveShmObject(char const *shm_object_name) noexcept
Attempts to remove shared memory object.
Notify
Notification policy.
BasicWriter< T, BoostConditionPolicy > Writer
Convenience alias with reasonable default condition policy.
@ All
Notify all waiting readers.
std::string MakeShmObjectName(char const *topic_name)
Creates the shared memory object name from topic_name.
Contains core shm implementation details.