src/OpenFOAM: Rationalised use of enumerations by using the C++11 scoped form
for
db/functionObjects/timeControl/timeControl.H: timeControls
primitives/bools/Switch/Switch.H: class switchType
primitives/strings/fileName/fileName.H: fileType
primitives/strings/wordRe/wordRe.H: compOption
This commit is contained in:
@ -243,7 +243,7 @@ Foam::cvControls::cvControls
|
||||
|
||||
if (filterFaces_)
|
||||
{
|
||||
filterEdges_ = Switch::ON;
|
||||
filterEdges_ = Switch::switchType::on;
|
||||
}
|
||||
|
||||
writeTetDualMesh_ = Switch(filteringDict.lookup("writeTetDualMesh"));
|
||||
|
||||
@ -408,7 +408,7 @@ int main(int argc, char *argv[])
|
||||
fileHandler().readDir
|
||||
(
|
||||
lagrangianDirs[0],
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -328,7 +328,7 @@ int main(int argc, char *argv[])
|
||||
fileHandler().readDir
|
||||
(
|
||||
runTime.path(),
|
||||
fileName::Type::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
forAllReverse(dirs, diri)
|
||||
@ -661,7 +661,7 @@ int main(int argc, char *argv[])
|
||||
fileHandler().readDir
|
||||
(
|
||||
runTime.timePath()/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@ int main(int argc, char *argv[])
|
||||
cloudDirs = fileHandler().readDir
|
||||
(
|
||||
lagrangianDir,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -307,7 +307,7 @@ int main(int argc, char *argv[])
|
||||
fileNameList cloudDirs = readDir
|
||||
(
|
||||
runTime.timePath()/regionPrefix/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
);
|
||||
|
||||
forAll(cloudDirs, cloudI)
|
||||
@ -557,7 +557,7 @@ int main(int argc, char *argv[])
|
||||
fileNameList currentCloudDirs = readDir
|
||||
(
|
||||
runTime.timePath()/regionPrefix/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
);
|
||||
|
||||
bool cloudExists = inFileNameList(currentCloudDirs, cloudName);
|
||||
|
||||
@ -37,7 +37,7 @@ if (timeDirs.size())
|
||||
/ timeDirs.last().name()
|
||||
/ regionPrefix
|
||||
/ cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
);
|
||||
|
||||
forAll(cloudDirs, cloudI)
|
||||
|
||||
@ -1213,7 +1213,7 @@ int main(int argc, char *argv[])
|
||||
readDir
|
||||
(
|
||||
runTime.timePath()/regionPrefix/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -446,7 +446,7 @@ int main(int argc, char *argv[])
|
||||
readDir
|
||||
(
|
||||
runTime.timePath()/regionPrefix/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
forAll(cloudDirs, i)
|
||||
@ -1210,14 +1210,14 @@ int main(int argc, char *argv[])
|
||||
/"VTK"
|
||||
);
|
||||
|
||||
fileNameList dirs(readDir(procVTK, fileName::DIRECTORY));
|
||||
fileNameList dirs(readDir(procVTK, fileType::directory));
|
||||
label sz = dirs.size();
|
||||
dirs.setSize(sz+1);
|
||||
dirs[sz] = ".";
|
||||
|
||||
forAll(dirs, i)
|
||||
{
|
||||
fileNameList subFiles(readDir(procVTK/dirs[i], fileName::FILE));
|
||||
fileNameList subFiles(readDir(procVTK/dirs[i], fileType::file));
|
||||
|
||||
forAll(subFiles, j)
|
||||
{
|
||||
|
||||
@ -48,7 +48,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
#include "createTime.H"
|
||||
|
||||
fileNameList fieldNames = readDir(runTime.timePath(), fileName::FILE);
|
||||
fileNameList fieldNames = readDir(runTime.timePath(), fileType::file);
|
||||
dictionary fieldNameDict;
|
||||
forAll(fieldNames, i)
|
||||
{
|
||||
|
||||
@ -202,7 +202,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian
|
||||
readDir
|
||||
(
|
||||
dbPtr_->path()/times[timei].name()/lagrangianPrefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ void mapLagrangian(const meshToMesh0& meshToMesh0Interp)
|
||||
readDir
|
||||
(
|
||||
meshSource.time().timePath()/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ void mapLagrangian(const meshToMesh& interp)
|
||||
readDir
|
||||
(
|
||||
meshSource.time().timePath()/cloud::prefix,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@ -483,7 +483,7 @@ mode_t Foam::mode
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::Type Foam::type
|
||||
Foam::fileType Foam::type
|
||||
(
|
||||
const fileName& name,
|
||||
const bool checkVariants,
|
||||
@ -498,19 +498,19 @@ Foam::fileName::Type Foam::type
|
||||
|
||||
if (S_ISREG(m))
|
||||
{
|
||||
return fileName::FILE;
|
||||
return fileType::file;
|
||||
}
|
||||
else if (S_ISLNK(m))
|
||||
{
|
||||
return fileName::LINK;
|
||||
return fileType::link;
|
||||
}
|
||||
else if (S_ISDIR(m))
|
||||
{
|
||||
return fileName::DIRECTORY;
|
||||
return fileType::directory;
|
||||
}
|
||||
else
|
||||
{
|
||||
return fileName::UNDEFINED;
|
||||
return fileType::undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,7 +660,7 @@ double Foam::highResLastModified
|
||||
Foam::fileNameList Foam::readDir
|
||||
(
|
||||
const fileName& directory,
|
||||
const fileName::Type type,
|
||||
const fileType type,
|
||||
const bool filterVariants,
|
||||
const bool followLink
|
||||
)
|
||||
@ -714,10 +714,10 @@ Foam::fileNameList Foam::readDir
|
||||
|
||||
if
|
||||
(
|
||||
(type == fileName::DIRECTORY)
|
||||
(type == fileType::directory)
|
||||
||
|
||||
(
|
||||
type == fileName::FILE
|
||||
type == fileType::file
|
||||
&& fName[fName.size()-1] != '~'
|
||||
&& fExt != "bak"
|
||||
&& fExt != "BAK"
|
||||
@ -777,15 +777,15 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
return false;
|
||||
}
|
||||
|
||||
const fileName::Type srcType = src.type(false, followLink);
|
||||
const fileType srcType = src.type(false, followLink);
|
||||
|
||||
fileName destFile(dest);
|
||||
|
||||
// Check type of source file.
|
||||
if (srcType == fileName::FILE)
|
||||
if (srcType == fileType::file)
|
||||
{
|
||||
// If dest is a directory, create the destination file name.
|
||||
if (destFile.type() == fileName::DIRECTORY)
|
||||
if (destFile.type() == fileType::directory)
|
||||
{
|
||||
destFile = destFile/src.name();
|
||||
}
|
||||
@ -822,10 +822,10 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (srcType == fileName::LINK)
|
||||
else if (srcType == fileType::link)
|
||||
{
|
||||
// If dest is a directory, create the destination file name.
|
||||
if (destFile.type() == fileName::DIRECTORY)
|
||||
if (destFile.type() == fileType::directory)
|
||||
{
|
||||
destFile = destFile/src.name();
|
||||
}
|
||||
@ -838,10 +838,10 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
|
||||
ln(src, destFile);
|
||||
}
|
||||
else if (srcType == fileName::DIRECTORY)
|
||||
else if (srcType == fileType::directory)
|
||||
{
|
||||
// If dest is a directory, create the destination file name.
|
||||
if (destFile.type() == fileName::DIRECTORY)
|
||||
if (destFile.type() == fileType::directory)
|
||||
{
|
||||
destFile = destFile/src.component(src.components().size() -1);
|
||||
}
|
||||
@ -879,7 +879,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
}
|
||||
|
||||
// Copy files
|
||||
fileNameList contents = readDir(src, fileName::FILE, false, followLink);
|
||||
fileNameList contents = readDir(src, fileType::file, false, followLink);
|
||||
forAll(contents, i)
|
||||
{
|
||||
if (POSIX::debug)
|
||||
@ -897,7 +897,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
fileNameList subdirs = readDir
|
||||
(
|
||||
src,
|
||||
fileName::DIRECTORY,
|
||||
fileType::directory,
|
||||
false,
|
||||
followLink
|
||||
);
|
||||
@ -975,8 +975,8 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
|
||||
|
||||
if
|
||||
(
|
||||
dst.type() == fileName::DIRECTORY
|
||||
&& src.type(false, followLink) != fileName::DIRECTORY
|
||||
dst.type() == fileType::directory
|
||||
&& src.type(false, followLink) != fileType::directory
|
||||
)
|
||||
{
|
||||
const fileName dstName(dst/src.name());
|
||||
@ -1098,7 +1098,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
{
|
||||
fileName path = directory/fName;
|
||||
|
||||
if (path.type(false, false) == fileName::DIRECTORY)
|
||||
if (path.type(false, false) == fileType::directory)
|
||||
{
|
||||
if (!rmDir(path))
|
||||
{
|
||||
|
||||
@ -62,14 +62,14 @@ Foam::OFstreamAllocator::OFstreamAllocator
|
||||
if (compression == IOstream::COMPRESSED)
|
||||
{
|
||||
// Get identically named uncompressed version out of the way
|
||||
fileName::Type pathType = Foam::type(pathname, false, false);
|
||||
if (pathType == fileName::FILE || pathType == fileName::LINK)
|
||||
fileType pathType = Foam::type(pathname, false, false);
|
||||
if (pathType == fileType::file || pathType == fileType::link)
|
||||
{
|
||||
rm(pathname);
|
||||
}
|
||||
fileName gzPathName(pathname + ".gz");
|
||||
|
||||
if (!append && Foam::type(gzPathName) == fileName::LINK)
|
||||
if (!append && Foam::type(gzPathName) == fileType::link)
|
||||
{
|
||||
// Disallow writing into softlink to avoid any problems with
|
||||
// e.g. softlinked initial fields
|
||||
@ -82,15 +82,15 @@ Foam::OFstreamAllocator::OFstreamAllocator
|
||||
{
|
||||
// get identically named compressed version out of the way
|
||||
fileName gzPathName(pathname + ".gz");
|
||||
fileName::Type gzType = Foam::type(gzPathName, false, false);
|
||||
if (gzType == fileName::FILE || gzType == fileName::LINK)
|
||||
fileType gzType = Foam::type(gzPathName, false, false);
|
||||
if (gzType == fileType::file || gzType == fileType::link)
|
||||
{
|
||||
rm(gzPathName);
|
||||
}
|
||||
if
|
||||
(
|
||||
!append
|
||||
&& Foam::type(pathname, false, false) == fileName::LINK
|
||||
&& Foam::type(pathname, false, false) == fileType::link
|
||||
)
|
||||
{
|
||||
// Disallow writing into softlink to avoid any problems with
|
||||
|
||||
@ -92,7 +92,7 @@ void Foam::functionObjectList::listDir
|
||||
|
||||
// Recurse into sub-directories
|
||||
{
|
||||
fileNameList foDirs(fileHandler().readDir(dir, fileName::DIRECTORY));
|
||||
fileNameList foDirs(fileHandler().readDir(dir, fileType::directory));
|
||||
forAll(foDirs, fd)
|
||||
{
|
||||
listDir(dir/foDirs[fd], foMap);
|
||||
|
||||
@ -60,7 +60,7 @@ Foam::timeControl::timeControl
|
||||
:
|
||||
time_(t),
|
||||
prefix_(prefix),
|
||||
timeControl_(ocTimeStep),
|
||||
timeControl_(timeControls::timeStep),
|
||||
intervalSteps_(0),
|
||||
interval_(-1),
|
||||
executionIndex_(0)
|
||||
@ -102,28 +102,28 @@ void Foam::timeControl::read(const dictionary& dict)
|
||||
}
|
||||
else
|
||||
{
|
||||
timeControl_ = ocTimeStep;
|
||||
timeControl_ = timeControls::timeStep;
|
||||
}
|
||||
|
||||
switch (timeControl_)
|
||||
{
|
||||
case ocTimeStep:
|
||||
case timeControls::timeStep:
|
||||
{
|
||||
intervalSteps_ = dict.lookupOrDefault<label>(intervalName, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case ocWriteTime:
|
||||
case ocOutputTime:
|
||||
case timeControls::writeTime:
|
||||
case timeControls::outputTime:
|
||||
{
|
||||
intervalSteps_ = dict.lookupOrDefault<label>(intervalName, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ocClockTime:
|
||||
case ocRunTime:
|
||||
case ocCpuTime:
|
||||
case ocAdjustableRunTime:
|
||||
case timeControls::clockTime:
|
||||
case timeControls::runTime:
|
||||
case timeControls::cpuTime:
|
||||
case timeControls::adjustableRunTime:
|
||||
{
|
||||
interval_ = readScalar(dict.lookup(intervalName));
|
||||
break;
|
||||
@ -141,7 +141,7 @@ bool Foam::timeControl::execute()
|
||||
{
|
||||
switch (timeControl_)
|
||||
{
|
||||
case ocTimeStep:
|
||||
case timeControls::timeStep:
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -151,8 +151,8 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case ocWriteTime:
|
||||
case ocOutputTime:
|
||||
case timeControls::writeTime:
|
||||
case timeControls::outputTime:
|
||||
{
|
||||
if (time_.writeTime())
|
||||
{
|
||||
@ -162,8 +162,8 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case ocRunTime:
|
||||
case ocAdjustableRunTime:
|
||||
case timeControls::runTime:
|
||||
case timeControls::adjustableRunTime:
|
||||
{
|
||||
label executionIndex = label
|
||||
(
|
||||
@ -182,7 +182,7 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case ocCpuTime:
|
||||
case timeControls::cpuTime:
|
||||
{
|
||||
label executionIndex = label
|
||||
(
|
||||
@ -197,7 +197,7 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case ocClockTime:
|
||||
case timeControls::clockTime:
|
||||
{
|
||||
label executionIndex = label
|
||||
(
|
||||
@ -212,7 +212,7 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case ocNone:
|
||||
case timeControls::none:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -52,16 +52,16 @@ class timeControl
|
||||
public:
|
||||
|
||||
//- The time control options
|
||||
enum timeControls
|
||||
enum class timeControls
|
||||
{
|
||||
ocTimeStep, //!< execution is coupled to the time-step
|
||||
ocWriteTime, //!< execution is coupled to the write-time
|
||||
ocOutputTime, //!< execution is coupled to the output-time
|
||||
ocAdjustableRunTime, //!< Adjust time step for execution
|
||||
ocRunTime, //!< run time for execution
|
||||
ocClockTime, //!< clock time for execution
|
||||
ocCpuTime, //!< cpu time for execution
|
||||
ocNone //!< no execution
|
||||
timeStep, //!< execution is coupled to the time-step
|
||||
writeTime, //!< execution is coupled to the write-time
|
||||
outputTime, //!< execution is coupled to the output-time
|
||||
adjustableRunTime, //!< Adjust time step for execution
|
||||
runTime, //!< run time for execution
|
||||
clockTime, //!< clock time for execution
|
||||
cpuTime, //!< cpu time for execution
|
||||
none //!< no execution
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -124,7 +124,8 @@ Foam::scalar Foam::functionObjects::timeControl::timeToNextWrite()
|
||||
if
|
||||
(
|
||||
active()
|
||||
&& writeControl_.control() == Foam::timeControl::ocAdjustableRunTime
|
||||
&& writeControl_.control() ==
|
||||
Foam::timeControl::timeControls::adjustableRunTime
|
||||
)
|
||||
{
|
||||
const label writeTimeIndex = writeControl_.executionIndex();
|
||||
|
||||
@ -96,7 +96,7 @@ bool Foam::functionObjects::writeLocalObjects::read(const dictionary& dict)
|
||||
}
|
||||
else
|
||||
{
|
||||
resetWriteObjectName(wordRe(".*", wordRe::DETECT));
|
||||
resetWriteObjectName(wordRe(".*", wordRe::compOption::detect));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -272,7 +272,7 @@ Foam::fileOperation::lookupProcessorsPath(const fileName& fName) const
|
||||
|
||||
// Note: use parallel synchronised reading so cache will be same
|
||||
// order on all processors
|
||||
fileNameList dirNames(readDir(path, fileName::Type::DIRECTORY));
|
||||
fileNameList dirNames(readDir(path, fileType::directory));
|
||||
|
||||
// Extract info from processorsDDD or processorDDD:
|
||||
// - highest processor number
|
||||
@ -687,7 +687,7 @@ Foam::instantList Foam::fileOperation::findTimes
|
||||
Foam::readDir
|
||||
(
|
||||
directory,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
|
||||
@ -707,7 +707,7 @@ Foam::instantList Foam::fileOperation::findTimes
|
||||
Foam::readDir
|
||||
(
|
||||
collDir,
|
||||
fileName::DIRECTORY
|
||||
fileType::directory
|
||||
)
|
||||
);
|
||||
mergeTimes
|
||||
@ -902,7 +902,7 @@ Foam::fileNameList Foam::fileOperation::readObjects
|
||||
if (Foam::isDir(path))
|
||||
{
|
||||
newInstance = instance;
|
||||
objectNames = Foam::readDir(path, fileName::FILE);
|
||||
objectNames = Foam::readDir(path, fileType::file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -912,7 +912,7 @@ Foam::fileNameList Foam::fileOperation::readObjects
|
||||
if (!procsPath.empty())
|
||||
{
|
||||
newInstance = instance;
|
||||
objectNames = Foam::readDir(procsPath, fileName::FILE);
|
||||
objectNames = Foam::readDir(procsPath, fileType::file);
|
||||
}
|
||||
}
|
||||
return objectNames;
|
||||
@ -932,7 +932,7 @@ Foam::label Foam::fileOperation::nProcs
|
||||
label nProcs = 0;
|
||||
if (Pstream::master(comm_))
|
||||
{
|
||||
fileNameList dirNames(Foam::readDir(dir, fileName::Type::DIRECTORY));
|
||||
fileNameList dirNames(Foam::readDir(dir, fileType::directory));
|
||||
|
||||
// Detect any processorsDDD or processorDDD
|
||||
label maxProc = -1;
|
||||
@ -1233,7 +1233,7 @@ Foam::fileName Foam::search(const word& file, const fileName& directory)
|
||||
}
|
||||
|
||||
// If not found search each of the sub-directories
|
||||
fileNameList dirs(fileHandler().readDir(directory, fileName::DIRECTORY));
|
||||
fileNameList dirs(fileHandler().readDir(directory, fileType::directory));
|
||||
forAll(dirs, i)
|
||||
{
|
||||
fileName path = search(file, directory/dirs[i]);
|
||||
@ -1251,7 +1251,7 @@ void Foam::cpFiles(const fileName& srcDir, const fileName& targetDir)
|
||||
{
|
||||
mkDir(targetDir);
|
||||
|
||||
const fileNameList srcFiles(readDir(srcDir, fileName::FILE, true));
|
||||
const fileNameList srcFiles(readDir(srcDir, fileType::file, true));
|
||||
|
||||
forAll(srcFiles, filei)
|
||||
{
|
||||
|
||||
@ -202,15 +202,15 @@ public:
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
virtual fileName::Type type
|
||||
//- Return the file type: directory, file or link
|
||||
virtual fileType type
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkVariants = true,
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
//- Does the name exist (as directory or file) in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool exists
|
||||
(
|
||||
@ -219,14 +219,14 @@ public:
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
//- Does the name exist as a directory in the file system?
|
||||
virtual bool isDir
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
//- Does the name exist as a FILE in the file system?
|
||||
//- Does the name exist as a file in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool isFile
|
||||
(
|
||||
@ -263,7 +263,7 @@ public:
|
||||
virtual fileNameList readDir
|
||||
(
|
||||
const fileName&,
|
||||
const fileName::Type=fileName::FILE,
|
||||
const fileType = fileType::file,
|
||||
const bool filterVariants = true,
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
@ -889,14 +889,14 @@ mode_t Foam::fileOperations::masterUncollatedFileOperation::mode
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::Type Foam::fileOperations::masterUncollatedFileOperation::type
|
||||
Foam::fileType Foam::fileOperations::masterUncollatedFileOperation::type
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool checkVariants,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
return fileName::Type
|
||||
return fileType
|
||||
(
|
||||
masterOp<label, typeOp>
|
||||
(
|
||||
@ -1059,7 +1059,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::rmDir
|
||||
Foam::fileNameList Foam::fileOperations::masterUncollatedFileOperation::readDir
|
||||
(
|
||||
const fileName& dir,
|
||||
const fileName::Type type,
|
||||
const fileType type,
|
||||
const bool filtergz,
|
||||
const bool followLink
|
||||
) const
|
||||
|
||||
@ -156,7 +156,7 @@ protected:
|
||||
|
||||
label operator()(const fileName& fName) const
|
||||
{
|
||||
return Foam::type(fName, checkVariants_, followLink_);
|
||||
return label(Foam::type(fName, checkVariants_, followLink_));
|
||||
}
|
||||
};
|
||||
|
||||
@ -371,13 +371,15 @@ protected:
|
||||
|
||||
class readDirOp
|
||||
{
|
||||
const fileName::Type type_;
|
||||
const fileType type_;
|
||||
const bool filterVariants_;
|
||||
const bool followLink_;
|
||||
|
||||
public:
|
||||
|
||||
readDirOp
|
||||
(
|
||||
const fileName::Type type,
|
||||
const fileType type,
|
||||
const bool filterVariants,
|
||||
const bool followLink
|
||||
)
|
||||
@ -389,14 +391,13 @@ protected:
|
||||
|
||||
fileNameList operator()(const fileName& fName) const
|
||||
{
|
||||
return
|
||||
Foam::readDir
|
||||
(
|
||||
fName,
|
||||
type_,
|
||||
filterVariants_,
|
||||
followLink_
|
||||
);
|
||||
return Foam::readDir
|
||||
(
|
||||
fName,
|
||||
type_,
|
||||
filterVariants_,
|
||||
followLink_
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -530,15 +531,15 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
virtual fileName::Type type
|
||||
//- Return the file type: directory, file or link
|
||||
virtual fileType type
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkVariants = true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
//- Does the name exist (as directory or file) in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool exists
|
||||
(
|
||||
@ -547,14 +548,14 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
//- Does the name exist as a directory in the file system?
|
||||
virtual bool isDir
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist as a FILE in the file system?
|
||||
//- Does the name exist as a file in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool isFile
|
||||
(
|
||||
@ -591,7 +592,7 @@ public:
|
||||
virtual fileNameList readDir
|
||||
(
|
||||
const fileName&,
|
||||
const fileName::Type=fileName::FILE,
|
||||
const fileType = fileType::file,
|
||||
const bool filterVariants = true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
@ -214,7 +214,7 @@ mode_t Foam::fileOperations::uncollatedFileOperation::mode
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::Type Foam::fileOperations::uncollatedFileOperation::type
|
||||
Foam::fileType Foam::fileOperations::uncollatedFileOperation::type
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool checkVariants,
|
||||
@ -321,7 +321,7 @@ bool Foam::fileOperations::uncollatedFileOperation::rmDir
|
||||
Foam::fileNameList Foam::fileOperations::uncollatedFileOperation::readDir
|
||||
(
|
||||
const fileName& dir,
|
||||
const fileName::Type type,
|
||||
const fileType type,
|
||||
const bool filtergz,
|
||||
const bool followLink
|
||||
) const
|
||||
|
||||
@ -97,15 +97,15 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
virtual fileName::Type type
|
||||
//- Return the file type: directory, file or link
|
||||
virtual fileType type
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkVariants = true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
//- Does the name exist (as directory or file) in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool exists
|
||||
(
|
||||
@ -114,7 +114,7 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
//- Does the name exist as a directory in the file system?
|
||||
virtual bool isDir
|
||||
(
|
||||
const fileName&,
|
||||
@ -158,7 +158,7 @@ public:
|
||||
virtual fileNameList readDir
|
||||
(
|
||||
const fileName&,
|
||||
const fileName::Type=fileName::FILE,
|
||||
const fileType = fileType::file,
|
||||
const bool filtergz=true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
@ -107,15 +107,15 @@ mode_t mode
|
||||
const bool followLink = true
|
||||
);
|
||||
|
||||
//- Return the file type: DIRECTORY or FILE
|
||||
fileName::Type type
|
||||
//- Return the file type: directory or file
|
||||
fileType type
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkVariants = true,
|
||||
const bool followLink = true
|
||||
);
|
||||
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
//- Does the name exist (as directory or file) in the file system?
|
||||
// Optionally enable/disable check for variant files.
|
||||
bool exists
|
||||
(
|
||||
@ -124,10 +124,10 @@ bool exists
|
||||
const bool followLink = true
|
||||
);
|
||||
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
//- Does the name exist as a directory in the file system?
|
||||
bool isDir(const fileName&, const bool followLink = true);
|
||||
|
||||
//- Does the name exist as a FILE in the file system?
|
||||
//- Does the name exist as a file in the file system?
|
||||
// Optionally enable/disable check for variant files.
|
||||
bool isFile
|
||||
(
|
||||
@ -164,7 +164,7 @@ double highResLastModified
|
||||
fileNameList readDir
|
||||
(
|
||||
const fileName&,
|
||||
const fileName::Type=fileName::FILE,
|
||||
const fileType = fileType::file,
|
||||
const bool filterVariants = true,
|
||||
const bool followLink = true
|
||||
);
|
||||
|
||||
@ -24,19 +24,24 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Switch.H"
|
||||
#include "error.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
|
||||
const char* Foam::Switch::names[nSwitchType] =
|
||||
{
|
||||
"false", "true",
|
||||
"off", "on",
|
||||
"no", "yes",
|
||||
"n", "y",
|
||||
"f", "t",
|
||||
"none", "true", // Is there a reasonable counterpart to "none"?
|
||||
"false",
|
||||
"true",
|
||||
"off",
|
||||
"on",
|
||||
"no",
|
||||
"yes",
|
||||
"n",
|
||||
"y",
|
||||
"f",
|
||||
"t",
|
||||
"none",
|
||||
"any",
|
||||
"invalid"
|
||||
};
|
||||
|
||||
@ -49,35 +54,36 @@ Foam::Switch::switchType Foam::Switch::asEnum
|
||||
const bool allowInvalid
|
||||
)
|
||||
{
|
||||
for (int sw = 0; sw < Switch::INVALID; ++sw)
|
||||
for (switchType sw=switchType::False; sw<switchType::invalid; ++sw)
|
||||
{
|
||||
if (str == names[sw])
|
||||
if (str == names[toInt(sw)])
|
||||
{
|
||||
// handle aliases
|
||||
// Handle aliases
|
||||
switch (sw)
|
||||
{
|
||||
case Switch::NO_1:
|
||||
case Switch::NONE:
|
||||
case switchType::n:
|
||||
case switchType::none:
|
||||
{
|
||||
return Switch::NO;
|
||||
return switchType::no;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::YES_1:
|
||||
case switchType::y:
|
||||
case switchType::any:
|
||||
{
|
||||
return Switch::YES;
|
||||
return switchType::yes;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::FALSE_1:
|
||||
case switchType::f:
|
||||
{
|
||||
return Switch::FALSE;
|
||||
return switchType::False;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::TRUE_1:
|
||||
case switchType::t:
|
||||
{
|
||||
return Switch::TRUE;
|
||||
return switchType::True;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,7 +103,7 @@ Foam::Switch::switchType Foam::Switch::asEnum
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return Switch::INVALID;
|
||||
return switchType::invalid;
|
||||
}
|
||||
|
||||
|
||||
@ -116,13 +122,13 @@ Foam::Switch Foam::Switch::lookupOrAddToDict
|
||||
|
||||
bool Foam::Switch::valid() const
|
||||
{
|
||||
return switch_ <= Switch::NONE;
|
||||
return switch_ <= switchType::none;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::Switch::asText() const
|
||||
{
|
||||
return names[switch_];
|
||||
return names[toInt(switch_)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ Class
|
||||
|
||||
Description
|
||||
A simple wrapper around bool so that it can be read as a word:
|
||||
true/false, on/off, yes/no, y/n, t/f, or none.
|
||||
true/false, on/off, yes/no, y/n, t/f, or none/any.
|
||||
|
||||
SourceFiles
|
||||
Switch.C
|
||||
@ -60,52 +60,61 @@ Ostream& operator<<(Ostream&, const Switch&);
|
||||
|
||||
class Switch
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- The logic and enumerated text representation stored as a single byte
|
||||
unsigned char switch_;
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
// avoid issues with pre-processor defines
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#undef OFF
|
||||
#undef ON
|
||||
#undef NO
|
||||
#undef YES
|
||||
#undef NO_1
|
||||
#undef YES_1
|
||||
#undef FALSE_1
|
||||
#undef TRUE_1
|
||||
#undef NONE
|
||||
#undef PLACEHOLDER
|
||||
#undef INVALID
|
||||
|
||||
//- The various text representations for a switch value.
|
||||
// These also correspond to the entries in names.
|
||||
enum switchType
|
||||
enum class switchType : unsigned char
|
||||
{
|
||||
FALSE = 0, TRUE = 1,
|
||||
OFF = 2, ON = 3,
|
||||
NO = 4, YES = 5,
|
||||
NO_1 = 6, YES_1 = 7,
|
||||
FALSE_1 = 8, TRUE_1 = 9,
|
||||
NONE = 10, PLACEHOLDER = 11,
|
||||
INVALID
|
||||
False = 0,
|
||||
True = 1,
|
||||
off = 2,
|
||||
on = 3,
|
||||
no = 4,
|
||||
yes = 5,
|
||||
n = 6,
|
||||
y = 7,
|
||||
f = 8,
|
||||
t = 9,
|
||||
none = 10,
|
||||
any = 11,
|
||||
invalid
|
||||
};
|
||||
|
||||
//- Number of switchTypes
|
||||
static const unsigned char nSwitchType =
|
||||
static_cast<unsigned char>(switchType::invalid) + 1;
|
||||
|
||||
//- Convert switchType to integer (unsigned char)
|
||||
inline static unsigned char toInt(const switchType x)
|
||||
{
|
||||
return static_cast<unsigned char>(x);
|
||||
}
|
||||
|
||||
//- Increment the switchType counter
|
||||
inline friend switchType operator++(switchType& x)
|
||||
{
|
||||
return x = switchType(toInt(x) + 1);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- The logic and enumerated text representation stored as a single byte
|
||||
switchType switch_;
|
||||
|
||||
|
||||
// Static data members
|
||||
|
||||
//- The set of names corresponding to the switchType enumeration
|
||||
// Includes an extra entry for "invalid".
|
||||
static const char* names[INVALID+1];
|
||||
static const char* names[nSwitchType];
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Return a switchType representation of a word
|
||||
@ -119,7 +128,7 @@ public:
|
||||
//- Construct null as false
|
||||
Switch()
|
||||
:
|
||||
switch_(Switch::FALSE)
|
||||
switch_(switchType::False)
|
||||
{}
|
||||
|
||||
//- Construct from enumerated value
|
||||
@ -131,13 +140,13 @@ public:
|
||||
//- Construct from bool
|
||||
Switch(const bool b)
|
||||
:
|
||||
switch_(b ? Switch::TRUE : Switch::FALSE)
|
||||
switch_(b ? switchType::True : switchType::False)
|
||||
{}
|
||||
|
||||
//- Construct from integer values (treats integer as bool value)
|
||||
Switch(const int i)
|
||||
:
|
||||
switch_(i ? Switch::TRUE : Switch::FALSE)
|
||||
switch_(i ? switchType::True : switchType::False)
|
||||
{}
|
||||
|
||||
//- Construct from std::string, string, word
|
||||
@ -184,7 +193,7 @@ public:
|
||||
//- Conversion to bool
|
||||
operator bool() const
|
||||
{
|
||||
return (switch_ & 0x1);
|
||||
return (toInt(switch_) & 0x1);
|
||||
}
|
||||
|
||||
//- Assignment to enumerated value
|
||||
@ -196,7 +205,7 @@ public:
|
||||
//- Assignment to bool
|
||||
void operator=(const bool b)
|
||||
{
|
||||
switch_ = (b ? Switch::TRUE : Switch::FALSE);
|
||||
switch_ = (b ? switchType::True : switchType::False);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const Switch& s)
|
||||
{
|
||||
os << Switch::names[s.switch_];
|
||||
os << Switch::names[int(s.switch_)];
|
||||
os.check("Ostream& operator<<(Ostream&, const Switch&)");
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ Foam::fileName::fileName(const wordList& lst)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName::Type Foam::fileName::type
|
||||
Foam::fileType Foam::fileName::type
|
||||
(
|
||||
const bool checkVariants,
|
||||
const bool followLink
|
||||
|
||||
@ -63,6 +63,16 @@ Istream& operator>>(Istream&, fileName&);
|
||||
Ostream& operator<<(Ostream&, const fileName&);
|
||||
|
||||
|
||||
//- Enumeration of file types
|
||||
enum class fileType
|
||||
{
|
||||
undefined,
|
||||
file,
|
||||
directory,
|
||||
link
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fileName Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -79,16 +89,6 @@ class fileName
|
||||
|
||||
public:
|
||||
|
||||
//- Enumerations to handle file types and modes.
|
||||
enum Type
|
||||
{
|
||||
UNDEFINED,
|
||||
FILE,
|
||||
DIRECTORY,
|
||||
LINK
|
||||
};
|
||||
|
||||
|
||||
// Static data members
|
||||
|
||||
static const char* const typeName;
|
||||
@ -154,9 +154,9 @@ public:
|
||||
|
||||
// Interrogation
|
||||
|
||||
//- Return the file type: FILE, DIRECTORY, UNDEFINED or
|
||||
// LINK (only if followLink=false)
|
||||
Type type
|
||||
//- Return the file type: file, directory, undefined or
|
||||
// link (only if followLink=false)
|
||||
fileType type
|
||||
(
|
||||
const bool checkVariants = true,
|
||||
const bool followLink = true
|
||||
|
||||
@ -28,10 +28,10 @@ Description
|
||||
A wordRe is a word, but can also have a regular expression for matching
|
||||
words.
|
||||
|
||||
By default the constructors will generally preserve the argument as a
|
||||
string literal and the assignment operators will use the wordRe::DETECT
|
||||
compOption to scan the string for regular expression meta characters
|
||||
and/or invalid word characters and react accordingly.
|
||||
By default the constructors will generally preserve the argument as a string
|
||||
literal and the assignment operators will use the wordRe::compOption::detect
|
||||
compOption to scan the string for regular expression meta characters and/or
|
||||
invalid word characters and react accordingly.
|
||||
|
||||
The exceptions are when constructing/assigning from another
|
||||
Foam::wordRe (preserve the same type) or from a Foam::word (always
|
||||
@ -92,15 +92,15 @@ public:
|
||||
// Public data types
|
||||
|
||||
//- Enumeration with compile options
|
||||
// Note that 'REGEXP' is implicit if 'NOCASE' is specified alone.
|
||||
enum compOption
|
||||
// Note that 'regexp' is implicit if 'noCase' is specified alone.
|
||||
enum class compOption
|
||||
{
|
||||
LITERAL = 0, //!< treat as a string literal
|
||||
DETECT = 1, //!< detect if the string contains meta-characters
|
||||
REGEXP = 2, //!< treat as regular expression
|
||||
NOCASE = 4, //!< ignore case in regular expression
|
||||
DETECT_NOCASE = DETECT | NOCASE,
|
||||
REGEXP_NOCASE = REGEXP | NOCASE
|
||||
literal = 0, //!< treat as a string literal
|
||||
detect = 1, //!< detect if the string contains meta-characters
|
||||
regExp = 2, //!< treat as regular expression
|
||||
noCase = 4, //!< ignore case in regular expression
|
||||
detectNoCase = detect | noCase,
|
||||
regExpNoCase = regExp | noCase
|
||||
};
|
||||
|
||||
|
||||
@ -130,15 +130,27 @@ public:
|
||||
|
||||
//- Construct as copy of character array
|
||||
// Optionally specify how it should be treated.
|
||||
inline explicit wordRe(const char*, const compOption = LITERAL);
|
||||
inline explicit wordRe
|
||||
(
|
||||
const char*,
|
||||
const compOption = compOption::literal
|
||||
);
|
||||
|
||||
//- Construct as copy of string.
|
||||
// Optionally specify how it should be treated.
|
||||
inline explicit wordRe(const string&, const compOption = LITERAL);
|
||||
inline explicit wordRe
|
||||
(
|
||||
const string&,
|
||||
const compOption = compOption::literal
|
||||
);
|
||||
|
||||
//- Construct as copy of std::string
|
||||
// Optionally specify how it should be treated.
|
||||
inline explicit wordRe(const std::string&, const compOption = LITERAL);
|
||||
inline explicit wordRe
|
||||
(
|
||||
const std::string&,
|
||||
const compOption = compOption::literal
|
||||
);
|
||||
|
||||
//- Construct from Istream
|
||||
// Words are treated as literals, strings with an auto-test
|
||||
@ -172,10 +184,18 @@ public:
|
||||
// Editing
|
||||
|
||||
//- Copy string, auto-test for regular expression or other options
|
||||
inline void set(const std::string&, const compOption = DETECT);
|
||||
inline void set
|
||||
(
|
||||
const std::string&,
|
||||
const compOption = compOption::detect
|
||||
);
|
||||
|
||||
//- Copy string, auto-test for regular expression or other options
|
||||
inline void set(const char*, const compOption = DETECT);
|
||||
inline void set
|
||||
(
|
||||
const char*,
|
||||
const compOption = compOption::detect
|
||||
);
|
||||
|
||||
//- Clear string and precompiled regular expression
|
||||
inline void clear();
|
||||
@ -236,6 +256,13 @@ public:
|
||||
};
|
||||
|
||||
|
||||
inline int operator&
|
||||
(
|
||||
const wordRe::compOption co1,
|
||||
const wordRe::compOption co2
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -128,18 +128,18 @@ inline bool Foam::wordRe::compile(const compOption opt) const
|
||||
{
|
||||
bool doCompile = false;
|
||||
|
||||
if (opt & wordRe::REGEXP)
|
||||
if (opt & compOption::regExp)
|
||||
{
|
||||
doCompile = true;
|
||||
}
|
||||
else if (opt & wordRe::DETECT)
|
||||
else if (opt & compOption::detect)
|
||||
{
|
||||
if (string::meta<regExp>(*this) || !string::valid<word>(*this))
|
||||
{
|
||||
doCompile = true;
|
||||
}
|
||||
}
|
||||
else if (opt & wordRe::NOCASE)
|
||||
else if (opt & compOption::noCase)
|
||||
{
|
||||
doCompile = true;
|
||||
}
|
||||
@ -147,7 +147,7 @@ inline bool Foam::wordRe::compile(const compOption opt) const
|
||||
|
||||
if (doCompile)
|
||||
{
|
||||
re_.set(*this, (opt & wordRe::NOCASE));
|
||||
re_.set(*this, (opt & compOption::noCase));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -271,21 +271,31 @@ inline void Foam::wordRe::operator=(const keyType& str)
|
||||
inline void Foam::wordRe::operator=(const string& str)
|
||||
{
|
||||
string::operator=(str);
|
||||
compile(DETECT); // auto-detect regex
|
||||
compile(compOption::detect); // auto-detect regex
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::wordRe::operator=(const std::string& str)
|
||||
{
|
||||
string::operator=(str);
|
||||
compile(DETECT); // auto-detect regex
|
||||
compile(compOption::detect); // auto-detect regex
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::wordRe::operator=(const char* str)
|
||||
{
|
||||
string::operator=(str);
|
||||
compile(DETECT); // auto-detect regex
|
||||
compile(compOption::detect); // auto-detect regex
|
||||
}
|
||||
|
||||
|
||||
inline int Foam::operator&
|
||||
(
|
||||
const wordRe::compOption co1,
|
||||
const wordRe::compOption co2
|
||||
)
|
||||
{
|
||||
return int(co1) & int(co2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user