PLCnext API Documentation  21.9.0.40
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  explicit PimplPtr(Args&& ... args);
26  PimplPtr(const PimplPtr& arg) = delete;
28  PimplPtr(PimplPtr&& arg)noexcept;
30  PimplPtr& operator=(const PimplPtr& arg) = delete;
32  PimplPtr& operator=(PimplPtr&& arg)noexcept;
34  ~PimplPtr(void);
35 
36 public: // operators
38  Impl* operator->(void);
40  const Impl* operator->(void)const;
42  Impl& operator*(void);
44  const Impl& operator*(void)const;
45 
46 private: // fields
47  ImplPtr implPtr;
48 };
49 
50 template<class T>
51 class PimplPtr<T, true>
52 {
53 public: // usings
54  using Impl = T;
55  using ImplPtr = std::unique_ptr<Impl>;
56 
57 public: // construction/destruction
59  template <class ...Args>
60  explicit PimplPtr(Args&& ... args);
62  PimplPtr(const PimplPtr& arg);
64  PimplPtr(PimplPtr&& arg)noexcept;
66  PimplPtr& operator=(const PimplPtr& arg);
68  PimplPtr& operator=(PimplPtr&& arg)noexcept;
70  ~PimplPtr(void);
71 
72 public: // operators
74  Impl* operator->(void);
76  const Impl* operator->(void)const;
78  Impl& operator*(void);
80  const Impl& operator*(void)const;
81 
82 private: // fields
83  ImplPtr implPtr;
84 };
85 
86 } // end of namespace Arp
PimplPtr(Args &&... args)
Constructs an PImpl instance using the supplied arguments.
PimplPtr & operator=(const PimplPtr &arg)=delete
Assignment operator.
Root namespace for the PLCnext API
Impl * operator->(void)
Gets the pointer to the Impl instance for none const objects.
~PimplPtr(void)
Destructs this instance and frees all resources.
Impl & operator*(void)
Gets the reference to the Impl instance for none const objects.
Small wrapper class to ensure const correctness using PImpl pattern.
Definition: PimplPtr.hxx:15