exprDriverContextI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
31 {
32  return !contextObjects_.empty();
33 }
34 
35 
36 inline const Foam::regIOobject*
38 (
39  const word& name
40 ) const
41 {
42  // Like objectRegistry::cfindIOobject()
43  return contextObjects_.lookup(name, nullptr);
44 }
45 
46 
48 (
49  const word& name,
50  const regIOobject* objptr
51 )
52 {
53  if (objptr)
54  {
55  contextObjects_.set(name, objptr);
56  }
57  else
58  {
59  contextObjects_.erase(name);
60  }
61 }
62 
63 
65 (
66  const regIOobject* objptr
67 )
68 {
69  if (objptr)
70  {
71  addContextObject(objptr->name(), objptr);
72  }
73 }
74 
75 
77 (
78  const word& name
79 )
80 {
81  contextObjects_.erase(name);
82 }
83 
84 
86 (
87  const regIOobject* objptr
88 )
89 {
90  if (objptr)
91  {
92  contextObjects_.erase(objptr->name());
93  }
94 }
95 
96 
99 {
100  return contextObjects_;
101 }
102 
103 
106 {
107  return contextObjects_;
108 }
109 
110 
111 template<class ObjType>
112 const ObjType*
114 {
115  // Like objectRegistry::cfindObject()
116  return dynamic_cast<const ObjType*>(this->cfindContextIOobject(name));
117 }
118 
119 
120 // ************************************************************************* //
Foam::expressions::exprDriver::contextObjects_
contextObjectTableType contextObjects_
Externally defined context fields.
Definition: exprDriver.H:207
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::exprDriver::contextObjects
const contextObjectTableType & contextObjects() const noexcept
Read access to the object context.
Definition: exprDriverContextI.H:98
Foam::expressions::exprDriver::cfindContextObject
const ObjType * cfindContextObject(const word &name) const
Find context field object of specified type.
Definition: exprDriverContextI.H:113
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::expressions::exprDriver::cfindContextIOobject
const regIOobject * cfindContextIOobject(const word &name) const
Find named context field, if it exists.
Definition: exprDriverContextI.H:38
Foam::expressions::exprDriver::addContextObject
void addContextObject(const word &name, const regIOobject *)
Add the object to the context.
Definition: exprDriverContextI.H:48
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::HashTable::empty
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTableI.H:59
Foam::expressions::exprDriver::removeContextObject
void removeContextObject(const word &name)
Remove the object from the context.
Definition: exprDriverContextI.H:77
Foam::expressions::exprDriver::hasContextObjects
bool hasContextObjects() const
True if any context fields are defined.
Definition: exprDriverContextI.H:30