mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: generalize instant to be templated, movable, etc
- allows reuse for other purposes
This commit is contained in:
3
applications/test/instant/Make/files
Normal file
3
applications/test/instant/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-instant.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-instant
|
||||||
2
applications/test/instant/Make/options
Normal file
2
applications/test/instant/Make/options
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
|
||||||
|
/* EXE_LIBS = -lfiniteVolume */
|
||||||
82
applications/test/instant/Test-instant.C
Normal file
82
applications/test/instant/Test-instant.C
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
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 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
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Test instant, fileNameInstant
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "argList.H"
|
||||||
|
#include "instant.H"
|
||||||
|
#include "fileNameInstant.H"
|
||||||
|
#include "DynamicList.H"
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
DynamicList<instant> times;
|
||||||
|
|
||||||
|
times.append(instant{});
|
||||||
|
times.append({12, "abc"});
|
||||||
|
times.append(instant{3.14159});
|
||||||
|
times.append({300.456, "def"});
|
||||||
|
times.append({454.456, "xyz"});
|
||||||
|
times.append({10, "ten"});
|
||||||
|
|
||||||
|
{
|
||||||
|
word timeName("twenty");
|
||||||
|
|
||||||
|
Info<<"move append: " << timeName << nl;
|
||||||
|
times.append({20, std::move(timeName)});
|
||||||
|
Info<<"after append: " << timeName << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< nl << "times:" << times << nl;
|
||||||
|
sort(times);
|
||||||
|
Info<< "Sorted:" << times << nl;
|
||||||
|
|
||||||
|
|
||||||
|
DynamicList<fileNameInstant> files;
|
||||||
|
files.append(fileNameInstant{});
|
||||||
|
files.append({12, "twelve"});
|
||||||
|
files.append({3.14, "/path/almost-pi"});
|
||||||
|
files.append({300, "/dev/value"});
|
||||||
|
files.append({454, "/tmp/xyz"});
|
||||||
|
files.append({10, "ten"});
|
||||||
|
|
||||||
|
Info<< nl << "files:" << files << nl;
|
||||||
|
sort(files);
|
||||||
|
Info<< "Sorted:" << files << nl;
|
||||||
|
|
||||||
|
|
||||||
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
119
src/OpenFOAM/db/Time/instant/Instant.C
Normal file
119
src/OpenFOAM/db/Time/instant/Instant.C
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
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 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
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "Instant.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Instant<T>::Instant()
|
||||||
|
:
|
||||||
|
val_(0),
|
||||||
|
key_()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Instant<T>::Instant::Instant(scalar val, const T& key)
|
||||||
|
:
|
||||||
|
val_(val),
|
||||||
|
key_(key)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Instant<T>::Instant::Instant(scalar val, T&& key)
|
||||||
|
:
|
||||||
|
val_(val),
|
||||||
|
key_(std::move(key))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
bool Foam::Instant<T>::equal(scalar val) const
|
||||||
|
{
|
||||||
|
return ((val_ > val - SMALL) && (val_ < val + SMALL));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
template<class T2>
|
||||||
|
bool Foam::Instant<T>::equal(const Instant<T2>& other) const
|
||||||
|
{
|
||||||
|
return this->equal(other.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool Foam::operator==(const Instant<T1>& a, const Instant<T2>& b)
|
||||||
|
{
|
||||||
|
return a.equal(b.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool Foam::operator!=(const Instant<T1>& a, const Instant<T2>& b)
|
||||||
|
{
|
||||||
|
return !a.equal(b.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool Foam::operator<(const Instant<T1>& a, const Instant<T2>& b)
|
||||||
|
{
|
||||||
|
return a.value() < b.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool Foam::operator>(const Instant<T1>& a, const Instant<T2>& b)
|
||||||
|
{
|
||||||
|
return a.value() > b.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Istream& Foam::operator>>(Istream& is, Instant<T>& inst)
|
||||||
|
{
|
||||||
|
is >> inst.value() >> inst.name();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Ostream& Foam::operator<<(Ostream& os, const Instant<T>& inst)
|
||||||
|
{
|
||||||
|
os << inst.value() << '\t' << inst.name();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
179
src/OpenFOAM/db/Time/instant/Instant.H
Normal file
179
src/OpenFOAM/db/Time/instant/Instant.H
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
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 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
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::Instant
|
||||||
|
|
||||||
|
Description
|
||||||
|
A tuple of value and key.
|
||||||
|
The value often corresponds to a time value, thus the naming of the class.
|
||||||
|
The key will usually be a time name or a file name etc.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
Instant.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Instant_H
|
||||||
|
#define Instant_H
|
||||||
|
|
||||||
|
#include "scalar.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Instant Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class Instant
|
||||||
|
{
|
||||||
|
// Private Data
|
||||||
|
|
||||||
|
//- The value (eg, time)
|
||||||
|
scalar val_;
|
||||||
|
|
||||||
|
//- The name/key
|
||||||
|
T key_;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Public classes
|
||||||
|
|
||||||
|
//- Less function for sorting
|
||||||
|
struct less
|
||||||
|
{
|
||||||
|
bool operator()(const Instant& a, const Instant& b) const
|
||||||
|
{
|
||||||
|
return a.value() < b.value();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null, with value = 0.
|
||||||
|
Instant();
|
||||||
|
|
||||||
|
//- Copy construct from components
|
||||||
|
Instant(scalar val, const T& key);
|
||||||
|
|
||||||
|
//- Move construct from components
|
||||||
|
Instant(scalar val, T&& key);
|
||||||
|
|
||||||
|
//- Copy construct
|
||||||
|
Instant(const Instant&) = default;
|
||||||
|
|
||||||
|
//- Move construct
|
||||||
|
Instant(Instant&&) = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- The value (const access)
|
||||||
|
scalar value() const
|
||||||
|
{
|
||||||
|
return val_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The value (non-const access)
|
||||||
|
scalar& value()
|
||||||
|
{
|
||||||
|
return val_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The name/key (const access)
|
||||||
|
const T& name() const
|
||||||
|
{
|
||||||
|
return key_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The name/key (non-const access)
|
||||||
|
T& name()
|
||||||
|
{
|
||||||
|
return key_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- True if values are equal (includes SMALL for rounding)
|
||||||
|
bool equal(scalar val) const;
|
||||||
|
|
||||||
|
//- True if values are equal (includes SMALL for rounding)
|
||||||
|
template<class T2>
|
||||||
|
bool equal(const Instant<T2>& other) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Operators
|
||||||
|
|
||||||
|
//- Copy assignment
|
||||||
|
Instant& operator=(const Instant&) = default;
|
||||||
|
|
||||||
|
//- Move assignment
|
||||||
|
Instant& operator=(Instant&&) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// IOstream Operators
|
||||||
|
|
||||||
|
template<class T> Istream& operator>>(Istream& is, Instant<T>& inst);
|
||||||
|
template<class T> Ostream& operator<<(Ostream& os, const Instant<T>& inst);
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
//- Compare instant values for equality
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool operator==(const Instant<T1>& a, const Instant<T2>& b);
|
||||||
|
|
||||||
|
//- Compare instant values for inequality
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool operator!=(const Instant<T1>& a, const Instant<T2>& b);
|
||||||
|
|
||||||
|
//- Compare instant values for less-than
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool operator<(const Instant<T1>& a, const Instant<T2>& b);
|
||||||
|
|
||||||
|
//- Compare instant values for greater-than
|
||||||
|
template<class T1, class T2>
|
||||||
|
bool operator>(const Instant<T1>& a, const Instant<T2>& b);
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
#include "Instant.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
50
src/OpenFOAM/db/Time/instant/fileNameInstant.H
Normal file
50
src/OpenFOAM/db/Time/instant/fileNameInstant.H
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
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 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
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Typedef
|
||||||
|
Foam::fileNameInstant
|
||||||
|
|
||||||
|
Description
|
||||||
|
A tuple of value and fileName.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef fileNameInstant_H
|
||||||
|
#define fileNameInstant_H
|
||||||
|
|
||||||
|
#include "fileName.H"
|
||||||
|
#include "Instant.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
typedef Instant<fileName> fileNameInstant;
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -23,8 +23,9 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "instantList.H"
|
#include "instant.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -33,81 +34,22 @@ const char* const Foam::instant::typeName = "instant";
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::instant::instant()
|
Foam::instant::instant(scalar timeValue)
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::instant::instant(const scalar val, const word& tname)
|
|
||||||
:
|
:
|
||||||
value_(val),
|
Instant<word>(timeValue, Time::timeName(timeValue))
|
||||||
name_(tname)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
Foam::instant::instant(const scalar val)
|
Foam::instant::instant(const word& timeName)
|
||||||
:
|
:
|
||||||
value_(val),
|
Instant<word>(std::atof(timeName.c_str()), timeName)
|
||||||
name_(Time::timeName(val))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
Foam::instant::instant(const word& tname)
|
Foam::instant::instant(word&& timeName)
|
||||||
:
|
:
|
||||||
value_(atof(tname.c_str())),
|
Instant<word>(std::atof(timeName.c_str()), std::move(timeName))
|
||||||
name_(tname)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
bool Foam::instant::equal(const scalar val) const
|
|
||||||
{
|
|
||||||
return ((value_ > val - SMALL) && (value_ < val + SMALL));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
bool Foam::operator==(const instant& a, const instant& b)
|
|
||||||
{
|
|
||||||
return a.equal(b.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::operator!=(const instant& a, const instant& b)
|
|
||||||
{
|
|
||||||
return !a.equal(b.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::operator<(const instant& a, const instant& b)
|
|
||||||
{
|
|
||||||
return a.value() < b.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::operator>(const instant& a, const instant& b)
|
|
||||||
{
|
|
||||||
return a.value() > b.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, instant& inst)
|
|
||||||
{
|
|
||||||
is >> inst.value_ >> inst.name_;
|
|
||||||
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const instant& inst)
|
|
||||||
{
|
|
||||||
os << inst.value() << tab << inst.name();
|
|
||||||
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -36,113 +36,62 @@ SourceFiles
|
|||||||
#define instant_H
|
#define instant_H
|
||||||
|
|
||||||
#include "word.H"
|
#include "word.H"
|
||||||
#include "scalar.H"
|
#include "Instant.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
class instant;
|
|
||||||
|
|
||||||
Istream& operator>>(Istream& is, instant& inst);
|
|
||||||
Ostream& operator<<(Ostream& os, const instant& inst);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class instant Declaration
|
Class instant Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class instant
|
class instant
|
||||||
{
|
:
|
||||||
// Private data
|
public Instant<word>
|
||||||
|
|
||||||
scalar value_;
|
|
||||||
|
|
||||||
word name_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Public classes
|
|
||||||
|
|
||||||
//- Less function class used in sorting instants
|
|
||||||
class less
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool operator()(const instant& a, const instant& b) const
|
// Static Data Members
|
||||||
{
|
|
||||||
return a.value() < b.value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Static data members
|
|
||||||
|
|
||||||
static const char* const typeName;
|
static const char* const typeName;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Copy and move construct from components
|
||||||
instant();
|
using Instant<word>::Instant;
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct null, with time-value = 0.
|
||||||
instant(const scalar val, const word& tname);
|
instant() = default;
|
||||||
|
|
||||||
//- Construct from time value
|
//- Copy construct
|
||||||
explicit instant(const scalar val);
|
instant(const instant&) = default;
|
||||||
|
|
||||||
//- Construct from time name
|
//- Move construct
|
||||||
explicit instant(const word& tname);
|
instant(instant&&) = default;
|
||||||
|
|
||||||
|
//- Construct from timeValue, auto generating the name
|
||||||
|
explicit instant(scalar timeValue);
|
||||||
|
|
||||||
|
//- Construct from timeName, parsing timeName for a value
|
||||||
|
explicit instant(const word& timeName);
|
||||||
|
|
||||||
|
//- Construct from timeName, parsing timeName for a value
|
||||||
|
explicit instant(word&& timeName);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Operators
|
||||||
|
|
||||||
//- Value (const access)
|
//- Copy assignment
|
||||||
scalar value() const
|
instant& operator=(const instant&) = default;
|
||||||
{
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Value (non-const access)
|
//- Move assignment
|
||||||
scalar& value()
|
instant& operator=(instant&&) = default;
|
||||||
{
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Name (const access)
|
|
||||||
const word& name() const
|
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Name (non-const access)
|
|
||||||
word& name()
|
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Compare instant values to be equal (includes SMALL for rounding)
|
|
||||||
bool equal(const scalar val) const;
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operators
|
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, instant& inst);
|
|
||||||
friend Ostream& operator<<(Ostream& os, const instant& inst);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Global Operators
|
|
||||||
|
|
||||||
bool operator==(const instant& a, const instant& b);
|
|
||||||
bool operator!=(const instant& a, const instant& b);
|
|
||||||
bool operator<(const instant& a, const instant& b);
|
|
||||||
bool operator>(const instant& a, const instant& b);
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
Reference in New Issue
Block a user