MultiRegionRefs.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) 2023-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::MultiRegionRefs
26 
27 Description
28  Class to wrap a UPtrList of of region-associated objects (meshes, solvers,
29  domainDecompositions, ...). Access will return a wrapped reference and will
30  set the Info prefix to the region name. The prefix will remain until the
31  wrapped reference goes out of scope.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef MultiRegionRefs_H
36 #define MultiRegionRefs_H
37 
38 #include "IOstreams.H"
39 #include "regionName.H"
40 #include "UPtrList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 template<class Region>
48 class MultiRegionRefs;
49 
50 
51 /*---------------------------------------------------------------------------*\
52  Class RegionRef Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class Region>
56 class RegionRef
57 {
58 private:
59 
60  // Private Data
61 
62  //- The multi-region container
63  const MultiRegionRefs<Region>& mrr_;
64 
65  //- Previous prefix to restore on destruction
66  const word previousPrefix_;
67 
68  //- The region index
69  label regioni_;
70 
71  //- Reference to the region object
72  Region& region_;
73 
74 
75 public:
76 
77  // Constructors
78 
79  //- Construct form components
80  template<class NonConstRegion>
81  RegionRef
82  (
84  const word& previousPrefix,
85  const label regioni,
86  Region& region
87  );
88 
89  //- Disallow copy construct
90  RegionRef(const RegionRef& rp) = delete;
91 
92  //- Move construct
93  RegionRef(RegionRef&& rp);
94 
95 
96  //- Destructor
97  ~RegionRef();
98 
99 
100  // Member operators
101 
102  //- Cast to reference
103  operator Region&() const;
104 
105  //- Obtain the reference
106  Region& operator()() const;
107 };
108 
109 
110 /*---------------------------------------------------------------------------*\
111  Class MultiRegionRefs Declaration
112 \*---------------------------------------------------------------------------*/
113 
114 template<class Region>
115 class MultiRegionRefs
116 {
117  // Private Data
118 
119  //- List of region pointers
120  UPtrList<Region>& regions_;
121 
122  //- Previous prefix to restore on destruction
123  const word previousPrefix_;
124 
125  //- Table to facilitate access by name
126  HashTable<label, word> indices_;
127 
128 
129  // Private Member Functions
130 
131  //- Are we prefixing?
132  bool prefixes() const;
133 
134  //- Width of the write prefix
135  string::size_type prefixWidth() const;
136 
137 
138 public:
139 
140  // Friendship
141 
142  //- Declare friendship with region-reference class
143  friend class RegionRef<Region>;
144 
145  //- Declare friendship with const-region-reference class
146  friend class RegionRef<const Region>;
147 
148 
149  // Constructors
150 
151  //- Construct from a list of region pointers
153 
154 
155  //- Destructor
157 
158 
159  // Member Functions
160 
161  //- Return the size
162  label size() const;
163 
164 
165  // Member Operators
166 
167  //- Const-access a region
168  RegionRef<const Region> operator[](const label regioni) const;
169 
170  //- Access a region
171  RegionRef<Region> operator[](const label regioni);
172 
173  //- Const-access a region
175 
176  //- Access a region
178 };
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #ifdef NoRepository
188  #include "MultiRegionRefs.C"
189 #endif
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 #endif
194 
195 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
An STL-conforming hash table.
Definition: HashTable.H:127
Class to wrap a UPtrList of of region-associated objects (meshes, solvers, domainDecompositions,...
RegionRef< const Region > operator[](const label regioni) const
Const-access a region.
MultiRegionRefs(UPtrList< Region > &regions)
Construct from a list of region pointers.
label size() const
Return the size.
~MultiRegionRefs()
Destructor.
~RegionRef()
Destructor.
RegionRef(const MultiRegionRefs< NonConstRegion > &mrr, const word &previousPrefix, const label regioni, Region &region)
Construct form components.
Region & operator()() const
Obtain the reference.
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & regionName(const solver &region)
Definition: solver.H:218
const fvMesh & region(const dictionary &dict)
Cast the give dictionary to the corresponding region fvMesh.
Definition: fvMesh.C:1831