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-2022 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  //- Destructor
93  virtual ~IOMap() = default;
94 
95 
96  // Member Functions
97 
98  bool writeData(Ostream& os) const;
99 
100  //- Is object global
101  virtual bool global() const
102  {
103  return true;
104  }
105 
106  //- Return complete path + object name if the file exists
107  // either in the case/processor or case otherwise null
108  virtual fileName filePath() const
109  {
110  return globalFilePath(type());
111  }
112 
113 
114  // Member Operators
115 
116  //- Copy assignment of entries
117  void operator=(const IOMap<T>& rhs);
118 
119  //- Copy or move assignment of entries
120  using Map<T>::operator=;
121 };
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 #ifdef NoRepository
131  #include "IOMap.C"
132 #endif
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 #endif
137 
138 // ************************************************************************* //
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition: IOMap.C:103
A class for handling file names.
Definition: fileName.H:71
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:534
virtual bool global() const
Is object global.
Definition: IOMap.H:116
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOMap.C:93
A Map of objects of type <T> with automated input and output. Is a global object; i...
Definition: IOMap.H:50
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:45
TypeName("Map")
Runtime type information.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:752
virtual ~IOMap()=default
Destructor.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOMap.H:126
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:55
OBJstream os(runTime.globalPath()/outputName)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
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.