initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / memory / tmp / tmp.H
bloba1aa88bec47740ab8729ee2be592e4e3e183b666
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::tmp
28 Description
29     A class for managing temporary objects
31 SourceFiles
32     tmpI.H
34 \*---------------------------------------------------------------------------*/
36 #ifndef tmp_H
37 #define tmp_H
39 #include "refCount.H"
40 #include <cstddef>
42 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
43 #   define ConstructFromTmp
44 #endif
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 /*---------------------------------------------------------------------------*\
52                              Class tmp Declaration
53 \*---------------------------------------------------------------------------*/
55 template<class T>
56 class tmp
58     // Private data
60         //- Flag for whether object is a temporary or a constant object
61         bool isTmp_;
63         //- Pointer to temporary object
64         mutable T* ptr_;
66         // Const reference to constant object
67         const T& ref_;
70 public:
72     // Constructors
74         //- Store object pointer
75         inline explicit tmp(T* = 0);
77         //- Store object const reference
78         inline tmp(const T&);
80         //- Construct copy and increment reference count
81         inline tmp(const tmp<T>&);
84     // Destructor
86         //- Delete object when reference count == 0
87         inline ~tmp();
90     // Member Functions
92         // Access
94             //- Return true if this is really a temporary object
95             inline bool isTmp() const;
97             //- Return true if this temporary object empty,
98             //  ie, a temporary without allocation
99             inline bool empty() const;
101             //- Is this temporary object valid,
102             //  ie, it is a reference or a temporary that has been allocated
103             inline bool valid() const;
105         // Edit
107             //- Return tmp pointer for reuse
108             inline T* ptr() const;
110             //- If object pointer points to valid object:
111             //  delete object and set pointer to NULL
112             inline void clear() const;
115     // Member operators
117         //- Dereference operator
118         inline T& operator()();
120         //- Const dereference operator
121         inline const T& operator()() const;
123         //- Const cast to the underlying type reference
124         inline operator const T&() const;
126         //- Return object pointer
127         inline T* operator->();
129         //- Return const object pointer
130         inline const T* operator->() const;
132         //- Assignment operator
133         inline void operator=(const tmp<T>&);
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 } // End namespace Foam
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 #include "tmpI.H"
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 #endif
149 // ************************************************************************* //