IOMap.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::IOMap
29 
30 Description
31  A Map of objects of type <T> with automated input and output.
32  Is a global object; i.e. can be read from undecomposed case.
33 
34 SourceFiles
35  IOMap.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_IOMap_H
40 #define Foam_IOMap_H
41 
42 #include "Map.H"
43 #include "regIOobject.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class IOMap Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class T>
55 class IOMap
56 :
57  public regIOobject,
58  public Map<T>
59 {
60  // Private Member Functions
61 
62  //- Read if IOobject flags set. Return true if read.
63  bool readContents();
64 
65 public:
66 
67  //- The underlying content type
68  typedef Map<T> content_type;
69 
70  //- Runtime type information
71  TypeName("Map");
72 
73 
74  // Constructors
75 
76  //- Default copy construct
77  IOMap(const IOMap&) = default;
78 
79  //- Construct from IOobject
80  explicit IOMap(const IOobject& io);
81 
82  //- Construct from IOobject and size of Map
83  IOMap(const IOobject& io, const label size);
84 
85  //- Construct from IOobject and a copy of Map content
86  IOMap(const IOobject&, const Map<T>& content);
87 
88  //- Construct by transferring the Map content
89  IOMap(const IOobject&, Map<T>&& content);
90 
91 
92  // Factory Methods
93 
94  //- Read and return contents. The IOobject will not be registered
95  static Map<T> readContents(const IOobject& io);
96 
97 
98  //- Destructor
99  virtual ~IOMap() = default;
100 
101 
102  // Member Functions
103 
104  bool writeData(Ostream& os) const;
105 
106  //- Is object global
107  virtual bool global() const
108  {
109  return true;
110  }
111 
112  //- Return complete path + object name if the file exists
113  // either in the case/processor or case otherwise null
114  virtual fileName filePath() const
115  {
116  return globalFilePath(type());
117  }
118 
119 
120  // Member Operators
121 
122  //- Copy assignment of entries
123  void operator=(const IOMap<T>& rhs);
125  //- Copy or move assignment of entries
126  using Map<T>::operator=;
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 //- Global file type for IOMap
133 template<class T>
134 struct is_globalIOobject<IOMap<T>> : std::true_type {};
135 
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 } // End namespace Foam
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 #ifdef NoRepository
144  #include "IOMap.C"
145 #endif
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #endif
150 
151 // ************************************************************************* //
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition: IOMap.C:120
A class for handling file names.
Definition: fileName.H:72
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:547
virtual bool global() const
Is object global.
Definition: IOMap.H:124
Trait for specifying global vs. local file types.
Definition: IOobject.H:981
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOMap.C:110
A Map of objects of type <T> with automated input and output. Is a global object; i...
Definition: IOMap.H:50
TypeName("Map")
Runtime type information.
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:342
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
virtual ~IOMap()=default
Destructor.
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOMap.H:134
IOMap(const IOMap &)=default
Default copy construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Map< T > content_type
The underlying content type.
Definition: IOMap.H:67
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.