UautoPtr.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::UautoPtr
26 
27 Description
28  An auto-pointer similar to the STL auto_ptr but with automatic casting
29  to a reference to the type and with pointer allocation checking on access.
30 
31 SourceFiles
32  UautoPtrI.H
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef UautoPtr_H
37 #define UautoPtr_H
38 
39 #include <cstddef>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class UautoPtr Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template<class T>
51 class UautoPtr
52 {
53  // Public data
54 
55  //- Pointer to object
56  mutable T* ptr_;
57 
58 
59 public:
60 
61  typedef T Type;
62 
63 
64  // Constructors
65 
66  //- Store object pointer
67  inline explicit UautoPtr(T* = nullptr);
68 
69  //- Copy constructor
70  inline UautoPtr(const UautoPtr<T>&);
71 
72 
73  // Member Functions
74 
75  // Check
76 
77  //- Return true if the UautoPtr is empty (ie, no pointer set)
78  inline bool empty() const;
79 
80  //- Return true if the UautoPtr valid (ie, the pointer is set)
81  inline bool valid() const;
82 
83 
84  // Edit
85 
86  //- Return object pointer for reuse
87  inline T* ptr();
88 
89  //- Set pointer to that given
90  // If object pointer already set issue a FatalError
91  inline void set(T*);
92 
93  //- Set pointer to that given
94  inline void reset(T* = nullptr);
95 
96  //- Set pointer to nullptr
97  inline void clear();
98 
99 
100  // Member Operators
101 
102  //- Return reference to the object data
103  inline T& operator()();
104 
105  //- Return const reference to the object data
106  inline const T& operator()() const;
107 
108  //- Return reference to the object data
109  inline T& operator*();
110 
111  //- Return const reference to the object data
112  inline const T& operator*() const;
113 
114  //- Const cast to the underlying type reference
115  inline operator const T&() const;
116 
117  //- Return object pointer
118  inline T* operator->();
119 
120  //- Return const object pointer
121  inline const T* operator->() const;
122 
123  //- Take over the object pointer from parameter
124  inline void operator=(T*);
125 
126  //- Take over the object pointer from parameter
127  inline void operator=(const UautoPtr<T>&);
128 };
129 
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #include "UautoPtrI.H"
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 #endif
142 
143 // ************************************************************************* //
UautoPtr(T *=nullptr)
Store object pointer.
Definition: UautoPtrI.H:32
T * ptr()
Return object pointer for reuse.
Definition: UautoPtrI.H:62
bool empty() const
Return true if the UautoPtr is empty (ie, no pointer set)
Definition: UautoPtrI.H:48
bool valid() const
Return true if the UautoPtr valid (ie, the pointer is set)
Definition: UautoPtrI.H:55
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: UautoPtr.H:50
T & operator*()
Return reference to the object data.
Definition: UautoPtrI.H:130
void operator=(T *)
Take over the object pointer from parameter.
Definition: UautoPtrI.H:189
void reset(T *=nullptr)
Set pointer to that given.
Definition: UautoPtrI.H:84
T & operator()()
Return reference to the object data.
Definition: UautoPtrI.H:100
T * operator->()
Return object pointer.
Definition: UautoPtrI.H:167
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void clear()
Set pointer to nullptr.
Definition: UautoPtrI.H:91
Namespace for OpenFOAM.