CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
shared_memory.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_SYSTEM_SHARED_MEMORY_H
10#define CPPCOMMON_SYSTEM_SHARED_MEMORY_H
11
12#include "errors/exceptions.h"
13
14#include <memory>
15#include <string>
16
17namespace CppCommon {
18
20
29{
30public:
32
36 explicit SharedMemory(const std::string& name, size_t size);
37 SharedMemory(const SharedMemory&) = delete;
38 SharedMemory(SharedMemory&& shmem) = delete;
40
43
45 explicit operator bool() const { return (ptr() != nullptr); }
46
48 const std::string& name() const noexcept { return _name; }
50 size_t size() const noexcept { return _size; }
51
53 void* ptr();
55 const void* ptr() const;
56
58 bool owner() const;
59
60private:
61 class Impl;
62
63 Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
64 const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
65
66 static const size_t StorageSize = 64;
67 static const size_t StorageAlign = 8;
68 alignas(StorageAlign) std::byte _storage[StorageSize];
69
70 std::string _name;
71 size_t _size;
72};
73
76} // namespace CppCommon
77
78#endif // CPPCOMMON_SYSTEM_SHARED_MEMORY_H
Shared memory manager.
void * ptr()
Get the shared memory block pointer.
bool owner() const
Get the shared memory owner flag (true if the new one was created, false if the existing one was open...
SharedMemory & operator=(SharedMemory &&shmem)=delete
size_t size() const noexcept
Get the shared memory block size.
const std::string & name() const noexcept
Get the shared memory block name.
SharedMemory(SharedMemory &&shmem)=delete
SharedMemory & operator=(const SharedMemory &)=delete
SharedMemory(const SharedMemory &)=delete
Exceptions definition.
C++ Common project definitions.