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-2024 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  //- The region index
66  label regioni_;
67 
68  //- Reference to the region object
69  Region& region_;
70 
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct form components
77  template<class NonConstRegion>
78  RegionRef
79  (
81  const label regioni,
82  Region& region
83  );
84 
85  //- Disallow copy construct
86  RegionRef(const RegionRef& rp) = delete;
87 
88  //- Move construct
89  RegionRef(RegionRef&& rp);
90 
91 
92  //- Destructor
93  ~RegionRef();
94 
95 
96  // Member operators
97 
98  //- Cast to reference
99  operator Region&() const;
100 
101  //- Obtain the reference
102  Region& operator()() const;
103 };
104 
105 
106 /*---------------------------------------------------------------------------*\
107  Class MultiRegionRefs Declaration
108 \*---------------------------------------------------------------------------*/
109 
110 template<class Region>
111 class MultiRegionRefs
112 {
113  // Private Data
114 
115  //- List of region pointers
116  UPtrList<Region>& regions_;
117 
118  //- Previous prefix to restore on destruction
119  const word previousPrefix_;
120 
121  //- Table to facilitate access by name
122  HashTable<label, word> indices_;
123 
124 
125  // Private Member Functions
126 
127  //- Are we prefixing?
128  bool prefixes() const;
129 
130  //- Width of the write prefix
131  string::size_type prefixWidth() const;
132 
133 
134 public:
135 
136  // Friendship
137 
138  //- Declare friendship with region-reference class
139  friend class RegionRef<Region>;
140 
141  //- Declare friendship with const-region-reference class
142  friend class RegionRef<const Region>;
143 
144 
145  // Constructors
146 
147  //- Construct from a list of region pointers
149 
150 
151  //- Destructor
153 
154 
155  // Member Functions
156 
157  //- Return the size
158  label size() const;
159 
160 
161  // Member Operators
162 
163  //- Const-access a region
164  RegionRef<const Region> operator[](const label regioni) const;
165 
166  //- Access a region
167  RegionRef<Region> operator[](const label regioni);
168 
169  //- Const-access a region
171 
172  //- Access a region
174 };
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #ifdef NoRepository
184  #include "MultiRegionRefs.C"
185 #endif
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
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.
Region & operator()() const
Obtain the reference.
RegionRef(const MultiRegionRefs< NonConstRegion > &mrr, const label regioni, Region &region)
Construct form components.
A class for handling words, derived from string.
Definition: word.H:62
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:209