function1Base.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "function1Base.H"
29 #include "objectRegistry.H"
30 #include "Time.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
35 (
36  const bool useTime
37 ) const noexcept
38 {
39  if (obrPtr_ && useTime)
40  {
41  return &(obrPtr_->time());
42  }
43 
44  return obrPtr_;
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
49 
51 (
52  const word& entryName,
53  const objectRegistry* obrPtr
54 )
55 :
56  refCount(),
57  name_(entryName),
58  obrPtr_(obrPtr)
59 {}
60 
61 
63 (
64  const word& entryName,
65  const dictionary& dict,
66  const objectRegistry* obrPtr
67 )
68 :
69  refCount(),
70  name_(entryName),
71  obrPtr_(obrPtr)
72 {}
73 
74 
76 :
77  refCount(),
78  name_(rhs.name_),
79  obrPtr_(rhs.obrPtr_)
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
84 
85 // NOTE : do not delete obrPtr_ (no ownership)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
93 {
94  if (!obrPtr_)
95  {
97  << "Object registry not set"
98  << abort(FatalError);
99  }
100  return *obrPtr_;
101 }
102 
103 
105 {
106  if (!obrPtr_)
107  {
109  << "Object registry not set"
110  << abort(FatalError);
111  }
112 
113  return obrPtr_->time();
114 }
115 
116 
117 bool Foam::function1Base::isTime() const noexcept
118 {
119  return (obrPtr_ && obrPtr_->isTimeDb());
120 }
121 
122 
123 void Foam::function1Base::resetDb(const objectRegistry* obrPtr) noexcept
124 {
125  obrPtr_ = obrPtr;
126 }
127 
128 
130 {
131  obrPtr_ = &db;
132 }
133 
134 
136 {}
137 
138 
139 // ************************************************************************* //
Foam::function1Base::whichDb
const objectRegistry * whichDb() const noexcept
Return the associated registry or nullptr.
Definition: function1Base.H:119
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::function1Base::isTime
bool isTime() const noexcept
Return true if this function was created with the time database.
Definition: function1Base.C:117
Foam::function1Base::resetDb
void resetDb(const objectRegistry *obrPtr=nullptr) noexcept
Reset the associated objectRegistry.
Definition: function1Base.C:123
Foam::refCount
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
objectRegistry.H
Foam::function1Base::time
const Time & time() const
Return the time database.
Definition: function1Base.C:104
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::function1Base::obr
const objectRegistry & obr() const
Return the object registry.
Definition: function1Base.C:92
Foam::function1Base
Base class for template-invariant parts of Function1.
Definition: function1Base.H:54
Foam::function1Base::function1Base
function1Base(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name and optional registry.
Definition: function1Base.C:51
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::function1Base::~function1Base
virtual ~function1Base()
Destructor.
Definition: function1Base.C:86
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
function1Base.H
Foam::function1Base::userTimeToTime
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: function1Base.C:135