Commit 7ac55ac7 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: consolidate arch and version strings (issue #513)

- make some IOobject writing routines non-templated.

- relocate more IOobject methods into the IOobjectI.H
  (generally cleanup the main header).
parent e62e34f0
......@@ -45,6 +45,7 @@ Description
#include "fvMesh.H"
#include "cellModeller.H"
#include "globalFoam.H"
#include "foamVersion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -351,6 +351,12 @@ const Foam::Time& Foam::IOobject::time() const
}
const Foam::fileName& Foam::IOobject::rootPath() const
{
return time().rootPath();
}
const Foam::fileName& Foam::IOobject::caseName() const
{
return time().caseName();
......@@ -387,12 +393,6 @@ Foam::word Foam::IOobject::member() const
}
const Foam::fileName& Foam::IOobject::rootPath() const
{
return time().rootPath();
}
Foam::fileName Foam::IOobject::path() const
{
if (instance().isAbsolute())
......@@ -617,6 +617,8 @@ void Foam::IOobject::setBad(const string& s)
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::IOobject::operator=(const IOobject& io)
{
name_ = io.name_;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -191,6 +191,12 @@ public:
TypeName("IOobject");
// Static data members
//- Type of file modification checking
static fileCheckTypes fileModificationChecking;
// Static Member Functions
//- Split path into instance, local, name components
......@@ -202,11 +208,9 @@ public:
word& name
);
template<class Name>
static inline word groupName(Name name, const word& group);
//- Type of file modification checking
static fileCheckTypes fileModificationChecking;
//- Create dot-delimited name.group
template<class StringType>
static inline word groupName(StringType name, const word& group);
// Constructors
......@@ -280,214 +284,162 @@ public:
// Member Functions
// General access
// General access
//- Return the local objectRegistry
const objectRegistry& db() const;
//- Return time
const Time& time() const;
//- Return name
inline const word& name() const;
//- Return name of the class name read from header
inline const word& headerClassName() const;
//- Return the optional note
inline const string& note() const;
//- Return non-constant access to the optional note
inline string& note();
//- Rename
virtual void rename(const word& newName)
{
name_ = newName;
}
//- Register object created from this IOobject with registry if true
inline bool registerObject() const;
//- Register object created from this IOobject with registry if true
inline bool& registerObject();
//- Is object same for all processors
inline bool globalObject() const;
//- Is object same for all processors
inline bool& globalObject();
// Read/write options
//- Return time
const Time& time() const;
//- The read option
inline readOption readOpt() const;
//- Return the local objectRegistry
const objectRegistry& db() const;
//- Non-constant access to the read option
inline readOption& readOpt();
//- Return name
const word& name() const
{
return name_;
}
//- The write option
inline writeOption writeOpt() const;
//- Return name of the class name read from header
const word& headerClassName() const
{
return headerClassName_;
}
//- Return non-constant access to the optional note
string& note()
{
return note_;
}
//- Return the optional note
const string& note() const
{
return note_;
}
//- Rename
virtual void rename(const word& newName)
{
name_ = newName;
}
//- Register object created from this IOobject with registry if true
bool& registerObject()
{
return registerObject_;
}
//- Register object created from this IOobject with registry if true
bool registerObject() const
{
return registerObject_;
}
//- Is object same for all processors
bool& globalObject()
{
return globalObject_;
}
//- Is object same for all processors
bool globalObject() const
{
return globalObject_;
}
// Read/write options
readOption readOpt() const
{
return rOpt_;
}
readOption& readOpt()
{
return rOpt_;
}
writeOption writeOpt() const
{
return wOpt_;
}
writeOption& writeOpt()
{
return wOpt_;
}
//- Non-constant access to the write option
inline writeOption& writeOpt();
// Path components
//- Return group (extension part of name)
word group() const;
//- Return member (name without the extension)
word member() const;
// Path components
const fileName& rootPath() const;
//- Return group (extension part of name)
word group() const;
const fileName& caseName() const;
//- Return member (name without the extension)
word member() const;
const fileName& instance() const
{
return instance_;
}
fileName& instance()
{
return instance_;
}
const fileName& rootPath() const;
const fileName& local() const
{
return local_;
}
const fileName& caseName() const;
//- Return complete path
fileName path() const;
inline const fileName& instance() const;
//- Return complete path with alternative instance and local
fileName path
(
const word& instance,
const fileName& local = fileName::null
) const;
inline fileName& instance();
//- Return complete path + object name
fileName objectPath() const
{
return path()/name();
}
inline const fileName& local() const;
//- Helper for filePath that searches locally.
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName localFilePath(const bool search=true) const;
//- Return complete path
fileName path() const;
//- Helper for filePath that searches up if in parallel
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName globalFilePath(const bool search=true) const;
//- Return complete path with alternative instance and local
fileName path
(
const word& instance,
const fileName& local = fileName::null
) const;
//- Return complete path + object name
inline fileName objectPath() const;
//- Helper for filePath that searches locally.
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName localFilePath(const bool search=true) const;
//- Helper for filePath that searches up if in parallel
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName globalFilePath(const bool search=true) const;
// Reading
//- Read header
bool readHeader(Istream&);
// Reading
//- Read header (uses typeFilePath to find file) and check its info.
// Optionally checks headerClassName against the type-name.
// When search is false, simply use the current instance,
// otherwise search previous instances.
template<class Type>
bool typeHeaderOk
(
const bool checkType = true,
const bool search = true
);
//- Read header
bool readHeader(Istream& is);
//- Helper: warn that type does not support re-reading
template<class Type>
void warnNoRereading() const;
//- Read header (uses typeFilePath to find file) and check its info.
// Optionally checks headerClassName against the type-name.
// When search is false, simply use the current instance,
// otherwise search previous instances.
template<class Type>
bool typeHeaderOk
(
const bool checkType = true,
const bool search = true
);
// Writing
//- Helper: warn that type does not support re-reading
template<class Type>
void warnNoRereading() const;
//- Write the standard OpenFOAM file/dictionary banner
// Optionally without -*- C++ -*- editor hint (eg, for logs)
template<class Stream>
static inline Stream& writeBanner(Stream& os, bool noHint=false);
//- Write the standard file section divider
template<class Stream>
static inline Stream& writeDivider(Stream& os);
// Writing
//- Write the standard end file divider
template<class Stream>
static inline Stream& writeEndDivider(Stream& os);
//- Write the standard OpenFOAM file/dictionary banner
// Optionally without -*- C++ -*- editor hint (eg, for logs)
static Ostream& writeBanner(Ostream& os, bool noHint=false);
//- Write header
bool writeHeader(Ostream&) const;
//- Write the standard file section divider
static Ostream& writeDivider(Ostream& os);
//- Write header. Allow override of type
bool writeHeader(Ostream&, const word& objectType) const;
//- Write the standard end file divider
static Ostream& writeEndDivider(Ostream& os);
//- Write header
bool writeHeader(Ostream& os) const;
// Error Handling
//- Write header. Allow override of type
bool writeHeader(Ostream& os, const word& objectType) const;
bool good() const
{
return objState_ == GOOD;
}
bool bad() const
{
return objState_ == BAD;
}
// Error Handling
inline bool good() const;
// Info
inline bool bad() const;
//- Return info proxy.
// Used to print token information to a stream
InfoProxy<IOobject> info() const
{
return *this;
}
// Info
//- Return info proxy.
// Used to print token information to a stream
InfoProxy<IOobject> info() const
{
return *this;
}
// Member operators
void operator=(const IOobject&);
void operator=(const IOobject& io);
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -23,95 +23,137 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVersion.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Name>
inline Foam::word Foam::IOobject::groupName(Name name, const word& group)
template<class StringType>
inline Foam::word Foam::IOobject::groupName(StringType name, const word& group)
{
if (group != word::null)
if (group.empty())
{
return name + ('.' + group);
return name;
}
else
{
return name;
return name + ('.' + group);
}
}
template<class Stream>
inline Stream& Foam::IOobject::writeBanner(Stream& os, bool noHint)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// General access
inline const Foam::word& Foam::IOobject::name() const
{
static bool spacesSet(false);
static char spaces[40];
return name_;
}
if (!spacesSet)
{
memset(spaces, ' ', 40);
size_t len = strlen(Foam::FOAMversion);
if (len < 38)
{
spaces[38 - len] = '\0';
}
else
{
spaces[0] = '\0';
}
spacesSet = true;
}
if (noHint)
{
os <<
"/*--------------------------------------"
"-------------------------------------*\\\n";
}
else
{
os <<
"/*--------------------------------*- C++ "
"-*----------------------------------*\\\n";
}
inline const Foam::word& Foam::IOobject::headerClassName() const
{
return headerClassName_;
}
inline const Foam::string& Foam::IOobject::note() const
{
return note_;
}
inline Foam::string& Foam::IOobject::note()
{
return note_;
}
inline bool Foam::IOobject::registerObject() const
{
return registerObject_;
}
inline bool& Foam::IOobject::registerObject()
{
return registerObject_;
}
inline bool Foam::IOobject::globalObject() const
{
return globalObject_;
}
os <<
"| ========= |"
" |\n"
"| \\\\ / F ield |"
" OpenFOAM: The Open Source CFD Toolbox |\n"
"| \\\\ / O peration |"
" Version: " << FOAMversion << spaces << "|\n"
"| \\\\ / A nd |"
" Web: www.OpenFOAM.com |\n"
"| \\\\/ M anipulation |"
" |\n"
"\\*-----------------------------------------"
"----------------------------------*/\n";
return os;
inline bool& Foam::IOobject::globalObject()
{
return globalObject_;
}
template<class Stream>
inline Stream& Foam::IOobject::writeDivider(Stream& os)
// Read/write options
inline Foam::IOobject::readOption Foam::IOobject::readOpt() const
{
os <<
"// * * * * * * * * * * * * * * * * * "
"* * * * * * * * * * * * * * * * * * * * //\n";
return rOpt_;
}
return os;
inline Foam::IOobject::readOption& Foam::IOobject::readOpt()
{
return rOpt_;
}
template<class Stream>
inline Stream& Foam::IOobject::writeEndDivider(Stream& os)
inline Foam::IOobject::writeOption Foam::IOobject::writeOpt() const
{
os << "\n\n"
"// *****************************************"
"******************************** //\n";
return wOpt_;
}
inline Foam::IOobject::writeOption& Foam::IOobject::writeOpt()
{
return wOpt_;
}
// Path components
inline const Foam::fileName& Foam::IOobject::instance() const
{
return instance_;
}
return os;
inline Foam::fileName& Foam::IOobject::instance()
{
return instance_;
}
inline const Foam::fileName& Foam::IOobject::local() const
{
return local_;
}
inline Foam::fileName Foam::IOobject::objectPath() const
{
return path()/name();
}
// Error Handling
inline bool Foam::IOobject::good() const
{
return objState_ == GOOD;
}
inline bool Foam::IOobject::bad() const
{
return objState_ == BAD;