regIOobject.H 11.2 KB
 OpenFOAM-admin committed Apr 15, 2008 1 2 3 4 /*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration |  OpenFOAM bot committed Oct 31, 2019 5  \\ / A nd | www.openfoam.com  OpenFOAM bot committed Feb 06, 2019 6 7  \\/ M anipulation | -------------------------------------------------------------------------------  OpenFOAM bot committed Oct 31, 2019 8  Copyright (C) 2011-2017 OpenFOAM Foundation  Mark Olesen committed Jan 13, 2020 9  Copyright (C) 2018-2020 OpenCFD Ltd.  OpenFOAM-admin committed Apr 15, 2008 10 11 12 13 ------------------------------------------------------------------------------- License This file is part of OpenFOAM.  Mark Olesen committed Mar 29, 2010 14 15 16 17  OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  OpenFOAM-admin committed Apr 15, 2008 18 19 20 21 22 23 24  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License  Mark Olesen committed Mar 29, 2010 25  along with OpenFOAM. If not, see .  OpenFOAM-admin committed Apr 15, 2008 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  Class Foam::regIOobject Description regIOobject is an abstract class derived from IOobject to handle automatic object registration with the objectRegistry. SourceFiles regIOobject.C regIOobjectRead.C regIOobjectWrite.C \*---------------------------------------------------------------------------*/ #ifndef regIOobject_H #define regIOobject_H #include "IOobject.H" #include "typeInfo.H"  Mark Olesen committed Feb 19, 2020 46 #include "stdFoam.H"  OpenFOAM-admin committed Apr 15, 2008 47 48 49 50 #include "OSspecific.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //  mattijs committed Mar 10, 2009 51   OpenFOAM-admin committed Apr 15, 2008 52 53 54 namespace Foam {  mattijs committed Aug 09, 2011 55 56 57 58 namespace functionEntries { class codeStream; }  Andrew Heather committed Jul 07, 2017 59 60 61 62 63 namespace fileOperations { class uncollatedFileOperation; class masterUncollatedFileOperation; }  mattijs committed Aug 09, 2011 64   OpenFOAM-admin committed Apr 15, 2008 65 /*---------------------------------------------------------------------------*\  Mark Olesen committed Feb 25, 2009 66  Class regIOobject Declaration  OpenFOAM-admin committed Apr 15, 2008 67 68 69 70 71 72 \*---------------------------------------------------------------------------*/ class regIOobject : public IOobject {  mattijs committed Jan 25, 2016 73 protected:  mattijs committed Nov 16, 2010 74   Andrew Heather committed Jul 07, 2017 75  //- Helper: check readOpt flags and read if necessary  mattijs committed Jan 25, 2016 76 77 78 79 80  bool readHeaderOk ( const IOstream::streamFormat PstreamFormat, const word& typeName );  mattijs committed Aug 09, 2011 81   mattijs committed Jan 25, 2016 82 83 84 85  //- Construct and return an IFstream for the object. // The results is NULL if the stream construction failed Istream* objectStream();  mattijs committed Aug 09, 2011 86 87 88 89  //- To flag master-only reading of objects static bool masterOnlyReading;  OpenFOAM-admin committed Apr 15, 2008 90 91 private:  Mark Olesen committed Jan 13, 2020 92  // Private Data  OpenFOAM-admin committed Apr 15, 2008 93 94 95 96 97 98 99  //- Is this object registered with the registry bool registered_; //- Is this object owned by the registry bool ownedByRegistry_;  mattijs committed Jan 25, 2016 100 101  //- List of modification watch indices mutable labelList watchIndices_;  OpenFOAM-admin committed Apr 15, 2008 102   mattijs committed Mar 10, 2009 103 104 105  //- eventNo of last update label eventNo_;  OpenFOAM-admin committed Apr 15, 2008 106  //- Istream for reading  Andrew Heather committed Jul 07, 2017 107  autoPtr isPtr_;  OpenFOAM-admin committed Apr 15, 2008 108 109   110  // Private Member Functions  OpenFOAM-admin committed Apr 15, 2008 111 112  //- Return Istream  Andrew Heather committed Jul 07, 2017 113  Istream& readStream(const bool valid = true);  OpenFOAM-admin committed Apr 15, 2008 114   Mark Olesen committed May 30, 2018 115 116  //- No copy assignment void operator=(const regIOobject&) = delete;  OpenFOAM-admin committed Apr 15, 2008 117 118 119 120  public:  Mark Olesen committed Jan 13, 2020 121 122  //- Declare friendship with classes that need access to //- masterOnlyReading  mattijs committed Aug 09, 2011 123  friend class functionEntries::codeStream;  Andrew Heather committed Jul 07, 2017 124 125  friend class fileOperations::uncollatedFileOperation; friend class fileOperations::masterUncollatedFileOperation;  mattijs committed Aug 09, 2011 126 127   OpenFOAM-admin committed Apr 15, 2008 128 129 130 131 132  // Static data //- Runtime type information TypeName("regIOobject");  Henry Weller committed Nov 25, 2016 133  static float fileModificationSkew;  OpenFOAM-admin committed Apr 15, 2008 134   mattijs committed Nov 27, 2019 135 136  static int maxFileModificationPolls;  OpenFOAM-admin committed Apr 15, 2008 137 138 139  // Constructors  Mark Olesen committed Nov 20, 2019 140 141 142  //- Construct from IOobject. The optional flag adds special handling //- if the object is the top-level regIOobject (eg, Time). regIOobject(const IOobject& io, const bool isTime = false);  OpenFOAM-admin committed Apr 15, 2008 143   Mark Olesen committed Jun 03, 2019 144  //- Copy construct  Mark Olesen committed Nov 20, 2019 145  regIOobject(const regIOobject& rio);  OpenFOAM-admin committed Apr 15, 2008 146   Mark Olesen committed Jun 03, 2019 147 148  //- Copy construct, transferring registry registration to the copy //- if registerCopy is true  Mark Olesen committed Nov 20, 2019 149  regIOobject(const regIOobject& rio, bool registerCopy);  OpenFOAM-admin committed Apr 15, 2008 150   Mark Olesen committed Jun 03, 2019 151 152  //- Copy construct with new name, transferring registry registration //- to the copy f registerCopy is true  Henry committed Feb 13, 2015 153 154  regIOobject(const word& newName, const regIOobject&, bool registerCopy);  Mark Olesen committed Nov 20, 2019 155 156  //- Copy construct with new IO parameters regIOobject(const IOobject& io, const regIOobject& rio);  Henry committed Feb 13, 2015 157   OpenFOAM-admin committed Apr 15, 2008 158   Mark Olesen committed Apr 12, 2010 159 160  //- Destructor virtual ~regIOobject();  OpenFOAM-admin committed Apr 15, 2008 161 162   Mark Olesen committed Nov 20, 2019 163  // Member Functions  OpenFOAM-admin committed Apr 15, 2008 164 165 166  // Registration  Mark Olesen committed Nov 20, 2019 167  //- Add object to registry, if not already registered  Mark Olesen committed Jan 13, 2020 168 169  // \return true if object was already registered, // or was newly registered  Mark Olesen committed Feb 25, 2009 170  bool checkIn();  OpenFOAM-admin committed Apr 15, 2008 171   Mark Olesen committed Jun 03, 2019 172 173  //- Remove all file watches and remove object from registry // \return true if object was registered and was removed  Mark Olesen committed Feb 25, 2009 174  bool checkOut();  OpenFOAM-admin committed Apr 15, 2008 175   mattijs committed Jan 25, 2016 176 177 178  //- Add file watch on object (if registered and READ_IF_MODIFIED) virtual void addWatch();  Mark Olesen committed Feb 25, 2009 179  //- Is this object owned by the registry?  OpenFOAM-admin committed Apr 15, 2008 180 181  inline bool ownedByRegistry() const;  Mark Olesen committed Jan 13, 2020 182 183 184 185  //- Register object with its registry //- and transfer ownership to the registry. // \return true if now ownedByRegistry inline bool store();  OpenFOAM-admin committed Apr 15, 2008 186   Mark Olesen committed Jan 13, 2020 187 188  //- Register object pointer with its registry //- and transfer ownership to the registry.  Mark Olesen committed Nov 20, 2019 189  // \return reference to the object.  OpenFOAM-admin committed Apr 15, 2008 190  template  Mark Olesen committed Nov 08, 2018 191  inline static Type& store(Type* p);  OpenFOAM-admin committed Apr 15, 2008 192   Mark Olesen committed Jan 13, 2020 193 194 195  //- Register object pointer with its registry //- and transfer ownership to the registry. // Clears the autoPtr parameter.  Mark Olesen committed Nov 20, 2019 196  // \return reference to the object.  Mark Olesen committed Nov 08, 2018 197 198 199  template inline static Type& store(autoPtr& aptr);  Mark Olesen committed Jan 13, 2020 200 201 202  //- Register object pointer with its registry //- and transfer ownership to the registry. // Clears the autoPtr parameter.  Mark Olesen committed Nov 20, 2019 203  // \return reference to the object.  OpenFOAM-admin committed Apr 15, 2008 204  template  Mark Olesen committed Nov 08, 2018 205  inline static Type& store(autoPtr&& aptr);  OpenFOAM-admin committed Apr 15, 2008 206   Mark Olesen committed Jan 13, 2020 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222  //- Register temporary pointer with its registry //- and transfer ownership of pointer to the registry. // After the call, tmp parameter changes from PTR to CREF. // // \return reference to the object. template inline static Type& store(tmp& tptr); //- Register temporary pointer with its registry //- and transfer ownership of pointer to the registry. // After the call, the tmp parameter content is \em unspecified. // // \return reference to the object. template inline static Type& store(tmp&& tptr);  OpenFOAM-admin committed Apr 15, 2008 223  //- Release ownership of this object from its registry  Mark Olesen committed Jun 03, 2019 224 225  // \param unregister optionally set as non-registered inline void release(const bool unregister = false);  OpenFOAM-admin committed Apr 15, 2008 226 227   Mark Olesen committed Jan 13, 2020 228  // Dependency Checking  mattijs committed Mar 10, 2009 229 230 231 232 233 234 235  //- Event number at last update. inline label eventNo() const; //- Event number at last update. inline label& eventNo();  henry committed Oct 20, 2009 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254  //- Return true if up-to-date with respect to given object bool upToDate(const regIOobject&) const; //- Return true if up-to-date with respect to given objects bool upToDate ( const regIOobject&, const regIOobject& ) const; //- Return true if up-to-date with respect to given objects bool upToDate ( const regIOobject&, const regIOobject&, const regIOobject& ) const; //- Return true if up-to-date with respect to given objects  henry committed Mar 12, 2009 255 256  bool upToDate (  henry committed Oct 20, 2009 257 258 259 260  const regIOobject&, const regIOobject&, const regIOobject&, const regIOobject&  henry committed Mar 12, 2009 261 262  ) const;  Mark Olesen committed Nov 20, 2019 263 264  //- Set as up-to-date  henry committed Mar 12, 2009 265 266  void setUpToDate();  mattijs committed Mar 10, 2009 267   OpenFOAM-admin committed Apr 15, 2008 268 269 270 271 272 273 274 275  // Edit //- Rename virtual void rename(const word& newName); // Reading  mattijs committed Jan 25, 2016 276 277 278 279 280 281 282 283 284  //- Return complete path + object name if the file exists // in the case directory otherwise null. Does not search // up if parallel. Can be overridden to provide this functionality // (e.g. IOdictionary) virtual fileName filePath() const; //- Read and check header info bool headerOk();  OpenFOAM-admin committed Apr 15, 2008 285  //- Return Istream and check object type against that given  Andrew Heather committed Jul 07, 2017 286  Istream& readStream(const word&, const bool valid = true);  OpenFOAM-admin committed Apr 15, 2008 287 288 289 290 291 292 293 294 295 296 297 298  //- Close Istream void close(); //- Virtual readData function. // Must be defined in derived types for which // re-reading is required virtual bool readData(Istream&); //- Read object virtual bool read();  Mark Olesen committed Jan 13, 2020 299 300  //- Add file watch for fileName on object if not yet watched. // \return index of watch  mattijs committed Jan 25, 2016 301 302 303 304  virtual label addWatch(const fileName&); //- Return file-monitoring handles inline const labelList& watchIndices() const;  mattijs committed Jun 02, 2010 305   mattijs committed Jan 25, 2016 306 307  //- Return file-monitoring handles inline labelList& watchIndices();  mattijs committed Jun 02, 2010 308 309  //- Return true if the object's file (or files for objectRegistry)  Mark Olesen committed Jan 13, 2020 310  //- have been modified. (modified state is cached by Time)  OpenFOAM-admin committed Apr 15, 2008 311 312  virtual bool modified() const;  mattijs committed Jun 02, 2010 313  //- Read object if modified (as set by call to modified)  OpenFOAM-admin committed Apr 15, 2008 314 315 316 317 318  virtual bool readIfModified(); // Writing  Andrew Heather committed Mar 28, 2018 319  //- Pure virtual writeData function.  OpenFOAM-admin committed Apr 15, 2008 320 321 322  // Must be defined in derived types virtual bool writeData(Ostream&) const = 0;  Mark Olesen committed Feb 19, 2020 323  //- Write using stream options  OpenFOAM-admin committed Apr 15, 2008 324 325  virtual bool writeObject (  Mark Olesen committed Feb 19, 2020 326  IOstreamOption streamOpt,  Andrew Heather committed Jul 07, 2017 327  const bool valid  OpenFOAM-admin committed Apr 15, 2008 328 329 330  ) const; //- Write using setting from DB  Andrew Heather committed Jul 07, 2017 331  virtual bool write(const bool valid = true) const;  OpenFOAM-admin committed Apr 15, 2008 332 333   mattijs committed Jan 25, 2016 334 335 336 337 338 339 340 341 342  // Other //- Is object global virtual bool global() const { return false; }  Mark Olesen committed Jan 13, 2020 343  // Member Operators  OpenFOAM-admin committed Apr 15, 2008 344   Mark Olesen committed Jan 13, 2020 345 346  //- Copy assignment void operator=(const IOobject& io);  Mark Olesen committed Feb 19, 2020 347 348 349 350 351 352 353 354 355 356 357 358 359  // Housekeeping //- Write using given format, version and compression FOAM_DEPRECATED_FOR(2020-02, "writeObject(IOstreamOption, bool)") virtual bool writeObject ( IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType comp, const bool valid ) const;  OpenFOAM-admin committed Apr 15, 2008 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "regIOobjectI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //