CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
shared_type.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_SYSTEM_SHARED_TYPE_H
10#define CPPCOMMON_SYSTEM_SHARED_TYPE_H
11
13
14#include <memory>
15#include <string>
16
17namespace CppCommon {
18
20
26template <typename T>
28{
29public:
31
34 explicit SharedType(const std::string& name);
35 SharedType(const SharedType<T>&) = delete;
37 ~SharedType() = default;
38
41
43 explicit operator bool() const { return (_shared.ptr() != nullptr); }
44
46 T& operator*() { return ref(); }
48 const T& operator*() const { return ref(); }
49
51 T* operator->() { return ptr(); }
53 const T* operator->() const { return ptr(); }
54
56 const std::string& name() const noexcept { return _shared.name(); }
58 size_t size() const noexcept { return _shared.size(); }
59
61 T* ptr() { return (T*)_shared.ptr(); }
63 const T* ptr() const { return (const T*)_shared.ptr(); }
64
66 T& ref() { return *ptr(); }
68 const T& ref() const { return *ptr(); }
69
71 bool owner() const { return _shared.owner(); }
72
73private:
74 SharedMemory _shared;
75};
76
79} // namespace CppCommon
80
81#include "shared_type.inl"
82
83#endif // CPPCOMMON_SYSTEM_SHARED_TYPE_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...
size_t size() const noexcept
Get the shared memory block size.
const std::string & name() const noexcept
Get the shared memory block name.
Shared memory type.
Definition shared_type.h:28
const T * operator->() const
Dereference constant shared memory type member.
Definition shared_type.h:53
const T & operator*() const
Dereference constant shared memory type.
Definition shared_type.h:48
size_t size() const noexcept
Get the shared memory type size.
Definition shared_type.h:58
bool owner() const
Get the shared memory type owner flag (true if the new one was created, false if the existing one was...
Definition shared_type.h:71
T & ref()
Get the shared memory type reference.
Definition shared_type.h:66
T * operator->()
Dereference shared memory type member.
Definition shared_type.h:51
T * ptr()
Get the shared memory type pointer.
Definition shared_type.h:61
const std::string & name() const noexcept
Get the shared memory type name.
Definition shared_type.h:56
SharedType< T > & operator=(SharedType< T > &&)=delete
const T & ref() const
Get the constant shared memory type reference.
Definition shared_type.h:68
SharedType(SharedType< T > &&)=delete
SharedType< T > & operator=(const SharedType< T > &)=delete
const T * ptr() const
Get the constant shared memory type pointer.
Definition shared_type.h:63
T & operator*()
Dereference shared memory type.
Definition shared_type.h:46
SharedType(const SharedType< T > &)=delete
C++ Common project definitions.
Shared memory manager definition.
Shared memory type inline implementation.