PLCnext API Documentation  22.9.0.33
PimplPtr.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include <memory>
9 
10 namespace Arp
11 {
12 
14 template<class T, bool Copyable = false>
15 class PimplPtr
16 {
17 public: // usings
18  using Impl = T;
19  using ImplPtr = std::unique_ptr<Impl>;
20 
21 public: // construction/destruction
23  template <class ...Args>
24  ARP_CXX_SYMBOL_EXPORT explicit PimplPtr(Args&& ... args);
26  PimplPtr(const PimplPtr& arg) = delete;
28  ARP_CXX_SYMBOL_EXPORT PimplPtr(PimplPtr&& arg)noexcept;
30  PimplPtr& operator=(const PimplPtr& arg) = delete;
32  ARP_CXX_SYMBOL_EXPORT PimplPtr& operator=(PimplPtr&& arg)noexcept;
34  ARP_CXX_SYMBOL_EXPORT ~PimplPtr(void);
35 
36 public: // operators
38  ARP_CXX_SYMBOL_EXPORT Impl* operator->(void);
40  ARP_CXX_SYMBOL_EXPORT const Impl* operator->(void)const;
42  ARP_CXX_SYMBOL_EXPORT Impl& operator*(void);
44  ARP_CXX_SYMBOL_EXPORT const Impl& operator*(void)const;
46  ARP_CXX_SYMBOL_EXPORT explicit operator bool(void)const noexcept;
47 
48 private: // fields
49  ImplPtr implPtr;
50 };
51 
52 template<class T>
53 class PimplPtr<T, true>
54 {
55 public: // usings
56  using Impl = T;
57  using ImplPtr = std::unique_ptr<Impl>;
58 
59 public: // construction/destruction
61  template <class ...Args>
62  ARP_CXX_SYMBOL_EXPORT explicit PimplPtr(Args&& ... args);
64  ARP_CXX_SYMBOL_EXPORT PimplPtr(const PimplPtr& arg);
66  ARP_CXX_SYMBOL_EXPORT PimplPtr(PimplPtr&& arg)noexcept;
68  ARP_CXX_SYMBOL_EXPORT PimplPtr& operator=(const PimplPtr& arg);
70  ARP_CXX_SYMBOL_EXPORT PimplPtr& operator=(PimplPtr&& arg)noexcept;
72  ARP_CXX_SYMBOL_EXPORT ~PimplPtr(void);
73 
74 public: // operators
76  ARP_CXX_SYMBOL_EXPORT Impl* operator->(void);
78  ARP_CXX_SYMBOL_EXPORT const Impl* operator->(void)const;
80  ARP_CXX_SYMBOL_EXPORT Impl& operator*(void);
82  ARP_CXX_SYMBOL_EXPORT const Impl& operator*(void)const;
84  ARP_CXX_SYMBOL_EXPORT explicit operator bool(void) const noexcept;
85 
86 private: // fields
87  ImplPtr implPtr;
88 };
89 
90 } // end of namespace Arp
ARP_CXX_SYMBOL_EXPORT Impl & operator*(void)
Gets the reference to the Impl instance for none const objects.
ARP_CXX_SYMBOL_EXPORT const Impl * operator->(void) const
Gets the pointer to the const Impl instance for const objects.
ARP_CXX_SYMBOL_EXPORT ~PimplPtr(void)
Destructs this instance and frees all resources.
ARP_CXX_SYMBOL_EXPORT PimplPtr(PimplPtr &&arg) noexcept
Move constructor.
ARP_CXX_SYMBOL_EXPORT PimplPtr(Args &&... args)
Constructs an PImpl instance using the supplied arguments.
ARP_CXX_SYMBOL_EXPORT Impl * operator->(void)
Gets the pointer to the Impl instance for none const objects.
ARP_CXX_SYMBOL_EXPORT PimplPtr & operator=(const PimplPtr &arg)
Assignment operator.
ARP_CXX_SYMBOL_EXPORT PimplPtr(const PimplPtr &arg)
Copy constructor.
ARP_CXX_SYMBOL_EXPORT const Impl & operator*(void) const
Gets the reference to the const Impl instance for const objects.
ARP_CXX_SYMBOL_EXPORT PimplPtr & operator=(PimplPtr &&arg) noexcept
Assignment move operator.
Small wrapper class to ensure const correctness using PImpl pattern.
Definition: PimplPtr.hxx:16
ARP_CXX_SYMBOL_EXPORT const Impl * operator->(void) const
Gets the pointer to the const Impl instance for const objects.
ARP_CXX_SYMBOL_EXPORT ~PimplPtr(void)
Destructs this instance and frees all resources.
PimplPtr & operator=(const PimplPtr &arg)=delete
Assignment operator.
ARP_CXX_SYMBOL_EXPORT PimplPtr(PimplPtr &&arg) noexcept
Move constructor.
ARP_CXX_SYMBOL_EXPORT PimplPtr(Args &&... args)
Constructs an PImpl instance using the supplied arguments.
PimplPtr(const PimplPtr &arg)=delete
Copy constructor.
ARP_CXX_SYMBOL_EXPORT Impl * operator->(void)
Gets the pointer to the Impl instance for none const objects.
ARP_CXX_SYMBOL_EXPORT PimplPtr & operator=(PimplPtr &&arg) noexcept
Assignment move operator.
ARP_CXX_SYMBOL_EXPORT Impl & operator*(void)
Gets the reference to the Impl instance for none const objects.
ARP_CXX_SYMBOL_EXPORT const Impl & operator*(void) const
Gets the reference to the const Impl instance for const objects.
Root namespace for the PLCnext API