oneOrTmp.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) 2025 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::oneOrTmp
26 
27 Description
28  Variant type that either contains and behaves as tmp object or represents a
29  value of one. Provides multiplication and scaling operations which are
30  optimised away if representing a value of one.
31 
32 SourceFiles
33  oneOrTmpI.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef oneOrTmp_H
38 #define oneOrTmp_H
39 
40 #include "one.H"
41 #include "tmp.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class oneOrTmp Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class Type>
53 class oneOrTmp
54 {
55  // Private Data
56 
57  //- Is this a value of one?
58  bool isOne_;
59 
60  //- Temporary object
61  tmp<Type> tt_;
62 
63 
64 public:
65 
66  // Constructors
67 
68  //- Construct as one
69  inline oneOrTmp();
70 
71  //- Construct from an object
72  inline oneOrTmp(const Type&);
73 
74  //- Construct from a temporary object
75  inline oneOrTmp(const tmp<Type>&);
76 
77  //- Copy construct
78  inline oneOrTmp(const oneOrTmp<Type>&);
79 
80 
81  //- Destructor
82  ~oneOrTmp();
83 
84 
85  // Member Functions
86 
87  //- Scale an object by this value
88  template<class Other>
89  void scale(Other& o) const;
90 
91 
92  // Member Operators
93 
94  //- Assign to one
95  inline void operator=(const one&);
96 
97  //- Assign to a temporary object
98  inline void operator=(const tmp<Type>&);
99 
100  //- Return an instance of the class which refers to this one. Used in
101  // the same way as tmp::operator() to prevent the tmp being consumed.
102  inline oneOrTmp<Type> operator()() const;
103 
104  //- Multiply with an object
105  template<class Other>
106  inline tmp<Other> operator*(const Other&);
107 
108  //- Multiply with a temporary object
109  template<class Other>
110  inline tmp<Other> operator*(const tmp<Other>&);
111 
112  //- Disallow default bitwise assignment
113  void operator=(const oneOrTmp<Type>&) = delete;
114 };
115 
116 
117 // Global Operators
118 
119 //- Multiply with an object
120 template<class Type, class Other>
121 inline tmp<Other> operator*(const Other&, const oneOrTmp<Type>&);
122 
123 //- Multiply with a temporary object
124 template<class Type, class Other>
125 inline tmp<Other> operator*(const tmp<Other>&, const oneOrTmp<Type>&);
126 
127 //- Multiply-assign with an object
128 template<class Type, class Other>
129 inline void operator*=(Other&, const oneOrTmp<Type>&);
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #include "oneOrTmpI.H"
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 #endif
142 
143 // ************************************************************************* //
Variant type that either contains and behaves as tmp object or represents a value of one....
Definition: oneOrTmp.H:53
oneOrTmp()
Construct as one.
Definition: oneOrTmpI.H:31
void scale(Other &o) const
Scale an object by this value.
Definition: oneOrTmpI.H:74
~oneOrTmp()
Destructor.
Definition: oneOrTmpI.H:66
tmp< Other > operator*(const Other &)
Multiply with an object.
oneOrTmp< Type > operator()() const
Return an instance of the class which refers to this one. Used in.
Definition: oneOrTmpI.H:102
void operator=(const one &)
Assign to one.
Definition: oneOrTmpI.H:86
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Definition: one.H:51
Namespace for OpenFOAM.
tmp< DimensionedField< Type, GeoMesh, Field > > operator*(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &df2)
void operator*=(Other &, const oneOrTmp< Type > &)
Multiply-assign with an object.
Definition: oneOrTmpI.H:168