tmp.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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::tmp
26 
27 Description
28  A class for managing temporary objects
29 
30 SourceFiles
31  tmpI.H
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef tmp_H
36 #define tmp_H
37 
38 #include "refCount.H"
39 #include <cstddef>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class tmp Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template<class T>
51 class tmp
52 {
53  // Private data
54 
55  //- Flag for whether object is a temporary or a constant object
56  bool isTmp_;
57 
58  //- Pointer to temporary object
59  mutable T* ptr_;
60 
61  //- Const reference to constant object
62  const T& ref_;
63 
64 
65 public:
66 
67  // Constructors
68 
69  //- Store object pointer
70  inline explicit tmp(T* = 0);
71 
72  //- Store object const reference
73  inline tmp(const T&);
74 
75  //- Construct copy and increment reference count
76  inline tmp(const tmp<T>&);
77 
78  //- Construct copy transferring content of temporary if required
79  inline tmp(const tmp<T>&, bool allowTransfer);
80 
81 
82  //- Destructor, delete object when reference count == 0
83  inline ~tmp();
84 
85 
86  // Member Functions
87 
88  // Access
89 
90  //- Return true if this is really a temporary object
91  inline bool isTmp() const;
92 
93  //- Return true if this temporary object empty,
94  // ie, a temporary without allocation
95  inline bool empty() const;
96 
97  //- Is this temporary object valid,
98  // ie, it is a reference or a temporary that has been allocated
99  inline bool valid() const;
100 
101  // Edit
102 
103  //- Return tmp pointer for reuse
104  inline T* ptr() const;
105 
106  //- If object pointer points to valid object:
107  // delete object and set pointer to NULL
108  inline void clear() const;
109 
110 
111  // Member operators
112 
113  //- Dereference operator
114  inline T& operator()();
115 
116  //- Const dereference operator
117  inline const T& operator()() const;
118 
119  //- Const cast to the underlying type reference
120  inline operator const T&() const;
121 
122  //- Return object pointer
123  inline T* operator->();
124 
125  //- Return const object pointer
126  inline const T* operator->() const;
127 
128  //- Assignment operator
129  inline void operator=(const tmp<T>&);
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #include "tmpI.H"
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 #endif
144 
145 // ************************************************************************* //
Foam::tmp::operator()
T & operator()()
Dereference operator.
Definition: tmpI.H:185
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::tmp::operator->
T * operator->()
Return object pointer.
Definition: tmpI.H:242
Foam::tmp::isTmp
bool isTmp() const
Return true if this is really a temporary object.
Definition: tmpI.H:125
Foam::tmp::ref_
const T & ref_
Const reference to constant object.
Definition: tmp.H:61
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::tmp::ptr
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:146
Foam::tmp::valid
bool valid() const
Is this temporary object valid,.
Definition: tmpI.H:139
Foam::tmp::tmp
tmp(T *=0)
Store object pointer.
Foam::tmp::ptr_
T * ptr_
Pointer to temporary object.
Definition: tmp.H:58
Foam::tmp::empty
bool empty() const
Return true if this temporary object empty,.
Definition: tmpI.H:132
Foam::tmp::operator=
void operator=(const tmp< T > &)
Assignment operator.
Definition: tmpI.H:270
Foam::tmp::isTmp_
bool isTmp_
Flag for whether object is a temporary or a constant object.
Definition: tmp.H:55
tmpI.H
refCount.H
Foam::tmp::~tmp
~tmp()
Destructor, delete object when reference count == 0.
Definition: tmpI.H:105
Foam::tmp::clear
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:172