Skip to content
Snippets Groups Projects
Commit 75f13e18 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: expose fileOperation::sortTimes as public

parent ea2e24b6
No related branches found
No related tags found
No related merge requests found
...@@ -179,63 +179,51 @@ static bool parseProcsNumRange ...@@ -179,63 +179,51 @@ static bool parseProcsNumRange
} // End anonymous namespace } // End anonymous namespace
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileMonitor& Foam::fileOperation::monitor() const
{
if (!monitorPtr_)
{
monitorPtr_.reset
(
new fileMonitor
(
regIOobject::fileModificationChecking == IOobject::inotify
|| regIOobject::fileModificationChecking == IOobject::inotifyMaster
)
);
}
return *monitorPtr_;
}
Foam::instantList
Foam::instantList Foam::fileOperation::sortTimes Foam::fileOperation::sortTimes
( (
const fileNameList& dirNames, const fileNameList& dirEntries,
const word& constantName const word& constantName
) )
{ {
// Initialise instant list
instantList times(dirNames.size() + 1);
label nTimes = 0;
// Check for "constant" // Check for "constant"
bool haveConstant = false; bool haveConstant = false;
for (const fileName& dirName : dirNames)
if (!constantName.empty())
{ {
if (dirName == constantName) for (const fileName& dirName : dirEntries)
{ {
haveConstant = true; if (dirName == constantName)
times[nTimes].value() = 0; {
times[nTimes].name() = constantName; haveConstant = true;
++nTimes; break;
break; }
} }
} }
// Read and parse all the entries in the directory instantList times(dirEntries.size() + 1);
for (const fileName& dirName : dirNames) label nTimes = 0;
if (haveConstant)
{ {
scalar timeValue; times[nTimes].value() = 0;
if (readScalar(dirName, timeValue)) times[nTimes].name() = constantName;
++nTimes;
}
// Parse directory entries for scalar values
for (const fileName& dirName : dirEntries)
{
if (readScalar(dirName, times[nTimes].value()))
{ {
times[nTimes].value() = timeValue;
times[nTimes].name() = dirName; times[nTimes].name() = dirName;
++nTimes; ++nTimes;
} }
} }
// Reset the length of the times list times.resize(nTimes);
times.setSize(nTimes);
if (haveConstant) if (haveConstant)
{ {
...@@ -246,13 +234,32 @@ Foam::instantList Foam::fileOperation::sortTimes ...@@ -246,13 +234,32 @@ Foam::instantList Foam::fileOperation::sortTimes
} }
else if (nTimes > 1) else if (nTimes > 1)
{ {
std::sort(&times[0], times.end(), instant::less()); std::sort(times.begin(), times.end(), instant::less());
} }
return times; return times;
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::fileMonitor& Foam::fileOperation::monitor() const
{
if (!monitorPtr_)
{
monitorPtr_.reset
(
new fileMonitor
(
regIOobject::fileModificationChecking == IOobject::inotify
|| regIOobject::fileModificationChecking == IOobject::inotifyMaster
)
);
}
return *monitorPtr_;
}
void Foam::fileOperation::mergeTimes void Foam::fileOperation::mergeTimes
( (
const instantList& extraTimes, const instantList& extraTimes,
......
...@@ -131,9 +131,6 @@ protected: ...@@ -131,9 +131,6 @@ protected:
//- Get or create fileMonitor singleton //- Get or create fileMonitor singleton
fileMonitor& monitor() const; fileMonitor& monitor() const;
//- Sort directory entries according to time value
static instantList sortTimes(const fileNameList&, const word&);
//- Merge two times //- Merge two times
static void mergeTimes static void mergeTimes
( (
...@@ -225,6 +222,17 @@ public: ...@@ -225,6 +222,17 @@ public:
virtual ~fileOperation() = default; virtual ~fileOperation() = default;
// Static Functions
//- Sort directory entries according to time value,
// with "constant" appearing first (if it exists)
static instantList sortTimes
(
const fileNameList& dirEntries,
const word& constantName = "constant"
);
// Member Functions // Member Functions
//- Distributed roots (parallel run) //- Distributed roots (parallel run)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment