FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/refCount.H>
39 #include <cstddef>
40 
41 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
42 # define ConstructFromTmp
43 #endif
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class tmp Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class T>
55 class tmp
56 {
57  // Private data
58 
59  //- Flag for whether object is a temporary or a constant object
60  bool isTmp_;
61 
62  //- Pointer to temporary object
63  mutable T* ptr_;
64 
65  // Const reference to constant object
66  const T& ref_;
67 
68 
69 public:
70 
71  // Constructors
72 
73  //- Store object pointer
74  inline explicit tmp(T* = 0);
75 
76  //- Store object const reference
77  inline tmp(const T&);
78 
79  //- Construct copy and increment reference count
80  inline tmp(const tmp<T>&);
81 
82 
83  // Destructor
84 
85  //- Delete object when reference count == 0
86  inline ~tmp();
87 
88 
89  // Member Functions
90 
91  // Access
92 
93  //- Return true if this is really a temporary object
94  inline bool isTmp() const;
95 
96  //- Return true if this temporary object empty,
97  // ie, a temporary without allocation
98  inline bool empty() const;
99 
100  //- Is this temporary object valid,
101  // ie, it is a reference or a temporary that has been allocated
102  inline bool valid() const;
103 
104  // Edit
105 
106  //- Return tmp pointer for reuse
107  inline T* ptr() const;
108 
109  //- If object pointer points to valid object:
110  // delete object and set pointer to NULL
111  inline void clear() const;
112 
113 
114  // Member operators
115 
116  //- Dereference operator
117  inline T& operator()();
118 
119  //- Const dereference operator
120  inline const T& operator()() const;
121 
122  //- Const cast to the underlying type reference
123  inline operator const T&() const;
124 
125  //- Return object pointer
126  inline T* operator->();
127 
128  //- Return const object pointer
129  inline const T* operator->() const;
130 
131  //- Assignment operator
132  inline void operator=(const tmp<T>&);
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #include <OpenFOAM/tmpI.H>
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************ vim: set sw=4 sts=4 et: ************************ //