PLCnext API Documentation  22.3.0.20
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;
46  explicit operator bool() 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  explicit PimplPtr(Args&& ... args);
64  PimplPtr(const PimplPtr& arg);
66  PimplPtr(PimplPtr&& arg)noexcept;
68  PimplPtr& operator=(const PimplPtr& arg);
70  PimplPtr& operator=(PimplPtr&& arg)noexcept;
72  ~PimplPtr(void);
73 
74 public: // operators
76  Impl* operator->(void);
78  const Impl* operator->(void)const;
80  Impl& operator*(void);
82  const Impl& operator*(void)const;
84  explicit operator bool() const noexcept;
85 
86 private: // fields
87  ImplPtr implPtr;
88 };
89 
90 } // 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