Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
mattijs
2017-05-31 09:00:16 +01:00
215 changed files with 2426 additions and 1722 deletions

View File

@ -138,9 +138,7 @@ public:
>> m.orientation_; >> m.orientation_;
is.readEnd("magnet"); is.readEnd("magnet");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("operator>>(Istream&, magnet&)");
return is; return is;
} }

View File

@ -42,13 +42,44 @@ Description
using namespace Foam; using namespace Foam;
void infoHashString
(
unsigned modulus,
std::initializer_list<std::string> lst
)
{
if (modulus)
{
Info<< "basic string hashing (mod " << label(modulus) << ")" << endl;
for (const auto& str : lst)
{
Info<<"hash(" << str.c_str() << ")="
<< (Hash<string>()(str) % modulus) << nl;
}
}
else
{
Info<< "basic string hashing" << nl;
for (const auto& str : lst)
{
Info<<"hash(" << str.c_str() << ")="
<< Hash<string>()(str) << nl;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
IFstream is("hashingTests"); infoHashString(8, {"asdathis1", "adsxf", "hij", "klmpq"});
IFstream is("hashingTests");
while (is.good()) while (is.good())
{ {

View File

@ -26,6 +26,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "NamedEnum.H" #include "NamedEnum.H"
#include "Enum.H"
#include "IOstreams.H" #include "IOstreams.H"
using namespace Foam; using namespace Foam;
@ -34,15 +35,27 @@ class namedEnumTest
{ {
public: public:
enum option enum class option
{ {
a, A,
b, B,
c, C,
d D
}; };
static const Foam::NamedEnum<option, 4> namedEnum; enum class otherOption
{
A,
B,
C,
D
};
static const Foam::NamedEnum<option, 4> optionNamed;
static const Foam::Enum<otherOption> optionEnum;
static const Foam::Enum<option> optionEnum2;
}; };
@ -52,10 +65,25 @@ const char* Foam::NamedEnum<namedEnumTest::option, 4>::names[] =
"a", "a",
"b", "b",
"c", "c",
"d" "d",
}; };
const Foam::NamedEnum<namedEnumTest::option, 4> namedEnumTest::namedEnum; const Foam::NamedEnum<namedEnumTest::option, 4> namedEnumTest::optionNamed;
const Foam::Enum<namedEnumTest::otherOption> namedEnumTest::optionEnum
{
{ namedEnumTest::otherOption::A, "a" },
{ namedEnumTest::otherOption::B, "b" },
{ namedEnumTest::otherOption::C, "c" },
{ namedEnumTest::otherOption::D, "d" },
};
const Foam::Enum<namedEnumTest::option> namedEnumTest::optionEnum2
(
namedEnumTest::option::C,
{ "c", "d" }
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,35 +91,66 @@ const Foam::NamedEnum<namedEnumTest::option, 4> namedEnumTest::namedEnum;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const List<namedEnumTest::option> options Info<<"NamedEnum: " << namedEnumTest::optionNamed << nl;
= namedEnumTest::namedEnum.enums(); Info<<"Enum: " << namedEnumTest::optionEnum << nl;
Info<<"Enum: " << namedEnumTest::optionEnum2 << nl;
Info<< "enums: " << options << nl; dictionary testDict;
testDict.add("lookup1", "c");
Info<< "loop over enums (as list):" << nl;
forAll(options, i)
{
const namedEnumTest::option& opt = options[i];
Info<< "option[" << opt
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
}
Info<< "loop over enums (C++11 for range):" << nl;
for (const auto& opt : options)
{
Info<< "option[" << opt
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
}
Info<< nl Info<< nl
<< namedEnumTest::namedEnum["a"] << nl << int(namedEnumTest::optionNamed["a"]) << nl
<< namedEnumTest::namedEnum[namedEnumTest::a] << nl; << namedEnumTest::optionNamed[namedEnumTest::option::A] << nl;
Info<< "--- test read construction ---" << endl; Info<< nl
<< int(namedEnumTest::optionEnum["a"]) << nl
<< namedEnumTest::optionEnum[namedEnumTest::otherOption::A] << nl;
namedEnumTest::option dummy(namedEnumTest::namedEnum.read(Sin)); Info<< "--- test dictionary lookup ---" << endl;
Info<< namedEnumTest::namedEnum[dummy] << endl; {
Info<< "dict: " << testDict << endl;
Info<< "got: "
<< int
(
namedEnumTest::optionNamed.lookupOrDefault
(
"notFound",
testDict,
namedEnumTest::option::A
)
)
<< nl;
Info<< "got: "
<< int
(
namedEnumTest::optionNamed.lookupOrDefault
(
"lookup1",
testDict,
namedEnumTest::option::A
)
)
<< nl;
Info<< "got: "
<< int
(
namedEnumTest::optionEnum2.lookupOrDefault
(
"lookup1",
testDict,
namedEnumTest::option::A
)
)
<< nl;
}
Info<< "--- test read ---" << endl;
namedEnumTest::option dummy(namedEnumTest::optionNamed.read(Sin));
Info<< namedEnumTest::optionNamed[dummy] << endl;
Info<< "End\n" << endl; Info<< "End\n" << endl;

View File

@ -84,6 +84,12 @@ int main(int argc, char *argv[])
packed.resize(n, 1); packed.resize(n, 1);
} }
Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n"; Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n";
Info<< "packed bool size=" << packed.size() << nl;
// Neither of these should affect the size
packed.unset(2*n-1);
packed.set(2*n-1, 0);
Info<< "packed bool size=" << packed.size() << nl;
// set every other bit on: // set every other bit on:
Info<< "set every other bit on and count\n"; Info<< "set every other bit on and count\n";
@ -99,8 +105,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Counting brute-force:" << timer.cpuTimeIncrement() Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Count packed // Count packed
@ -110,8 +116,8 @@ int main(int argc, char *argv[])
sum += packed.count(); sum += packed.count();
} }
Info<< "Counting via count():" << timer.cpuTimeIncrement() Info<< "Counting via count():" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Dummy addition // Dummy addition
@ -123,8 +129,8 @@ int main(int argc, char *argv[])
sum += i + 1; sum += i + 1;
} }
} }
Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << endl; Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << " (sum is meaningless)" << endl;
// //
// Read // Read
@ -139,8 +145,8 @@ int main(int argc, char *argv[])
sum += stlVector[i]; sum += stlVector[i];
} }
} }
Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << endl; Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read unpacked // Read unpacked
@ -152,8 +158,8 @@ int main(int argc, char *argv[])
sum += unpacked[i]; sum += unpacked[i];
} }
} }
Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << endl; Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read packed // Read packed
@ -166,8 +172,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading packed using get:" << timer.cpuTimeIncrement() Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read packed // Read packed
@ -180,8 +186,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading packed using reference:" << timer.cpuTimeIncrement() Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read via iterator // Read via iterator
@ -194,8 +200,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement() Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read via iterator // Read via iterator
@ -208,8 +214,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement() Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read empty hash // Read empty hash
@ -222,8 +228,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement() Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read full hash // Read full hash
@ -236,8 +242,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement() Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
// Read empty static hash // Read empty static hash
@ -250,8 +256,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement() Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
#if 0 #if 0
// we can skip this test - it is usually quite slow // we can skip this test - it is usually quite slow
@ -265,8 +271,8 @@ int main(int argc, char *argv[])
} }
} }
Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement() Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << nl
Info<< " sum " << sum << endl; << " sum " << sum << endl;
#endif #endif
Info<< "Starting write tests" << endl; Info<< "Starting write tests" << endl;
@ -319,7 +325,6 @@ int main(int argc, char *argv[])
Info<< "Writing packed using set:" << timer.cpuTimeIncrement() Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
<< " s" << endl; << " s" << endl;
// Write packed // Write packed
for (label iter = 0; iter < nIters; ++iter) for (label iter = 0; iter < nIters; ++iter)
{ {

View File

@ -44,22 +44,9 @@ void Foam::DelaunayMeshTools::writeOBJ
OFstream str(fName); OFstream str(fName);
Pout<< nl Pout<< nl
<< "Writing points of types:" << nl; << "Writing points of types ("
<< int(startPointType) << "-" << int(endPointType)
forAllConstIter << ") to " << str.name() << endl;
(
HashTable<int>,
indexedVertexEnum::vertexTypeNames_,
iter
)
{
if (iter() >= startPointType && iter() <= endPointType)
{
Pout<< " " << iter.key() << nl;
}
}
Pout<< "to " << str.name() << endl;
for for
( (
@ -265,7 +252,7 @@ void Foam::DelaunayMeshTools::drawDelaunayCell
<< "f " << 1 + offset << " " << 4 + offset << " " << 3 + offset << nl << "f " << 1 + offset << " " << 4 + offset << " " << 3 + offset << nl
<< "f " << 1 + offset << " " << 2 + offset << " " << 4 + offset << endl; << "f " << 1 + offset << " " << 2 + offset << " " << 4 + offset << endl;
// os << "# cicumcentre " << endl; // os << "# circumcentre " << endl;
// meshTools::writeOBJ(os, c->dual()); // meshTools::writeOBJ(os, c->dual());

View File

@ -900,12 +900,10 @@ void Foam::conformalVoronoiMesh::writeMesh
mesh.addFvPatches(patches); mesh.addFvPatches(patches);
// Add zones to the mesh // Add zones to the mesh
addZones(mesh, cellCentres); addZones(mesh, cellCentres);
Info<< indent << "Add pointZones" << endl; Info<< indent << "Add pointZones" << endl;
{ {
label sz = mesh.pointZones().size(); label sz = mesh.pointZones().size();
@ -914,6 +912,9 @@ void Foam::conformalVoronoiMesh::writeMesh
forAll(dualMeshPointTypeNames_, typeI) forAll(dualMeshPointTypeNames_, typeI)
{ {
const word& znName =
dualMeshPointTypeNames_[dualMeshPointType(typeI)];
forAll(boundaryPts, ptI) forAll(boundaryPts, ptI)
{ {
const label& bPtType = boundaryPts[ptI]; const label& bPtType = boundaryPts[ptI];
@ -928,14 +929,14 @@ void Foam::conformalVoronoiMesh::writeMesh
Info<< incrIndent << indent Info<< incrIndent << indent
<< "Adding " << bPts.size() << "Adding " << bPts.size()
<< " points of type " << dualMeshPointTypeNames_.words()[typeI] << " points of type " << znName
<< decrIndent << endl; << decrIndent << endl;
mesh.pointZones().append mesh.pointZones().append
( (
new pointZone new pointZone
( (
dualMeshPointTypeNames_.words()[typeI], znName,
bPts, bPts,
sz + typeI, sz + typeI,
mesh.pointZones() mesh.pointZones()

View File

@ -229,7 +229,7 @@ int main(int argc, char *argv[])
word patchMapMethod; word patchMapMethod;
if (meshToMesh::interpolationMethodNames_.found(mapMethod)) if (meshToMesh::interpolationMethodNames_.hasEnum(mapMethod))
{ {
// Lookup corresponding AMI method // Lookup corresponding AMI method
meshToMesh::interpolationMethod method = meshToMesh::interpolationMethod method =

View File

@ -35,8 +35,7 @@ Foam::CLASSNAME::CLASSNAME(Istream& is)
member1(is), member1(is),
member2(is) member2(is)
{ {
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Foam::CLASSNAME::CLASSNAME(Foam::Istream&)");
} }
@ -44,25 +43,14 @@ Foam::CLASSNAME::CLASSNAME(Istream& is)
Foam::Istream& Foam::operator>>(Istream& is, CLASSNAME&) Foam::Istream& Foam::operator>>(Istream& is, CLASSNAME&)
{ {
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::CLASSNAME&)"
);
return is; return is;
} }
Foam::Ostream& Foam::operator<<(Ostream& os, const CLASSNAME&) Foam::Ostream& Foam::operator<<(Ostream& os, const CLASSNAME&)
{ {
// Check state of Ostream os.check(FUNCTION_NAME);
os.check
(
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
"const Foam::CLASSNAME&)"
);
return os; return os;
} }

View File

@ -36,8 +36,7 @@ Foam::CLASSNAME<TemplateArgument>::CLASSNAME(Istream& is)
member1(is), member1(is),
member2(is) member2(is)
{ {
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Foam::CLASSNAME<TemplateArgument>::CLASSNAME(Foam::Istream&)");
} }
@ -50,13 +49,7 @@ Foam::Istream& Foam::operator>>
CLASSNAME<TemplateArgument>& CLASSNAME<TemplateArgument>&
) )
{ {
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Foam::Istream& Foam::operator>>"
"(Foam::Istream&, Foam::CLASSNAME<TemplateArgument>&)"
);
return is; return is;
} }
@ -68,13 +61,7 @@ Foam::Ostream& Foam::operator<<
const CLASSNAME<TemplateArgument>& const CLASSNAME<TemplateArgument>&
) )
{ {
// Check state of Ostream os.check(FUNCTION_NAME);
os.check
(
"Foam::Ostream& Foam::operator<<"
"(Ostream&, const CLASSNAME<TemplateArgument>&)"
);
return os; return os;
} }

View File

@ -51,8 +51,8 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# USER EDITABLE PART: Changes made here may be lost with the next upgrade # USER EDITABLE PART: Changes made here may be lost with the next upgrade
set boost_version=boost_1_62_0 set boost_version=boost_1_64_0
set cgal_version=CGAL-4.9 set cgal_version=CGAL-4.9.1
setenv BOOST_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version setenv BOOST_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version
setenv CGAL_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version setenv CGAL_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version

View File

@ -66,6 +66,9 @@ case ThirdParty:
case Gcc63: case Gcc63:
set gcc_version=gcc-6.3.0 set gcc_version=gcc-6.3.0
breaksw breaksw
case Gcc71:
set gcc_version=gcc-7.1.0
breaksw
case Clang: case Clang:
set clang_version=llvm-3.7.1 set clang_version=llvm-3.7.1
breaksw breaksw

View File

@ -50,8 +50,8 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# USER EDITABLE PART: Changes made here may be lost with the next upgrade # USER EDITABLE PART: Changes made here may be lost with the next upgrade
boost_version=boost_1_62_0 boost_version=boost_1_64_0
cgal_version=CGAL-4.9 cgal_version=CGAL-4.9.1
export BOOST_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version export BOOST_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version
export CGAL_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version export CGAL_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version

View File

@ -65,6 +65,9 @@ ThirdParty)
Gcc63) Gcc63)
gcc_version=gcc-6.3.0 gcc_version=gcc-6.3.0
;; ;;
Gcc71)
gcc_version=gcc-7.1.0
;;
Clang) Clang)
clang_version=llvm-3.7.1 clang_version=llvm-3.7.1
;; ;;

View File

@ -770,7 +770,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
// If dest is a directory, create the destination file name. // If dest is a directory, create the destination file name.
if (destFile.type() == fileName::DIRECTORY) if (destFile.type() == fileName::DIRECTORY)
{ {
destFile = destFile/src.component(src.components().size() -1); destFile = destFile/src.components().last();
} }
// Make sure the destination directory exists. // Make sure the destination directory exists.
@ -943,7 +943,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
} }
} }
// fall-through: nothing to do // fallthrough: nothing to do
return false; return false;
} }

View File

@ -123,9 +123,7 @@ Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
fStat.status_.st_mtime = stat[11]; fStat.status_.st_mtime = stat[11];
fStat.status_.st_ctime = stat[12]; fStat.status_.st_ctime = stat[12];
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, fileStat&)");
return is; return is;
} }

View File

@ -118,12 +118,7 @@ Foam::Istream& Foam::operator>>(Istream& is, memInfo& m)
is.readEnd("memInfo"); is.readEnd("memInfo");
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::memInfo&)"
);
return is; return is;
} }
@ -136,12 +131,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const memInfo& m)
<< m.rss_ << m.rss_
<< token::END_LIST; << token::END_LIST;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check
(
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::memInfo&)"
);
return os; return os;
} }

View File

@ -61,9 +61,7 @@ Foam::Istream& Foam::operator>>(Istream& is, volumeType& vt)
// Read end of volumeType // Read end of volumeType
is.readEnd("volumeType"); is.readEnd("volumeType");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("operator>>(Istream&, volumeType&)");
return is; return is;
} }

View File

@ -29,7 +29,6 @@ License
#include "HashTable.H" #include "HashTable.H"
#include "List.H" #include "List.H"
#include "FixedList.H" #include "FixedList.H"
#include "Tuple2.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -74,7 +73,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(const label size)
{ {
table_ = new hashedEntry*[tableSize_]; table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++) for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
{ {
table_[hashIdx] = nullptr; table_[hashIdx] = nullptr;
} }
@ -112,14 +111,14 @@ Foam::HashTable<T, Key, Hash>::HashTable
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable Foam::HashTable<T, Key, Hash>::HashTable
( (
std::initializer_list<Tuple2<Key, T>> lst std::initializer_list<std::pair<Key, T>> lst
) )
: :
HashTable<T, Key, Hash>(2*lst.size()) HashTable<T, Key, Hash>(2*lst.size())
{ {
for (const Tuple2<Key, T>& pair : lst) for (const auto& pair : lst)
{ {
insert(pair.first(), pair.second()); insert(pair.first, pair.second);
} }
} }
@ -203,6 +202,17 @@ Foam::HashTable<T, Key, Hash>::find
( (
const Key& key const Key& key
) const ) const
{
return this->cfind(key);
}
template<class T, class Key, class Hash>
typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::cfind
(
const Key& key
) const
{ {
if (nElmts_) if (nElmts_)
{ {
@ -878,7 +888,7 @@ void Foam::HashTable<T, Key, Hash>::operator=
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::operator= void Foam::HashTable<T, Key, Hash>::operator=
( (
std::initializer_list<Tuple2<Key, T>> lst std::initializer_list<std::pair<Key, T>> lst
) )
{ {
// Could be zero-sized from a previous transfer() // Could be zero-sized from a previous transfer()
@ -893,7 +903,7 @@ void Foam::HashTable<T, Key, Hash>::operator=
for (const auto& pair : lst) for (const auto& pair : lst)
{ {
insert(pair.first(), pair.second()); insert(pair.first, pair.second);
} }
} }
@ -912,7 +922,7 @@ bool Foam::HashTable<T, Key, Hash>::operator==
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{ {
const_iterator other = find(iter.key()); const_iterator other = this->cfind(iter.key());
if (!other.found() || other.object() != iter.object()) if (!other.found() || other.object() != iter.object())
{ {

View File

@ -57,11 +57,13 @@ SourceFiles
#include "uLabel.H" #include "uLabel.H"
#include "word.H" #include "word.H"
#include "Xfer.H" #include "Xfer.H"
#include "Hash.H"
#include "className.H" #include "className.H"
#include "nullObject.H" #include "nullObject.H"
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <utility>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,7 +75,6 @@ namespace Foam
template<class T> class List; template<class T> class List;
template<class T> class UList; template<class T> class UList;
template<class T, unsigned Size> class FixedList; template<class T, unsigned Size> class FixedList;
template<class T1, class T2> class Tuple2;
template<class T, class Key, class Hash> class HashTable; template<class T, class Key, class Hash> class HashTable;
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -212,7 +213,7 @@ private:
// Private data type for table entries // Private data type for table entries
//- Structure to hold a hashed entry, with a SLList for collisions //- Structure to hold a hashed entry, with a linked-list for collisions
struct hashedEntry struct hashedEntry
{ {
//- The lookup key //- The lookup key
@ -224,7 +225,7 @@ private:
//- Pointer to next hashedEntry in sub-list //- Pointer to next hashedEntry in sub-list
hashedEntry* next_; hashedEntry* next_;
//- Construct from key, next pointer and object //- Construct from key, object, next pointer
inline hashedEntry(const Key& key, const T& obj, hashedEntry* next); inline hashedEntry(const Key& key, const T& obj, hashedEntry* next);
private: private:
@ -296,7 +297,7 @@ public:
HashTable(const Xfer<HashTable<T, Key, Hash>>& ht); HashTable(const Xfer<HashTable<T, Key, Hash>>& ht);
//- Construct from an initializer list //- Construct from an initializer list
HashTable(std::initializer_list<Tuple2<Key, T>> lst); HashTable(std::initializer_list<std::pair<Key, T>> lst);
//- Destructor //- Destructor
@ -327,6 +328,10 @@ public:
// If not found iterator = end() // If not found iterator = end()
const_iterator find(const Key& key) const; const_iterator find(const Key& key) const;
//- Find and return an const_iterator set at the hashed entry
// If not found iterator = end()
const_iterator cfind(const Key& key) const;
//- Return hashed entry if it exists, or return the given default //- Return hashed entry if it exists, or return the given default
inline const T& lookup(const Key& key, const T& deflt) const; inline const T& lookup(const Key& key, const T& deflt) const;
@ -554,7 +559,7 @@ public:
void operator=(const HashTable<T, Key, Hash>& rhs); void operator=(const HashTable<T, Key, Hash>& rhs);
//- Assignment from an initializer list //- Assignment from an initializer list
void operator=(std::initializer_list<Tuple2<Key, T>> lst); void operator=(std::initializer_list<std::pair<Key, T>> lst);
//- Equality. Hash tables are equal if the keys and values are equal. //- Equality. Hash tables are equal if the keys and values are equal.
// Independent of table storage size and table order. // Independent of table storage size and table order.

View File

@ -129,9 +129,7 @@ Foam::Ostream& Foam::HashTable<T, Key, Hash>::writeKeys
os << token::END_LIST << nl; // End delimiter os << token::END_LIST << nl; // End delimiter
} }
// Check state of IOstream
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
return os; return os;
} }
@ -145,12 +143,12 @@ Foam::Istream& Foam::operator>>
HashTable<T, Key, Hash>& L HashTable<T, Key, Hash>& L
) )
{ {
is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
// Anull list // Anull list
L.clear(); L.clear();
is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
@ -251,7 +249,7 @@ Foam::Istream& Foam::operator>>
<< exit(FatalIOError); << exit(FatalIOError);
} }
is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
return is; return is;
} }
@ -278,9 +276,7 @@ Foam::Ostream& Foam::operator<<
// Write end delimiter // Write end delimiter
os << token::END_LIST; os << token::END_LIST;
// Check state of IOstream
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -96,7 +96,7 @@ public:
{} {}
//- Construct from an initializer list //- Construct from an initializer list
Map(std::initializer_list<Tuple2<label, T>> map) Map(std::initializer_list<std::pair<label, T>> map)
: :
parent_type(map) parent_type(map)
{} {}

View File

@ -158,6 +158,17 @@ Foam::StaticHashTable<T, Key, Hash>::find
( (
const Key& key const Key& key
) const ) const
{
return this->cfind(key);
}
template<class T, class Key, class Hash>
typename Foam::StaticHashTable<T, Key, Hash>::const_iterator
Foam::StaticHashTable<T, Key, Hash>::cfind
(
const Key& key
) const
{ {
if (nElmts_) if (nElmts_)
{ {

View File

@ -203,6 +203,10 @@ public:
// If not found iterator = end() // If not found iterator = end()
const_iterator find(const Key& key) const; const_iterator find(const Key& key) const;
//- Find and return an const_iterator set at the hashed entry
// If not found iterator = end()
const_iterator cfind(const Key& key) const;
//- Return the table of contents //- Return the table of contents
List<Key> toc() const; List<Key> toc() const;

View File

@ -94,12 +94,12 @@ Foam::StaticHashTable<T, Key, Hash>::printInfo(Ostream& os) const
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L) Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
{ {
is.fatalCheck("operator>>(Istream&, StaticHashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
// Anull list // Anull list
L.clear(); L.clear();
is.fatalCheck("operator>>(Istream&, StaticHashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
@ -200,7 +200,7 @@ Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
<< exit(FatalIOError); << exit(FatalIOError);
} }
is.fatalCheck("operator>>(Istream&, StaticHashTable<T, Key, Hash>&)"); is.fatalCheck(FUNCTION_NAME);
return is; return is;
} }
@ -229,9 +229,7 @@ Foam::Ostream& Foam::operator<<
// Write end delimiter // Write end delimiter
os << token::END_LIST; os << token::END_LIST;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const StaticHashTable&)");
return os; return os;
} }

View File

@ -125,9 +125,7 @@ inline Foam::Istream& Foam::operator>>(Istream& is, Keyed<T>& item)
// Read end of Keyed item/key pair // Read end of Keyed item/key pair
is.readEnd("Keyed<T>"); is.readEnd("Keyed<T>");
// Check state of Ostream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, Keyed&)");
return is; return is;
} }

View File

@ -33,7 +33,7 @@ template<class LListBase, class T>
template<class INew> template<class INew>
void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew) void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
{ {
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
@ -97,7 +97,7 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
} }
token lastToken(is); token lastToken(is);
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
while while
( (
@ -111,7 +111,7 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
this->append(iNew(is).ptr()); this->append(iNew(is).ptr());
is >> lastToken; is >> lastToken;
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
} }
} }
else else
@ -122,7 +122,7 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
<< exit(FatalIOError); << exit(FatalIOError);
} }
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
} }

View File

@ -44,7 +44,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
// Anull list // Anull list
L.clear(); L.clear();
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
@ -98,7 +98,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
} }
token lastToken(is); token lastToken(is);
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
while while
( (
@ -114,7 +114,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
L.append(element); L.append(element);
is >> lastToken; is >> lastToken;
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)"); is.fatalCheck(FUNCTION_NAME);
} }
} }
else else
@ -126,7 +126,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
} }
// Check state of IOstream // Check state of IOstream
is.fatalCheck(" operator>>(Istream&, LList<LListBase,>&)"); is.fatalCheck(FUNCTION_NAME);
return is; return is;
} }
@ -152,9 +152,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
// Write end of contents // Write end of contents
os << token::END_LIST; os << token::END_LIST;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const LList<LListBase, T>&)");
return os; return os;
} }

View File

@ -34,10 +34,7 @@ template<class LListBase, class T>
template<class INew> template<class INew>
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew) void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"LPtrList<LListBase, T>::read(Istream&, const INew&)"
);
token firstToken(is); token firstToken(is);
@ -102,7 +99,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
} }
token lastToken(is); token lastToken(is);
is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)"); is.fatalCheck(FUNCTION_NAME);
while while
( (
@ -116,10 +113,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
this->append(iNew(is).ptr()); this->append(iNew(is).ptr());
is >> lastToken; is >> lastToken;
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"LPtrList<LListBase, T>::read(Istream&, const INew&)"
);
} }
} }
else else
@ -132,7 +126,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
<< exit(FatalIOError); << exit(FatalIOError);
} }
is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)"); is.fatalCheck(FUNCTION_NAME);
} }
@ -190,9 +184,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const LPtrList<LListBase, T>& lst)
// Write end of contents // Write end of contents
os << token::END_LIST; os << token::END_LIST;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const LPtrList<LListBase, T>&)");
return os; return os;
} }

View File

@ -52,9 +52,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UILList<LListBase, T>& lst)
// Write end of contents // Write end of contents
os << token::END_LIST; os << token::END_LIST;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const UILList<LListBase, T>&)");
return os; return os;
} }

View File

@ -591,9 +591,7 @@ Foam::Istream& Foam::operator>>
>> d.binWidth_ >> d.binWidth_
>> d.listStarts_; >> d.listStarts_;
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, Distribution<Type>&)");
return is; return is;
} }
@ -609,9 +607,7 @@ Foam::Ostream& Foam::operator<<
<< d.binWidth_ << token::SPACE << d.binWidth_ << token::SPACE
<< d.listStarts_; << d.listStarts_;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, " "const Distribution&)");
return os; return os;
} }

View File

@ -139,9 +139,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T)); os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
} }
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("const FixedList::writeList(Ostream&)");
return os; return os;
} }
@ -158,7 +156,7 @@ Foam::FixedList<T, Size>::FixedList(Istream& is)
template<class T, unsigned Size> template<class T, unsigned Size>
Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
{ {
is.fatalCheck("operator>>(Istream&, FixedList<T, Size>&)"); is.fatalCheck(FUNCTION_NAME);
if (is.format() == IOstream::ASCII || !contiguous<T>()) if (is.format() == IOstream::ASCII || !contiguous<T>())
{ {

View File

@ -46,11 +46,11 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
// Anull list // Anull list
L.setSize(0); L.setSize(0);
is.fatalCheck("operator>>(Istream&, List<T>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
is.fatalCheck("operator>>(Istream&, List<T>&) : reading first token"); is.fatalCheck(FUNCTION_NAME);
if (firstToken.isCompound()) if (firstToken.isCompound())
{ {

View File

@ -286,7 +286,7 @@ Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
void Foam::PackedBoolList::operator=(const Foam::UList<bool>& lst) void Foam::PackedBoolList::operator=(const UList<bool>& lst)
{ {
this->setSize(lst.size()); this->setSize(lst.size());

View File

@ -94,7 +94,7 @@ public:
inline PackedBoolList(); inline PackedBoolList();
//- Construct from Istream //- Construct from Istream
PackedBoolList(Istream&); PackedBoolList(Istream& is);
//- Construct with given size, initializes list to 0 //- Construct with given size, initializes list to 0
explicit inline PackedBoolList(const label size); explicit inline PackedBoolList(const label size);
@ -103,19 +103,19 @@ public:
inline PackedBoolList(const label size, const bool val); inline PackedBoolList(const label size, const bool val);
//- Copy constructor //- Copy constructor
inline PackedBoolList(const PackedBoolList&); inline PackedBoolList(const PackedBoolList& lst);
//- Copy constructor //- Copy constructor
explicit inline PackedBoolList(const PackedList<1>&); explicit inline PackedBoolList(const PackedList<1>& lst);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
inline PackedBoolList(const Xfer<PackedBoolList>&); inline PackedBoolList(const Xfer<PackedBoolList>& lst);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
inline PackedBoolList(const Xfer<PackedList<1>>&); inline PackedBoolList(const Xfer<PackedList<1>>& lst);
//- Construct from a list of bools //- Construct from a list of bools
explicit inline PackedBoolList(const Foam::UList<bool>&); explicit inline PackedBoolList(const UList<bool>& lst);
//- Construct from a list of labels //- Construct from a list of labels
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
@ -137,7 +137,7 @@ public:
using PackedList<1>::unset; using PackedList<1>::unset;
//- Set specified bits. //- Set specified bits.
void set(const PackedList<1>&); void set(const PackedList<1>& lst);
//- Set the listed indices. Return number of elements changed. //- Set the listed indices. Return number of elements changed.
// Does auto-vivify for non-existent entries. // Does auto-vivify for non-existent entries.
@ -148,7 +148,7 @@ public:
label set(const UIndirectList<label>& indices); label set(const UIndirectList<label>& indices);
//- Unset specified bits. //- Unset specified bits.
void unset(const PackedList<1>&); void unset(const PackedList<1>& lst);
//- Unset the listed indices. Return number of elements changed. //- Unset the listed indices. Return number of elements changed.
// Never auto-vivify entries. // Never auto-vivify entries.
@ -159,7 +159,7 @@ public:
label unset(const UIndirectList<label>& indices); label unset(const UIndirectList<label>& indices);
//- Subset with the specified list. //- Subset with the specified list.
void subset(const PackedList<1>&); void subset(const PackedList<1>& lst);
//- Subset with the listed indices. //- Subset with the listed indices.
// Return number of elements subsetted. // Return number of elements subsetted.
@ -178,11 +178,11 @@ public:
//- Transfer the contents of the argument list into this list //- Transfer the contents of the argument list into this list
// and annul the argument list. // and annul the argument list.
inline void transfer(PackedBoolList&); inline void transfer(PackedBoolList& lst);
//- Transfer the contents of the argument list into this list //- Transfer the contents of the argument list into this list
// and annul the argument list. // and annul the argument list.
inline void transfer(PackedList<1>&); inline void transfer(PackedList<1>& lst);
//- Transfer contents to the Xfer container //- Transfer contents to the Xfer container
inline Xfer<PackedBoolList> xfer(); inline Xfer<PackedBoolList> xfer();
@ -194,13 +194,13 @@ public:
inline void operator=(const bool val); inline void operator=(const bool val);
//- Assignment operator. //- Assignment operator.
inline void operator=(const PackedBoolList&); inline void operator=(const PackedBoolList& lst);
//- Assignment operator. //- Assignment operator.
inline void operator=(const PackedList<1>&); inline void operator=(const PackedList<1>& lst);
//- Assignment operator. //- Assignment operator.
void operator=(const Foam::UList<bool>&); void operator=(const UList<bool>& lst);
//- Assignment operator, //- Assignment operator,
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
@ -208,13 +208,13 @@ public:
//- Assignment operator, //- Assignment operator,
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
inline void operator=(const UIndirectList<label>&); inline void operator=(const UIndirectList<label>& indices);
//- Complement operator //- Complement operator
inline PackedBoolList operator~() const; inline PackedBoolList operator~() const;
//- And operator (lists may be dissimilar sizes) //- And operator (lists may be dissimilar sizes)
inline PackedBoolList& operator&=(const PackedList<1>&); inline PackedBoolList& operator&=(const PackedList<1>& lst);
//- And operator (lists may be dissimilar sizes) //- And operator (lists may be dissimilar sizes)
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
@ -222,14 +222,14 @@ public:
//- And operator (lists may be dissimilar sizes) //- And operator (lists may be dissimilar sizes)
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
inline PackedBoolList& operator&=(const UIndirectList<label>&); inline PackedBoolList& operator&=(const UIndirectList<label>& indices);
//- Xor operator (lists may be dissimilar sizes) //- Xor operator (lists may be dissimilar sizes)
// Retains unique entries // Retains unique entries
PackedBoolList& operator^=(const PackedList<1>&); PackedBoolList& operator^=(const PackedList<1>& lst);
//- Or operator (lists may be dissimilar sizes) //- Or operator (lists may be dissimilar sizes)
inline PackedBoolList& operator|=(const PackedList<1>&); inline PackedBoolList& operator|=(const PackedList<1>& lst);
//- Or operator (lists may be dissimilar sizes), //- Or operator (lists may be dissimilar sizes),
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
@ -237,26 +237,26 @@ public:
//- Or operator (lists may be dissimilar sizes), //- Or operator (lists may be dissimilar sizes),
// using the labels as indices to indicate which bits are set // using the labels as indices to indicate which bits are set
inline PackedBoolList& operator|=(const UIndirectList<label>&); inline PackedBoolList& operator|=(const UIndirectList<label>& indices);
//- Add entries to this list, synonymous with the or operator //- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const PackedList<1>&); inline PackedBoolList& operator+=(const PackedList<1>& lst);
//- Add entries to this list, synonymous with the or operator //- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const labelUList& indices); inline PackedBoolList& operator+=(const labelUList& indices);
//- Add entries to this list, synonymous with the or operator //- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const UIndirectList<label>&); inline PackedBoolList& operator+=(const UIndirectList<label>& indices);
//- Remove entries from this list - unset the specified bits //- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const PackedList<1>&); inline PackedBoolList& operator-=(const PackedList<1>& lst);
//- Remove entries from this list - unset the specified bits //- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const labelUList& indices); inline PackedBoolList& operator-=(const labelUList& indices);
//- Remove entries from this list - unset the specified bits //- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const UIndirectList<label>&); inline PackedBoolList& operator-=(const UIndirectList<label>& indices);
}; };

View File

@ -73,7 +73,7 @@ inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1>>& lst)
{} {}
inline Foam::PackedBoolList::PackedBoolList(const Foam::UList<bool>& lst) inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst)
: :
PackedList<1>() PackedList<1>()
{ {

View File

@ -266,7 +266,7 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
PackedList<nBits>& lst = *this; PackedList<nBits>& lst = *this;
lst.clear(); lst.clear();
is.fatalCheck("PackedList<nBits>::read(Istream&)"); is.fatalCheck(FUNCTION_NAME);
token firstTok(is); token firstTok(is);
is.fatalCheck is.fatalCheck
@ -349,7 +349,7 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
if (firstTok.pToken() == token::BEGIN_LIST) if (firstTok.pToken() == token::BEGIN_LIST)
{ {
token nextTok(is); token nextTok(is);
is.fatalCheck("PackedList<nBits>::read(Istream&)"); is.fatalCheck(FUNCTION_NAME);
while while
( (
@ -362,13 +362,13 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
lst.append(lst.readValue(is)); lst.append(lst.readValue(is));
is >> nextTok; is >> nextTok;
is.fatalCheck("PackedList<nBits>::read(Istream&)"); is.fatalCheck(FUNCTION_NAME);
} }
} }
else if (firstTok.pToken() == token::BEGIN_BLOCK) else if (firstTok.pToken() == token::BEGIN_BLOCK)
{ {
token nextTok(is); token nextTok(is);
is.fatalCheck("PackedList<nBits>::read(Istream&)"); is.fatalCheck(FUNCTION_NAME);
while while
( (
@ -381,7 +381,7 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
lst.setPair(is); lst.setPair(is);
is >> nextTok; is >> nextTok;
is.fatalCheck("PackedList<nBits>::read(Istream&)"); is.fatalCheck(FUNCTION_NAME);
} }
} }
else else

View File

@ -118,9 +118,9 @@ class Ostream;
template<unsigned nBits> class PackedList; template<unsigned nBits> class PackedList;
template<unsigned nBits> template<unsigned nBits>
Istream& operator>>(Istream&, PackedList<nBits>&); Istream& operator>>(Istream& is, PackedList<nBits>& lst);
template<unsigned nBits> template<unsigned nBits>
Ostream& operator<<(Ostream&, const PackedList<nBits>&); Ostream& operator<<(Ostream& os, const PackedList<nBits>& lst);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -160,11 +160,11 @@ protected:
inline static label packedLength(const label); inline static label packedLength(const label);
//- Read a list entry (allows for specialization) //- Read a list entry (allows for specialization)
inline static unsigned int readValue(Istream&); inline static unsigned int readValue(Istream& is);
//- Read an index/value pair and set accordingly. //- Read an index/value pair and set accordingly.
// For bool specialization, read a single index value // For bool specialization, read a single index value
inline void setPair(Istream&); inline void setPair(Istream& is);
private: private:
@ -268,7 +268,7 @@ public:
inline unsigned int get(const label i) const; inline unsigned int get(const label i) const;
//- Set value at index I. Return true if value changed. //- Set value at index I. Return true if value changed.
// Does auto-vivify for non-existent entries. // Does auto-vivify for non-existent, non-zero entries.
// Default value set is the max_value. // Default value set is the max_value.
inline bool set(const label i, const unsigned int val = ~0u); inline bool set(const label i, const unsigned int val = ~0u);
@ -306,10 +306,10 @@ public:
// non-addressable bits: // non-addressable bits:
// on: '!', off: '.' // on: '!', off: '.'
// //
Ostream& printBits(Ostream&, const bool fullOutput=false) const; Ostream& printBits(Ostream& os, const bool fullOutput=false) const;
//- Print information and bit patterns (with printBits) //- Print information and bit patterns (with printBits)
Ostream& printInfo(Ostream&, const bool fullOutput=false) const; Ostream& printInfo(Ostream& os, const bool fullOutput=false) const;
// Edit // Edit
@ -326,20 +326,20 @@ public:
//- Alter the size of the underlying storage. //- Alter the size of the underlying storage.
// The addressed size will be truncated if needed to fit, but will // The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched. // remain otherwise untouched.
inline void setCapacity(const label); inline void setCapacity(const label nElem);
//- Reset addressable list size, does not shrink the allocated size. //- Reset addressable list size, does not shrink the allocated size.
// Optionally specify a value for new elements. // Optionally specify a value for new elements.
inline void resize(const label, const unsigned int val = 0u); inline void resize(const label nElem, const unsigned int val = 0u);
//- Alias for resize() //- Alias for resize()
inline void setSize(const label, const unsigned int val = 0u); inline void setSize(const label nElem, const unsigned int val = 0u);
//- Reserve allocation space for at least this size. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size. // Never shrinks the allocated size.
// The list size is adjusted as per DynamicList with // The list size is adjusted as per DynamicList with
// SizeInc=0, SizeMult=2, SizeDiv=1 // SizeInc=0, SizeMult=2, SizeDiv=1
inline void reserve(const label); inline void reserve(const label nElem);
//- Clear the list, i.e. set addressable size to zero. //- Clear the list, i.e. set addressable size to zero.
// Does not adjust the underlying storage // Does not adjust the underlying storage
@ -353,7 +353,7 @@ public:
//- Transfer the contents of the argument list into this list //- Transfer the contents of the argument list into this list
// and annul the argument list. // and annul the argument list.
inline void transfer(PackedList<nBits>&); inline void transfer(PackedList<nBits>& lst);
//- Transfer contents to the Xfer container //- Transfer contents to the Xfer container
inline Xfer<PackedList<nBits>> xfer(); inline Xfer<PackedList<nBits>> xfer();
@ -442,7 +442,7 @@ public:
inline unsigned int get() const; inline unsigned int get() const;
//- Set value, returning true if changed, no range-checking //- Set value, returning true if changed, no range-checking
inline bool set(unsigned int); inline bool set(unsigned int val);
// Constructors // Constructors
@ -451,7 +451,7 @@ public:
inline iteratorBase(); inline iteratorBase();
//- Construct from base list and position index //- Construct from base list and position index
inline iteratorBase(const PackedList*, const label); inline iteratorBase(const PackedList* lst, const label i);
public: public:
@ -463,17 +463,17 @@ public:
//- Write index/value for a non-zero entry //- Write index/value for a non-zero entry
// The bool specialization writes the index only // The bool specialization writes the index only
inline bool writeIfSet(Ostream&) const; inline bool writeIfSet(Ostream& os) const;
// Member Operators // Member Operators
//- Compare values (not positions) //- Compare values (not positions)
inline bool operator==(const iteratorBase&) const; inline bool operator==(const iteratorBase& iter) const;
inline bool operator!=(const iteratorBase&) const; inline bool operator!=(const iteratorBase& iter) const;
//- Assign value, not position. //- Assign value, not position.
// This allows packed[0] = packed[3] for assigning values // This allows packed[0] = packed[3] for assigning values
inline void operator=(const iteratorBase&); inline void operator=(const iteratorBase& iter);
//- Assign value. //- Assign value.
// A non-existent entry will be auto-vivified. // A non-existent entry will be auto-vivified.
@ -484,7 +484,7 @@ public:
inline operator unsigned int () const; inline operator unsigned int () const;
//- Print information and values //- Print information and values
Ostream& printInfo(Ostream&) const; Ostream& printInfo(Ostream& os) const;
}; };
@ -496,11 +496,11 @@ public:
//- Disallow copy constructor from const_iterator //- Disallow copy constructor from const_iterator
// This would violate const-ness! // This would violate const-ness!
iterator(const const_iterator&); iterator(const const_iterator& iter);
//- Disallow assignment from const_iterator //- Disallow assignment from const_iterator
// This would violate const-ness! // This would violate const-ness!
void operator=(const const_iterator&); void operator=(const const_iterator& iter);
public: public:
@ -513,21 +513,21 @@ public:
//- Construct from iterator base, eg iter(packedlist[i]) //- Construct from iterator base, eg iter(packedlist[i])
// but also "iterator iter = packedlist[i];" // but also "iterator iter = packedlist[i];"
// An out-of-range iterator is assigned end() // An out-of-range iterator is assigned end()
inline iterator(const iteratorBase&); inline iterator(const iteratorBase& iter);
//- Construct from base list and position index //- Construct from base list and position index
inline iterator(const PackedList*, const label); inline iterator(const PackedList* lst, const label i);
// Member Operators // Member Operators
//- Compare positions (not values) //- Compare positions (not values)
inline bool operator==(const iteratorBase&) const; inline bool operator==(const iteratorBase& iter) const;
inline bool operator!=(const iteratorBase&) const; inline bool operator!=(const iteratorBase& iter) const;
//- Assign from iteratorBase, eg iter = packedlist[i] //- Assign from iteratorBase, eg iter = packedlist[i]
// An out-of-range iterator is assigned end() // An out-of-range iterator is assigned end()
inline void operator=(const iteratorBase&); inline void operator=(const iteratorBase& iter);
//- Return value //- Return value
inline unsigned int operator*() const; inline unsigned int operator*() const;
@ -571,24 +571,24 @@ public:
//- Construct from iterator base, eg iter(packedlist[i]) //- Construct from iterator base, eg iter(packedlist[i])
// but also "const_iterator iter = packedlist[i];" // but also "const_iterator iter = packedlist[i];"
// An out-of-range iterator is assigned cend() // An out-of-range iterator is assigned cend()
inline const_iterator(const iteratorBase&); inline const_iterator(const iteratorBase& iter);
//- Construct from base list and position index //- Construct from base list and position index
inline const_iterator(const PackedList*, const label); inline const_iterator(const PackedList* lst, const label i);
//- Construct from iterator //- Construct from iterator
inline const_iterator(const iterator&); inline const_iterator(const iterator& iter);
// Member operators // Member operators
//- Compare positions (not values) //- Compare positions (not values)
inline bool operator==(const iteratorBase&) const; inline bool operator==(const iteratorBase& iter) const;
inline bool operator!=(const iteratorBase&) const; inline bool operator!=(const iteratorBase& iter) const;
//- Assign from iteratorBase or derived //- Assign from iteratorBase or derived
// eg, iter = packedlist[i] or even iter = list.begin() // eg, iter = packedlist[i] or even iter = list.begin()
inline void operator=(const iteratorBase&); inline void operator=(const iteratorBase& iter);
//- Return referenced value directly //- Return referenced value directly
inline unsigned int operator*() const; inline unsigned int operator*() const;
@ -621,14 +621,14 @@ public:
friend Istream& operator>> <nBits> friend Istream& operator>> <nBits>
( (
Istream&, Istream& is,
PackedList<nBits>& PackedList<nBits>& lst
); );
friend Ostream& operator<< <nBits> friend Ostream& operator<< <nBits>
( (
Ostream&, Ostream& os,
const PackedList<nBits>& const PackedList<nBits>& lst
); );
}; };

View File

@ -137,8 +137,7 @@ inline void Foam::PackedList<nBits>::setPair(Istream& is)
set(ind, val); set(ind, val);
// Check state of Istream is.check(FUNCTION_NAME);
is.check("PackedList<nBits>::setPair(Istream&)");
} }
@ -268,7 +267,7 @@ Foam::PackedList<nBits>::clone() const
template<unsigned nBits> template<unsigned nBits>
inline Foam::PackedList<nBits>::iteratorBase::iteratorBase() inline Foam::PackedList<nBits>::iteratorBase::iteratorBase()
: :
list_(0), list_(nullptr),
index_(0) index_(0)
{} {}
@ -1003,6 +1002,12 @@ inline bool Foam::PackedList<nBits>::set
} }
else if (i >= size_) else if (i >= size_)
{ {
if (!val)
{
// Same as unset out-of-bounds = noop
return false;
}
// Lazy evaluation - increase size on assigment // Lazy evaluation - increase size on assigment
resize(i + 1); resize(i + 1);
} }
@ -1014,7 +1019,7 @@ inline bool Foam::PackedList<nBits>::set
template<unsigned nBits> template<unsigned nBits>
inline bool Foam::PackedList<nBits>::unset(const label i) inline bool Foam::PackedList<nBits>::unset(const label i)
{ {
// lazy evaluation - ignore out-of-bounds // Unset out-of-bounds = noop
if (i < 0 || i >= size_) if (i < 0 || i >= size_)
{ {
return false; return false;

View File

@ -35,7 +35,7 @@ template<class T>
template<class INew> template<class INew>
void Foam::PtrList<T>::read(Istream& is, const INew& inewt) void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
{ {
is.fatalCheck("PtrList<T>::read(Istream&, const INew&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);

View File

@ -120,9 +120,7 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
} }
} }
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("UIndirectList::writeList(Ostream&)");
return os; return os;
} }

View File

@ -150,9 +150,7 @@ Foam::Ostream& Foam::UList<T>::writeList
} }
} }
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("UList<T>::writeList(Ostream&)");
return os; return os;
} }
@ -169,7 +167,7 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
template<class T> template<class T>
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
{ {
is.fatalCheck("operator>>(Istream&, UList<T>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);

View File

@ -44,9 +44,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& L)
// Write end delimiter // Write end delimiter
os << nl << decrIndent << indent << token::END_LIST << nl; os << nl << decrIndent << indent << token::END_LIST << nl;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const UPtrList&)");
return os; return os;
} }

View File

@ -1,142 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ 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 "NamedEnum.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Enum, int nEnum>
Foam::NamedEnum<Enum, nEnum>::NamedEnum()
:
HashTable<int>(2*nEnum)
{
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (!names[enumI] || names[enumI][0] == '\0')
{
stringList goodNames(enumI);
for (int i = 0; i < enumI; ++i)
{
goodNames[i] = names[i];
}
FatalErrorInFunction
<< "Illegal enumeration name at position " << enumI << endl
<< "after entries " << goodNames << ".\n"
<< "Possibly your NamedEnum<Enum, nEnum>::names array"
<< " is not of size " << nEnum << endl
<< abort(FatalError);
}
insert(names[enumI], enumI);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Enum, int nEnum>
Enum Foam::NamedEnum<Enum, nEnum>::read(Istream& is) const
{
const word name(is);
HashTable<int>::const_iterator iter = find(name);
if (!iter.found())
{
FatalIOErrorInFunction(is)
<< name << " is not in enumeration: "
<< sortedToc() << exit(FatalIOError);
}
return Enum(iter.object());
}
template<class Enum, int nEnum>
void Foam::NamedEnum<Enum, nEnum>::write(const Enum e, Ostream& os) const
{
os << operator[](e);
}
template<class Enum, int nEnum>
Foam::stringList Foam::NamedEnum<Enum, nEnum>::strings()
{
stringList lst(nEnum);
label nElem = 0;
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (names[enumI] && names[enumI][0])
{
lst[nElem++] = names[enumI];
}
}
lst.setSize(nElem);
return lst;
}
template<class Enum, int nEnum>
Foam::wordList Foam::NamedEnum<Enum, nEnum>::words()
{
wordList lst(nEnum);
label nElem = 0;
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (names[enumI] && names[enumI][0])
{
lst[nElem++] = names[enumI];
}
}
lst.setSize(nElem);
return lst;
}
template<class Enum, int nEnum>
Foam::List<Enum> Foam::NamedEnum<Enum, nEnum>::enums()
{
List<Enum> lst(nEnum);
label nElem = 0;
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (names[enumI] && names[enumI][0])
{
lst[nElem++] = Enum(enumI);
}
}
lst.setSize(nElem);
return lst;
}
// ************************************************************************* //

View File

@ -117,11 +117,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UPstream::commsStruct& comm)
<< comm.allBelow_ << token::SPACE << comm.allBelow_ << token::SPACE
<< comm.allNotBelow_; << comm.allNotBelow_;
os.check os.check(FUNCTION_NAME);
(
"Ostream& operator<<(Ostream&, const commsStruct&)"
);
return os; return os;
} }

View File

@ -105,9 +105,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
<< endl; << endl;
} }
// Check state of stream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const token&)");
return os; return os;
} }

View File

@ -38,11 +38,7 @@ Foam::dictionaryEntry::dictionaryEntry
entry(keyType(is)), entry(keyType(is)),
dictionary(parentDict, is) dictionary(parentDict, is)
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"dictionaryEntry::dictionaryEntry"
"(const dictionary& parentDict, Istream&)"
);
} }
@ -56,11 +52,7 @@ Foam::dictionaryEntry::dictionaryEntry
entry(key), entry(key),
dictionary(key, parentDict, is) dictionary(key, parentDict, is)
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"dictionaryEntry::dictionaryEntry"
"(const keyType&, const dictionary& parentDict, Istream&)"
);
} }

View File

@ -115,8 +115,7 @@ void Foam::dictionaryListEntry::write(Ostream& os) const
// Write end delimiter // Write end delimiter
os << decrIndent << indent << token::END_LIST << nl; os << decrIndent << indent << token::END_LIST << nl;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const dictionaryListEntry&)");
} }

View File

@ -84,11 +84,7 @@ bool Foam::functionEntry::execute
Istream& is Istream& is
) )
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"functionEntry::execute"
"(const word& functionName, dictionary& parentDict, Istream&)"
);
if (!executedictionaryIstreamMemberFunctionTablePtr_) if (!executedictionaryIstreamMemberFunctionTablePtr_)
{ {
@ -127,11 +123,7 @@ bool Foam::functionEntry::execute
Istream& is Istream& is
) )
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"functionEntry::execute"
"(const word&, const dictionary&, primitiveEntry&, Istream&)"
);
if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_) if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
{ {

View File

@ -91,10 +91,7 @@ bool Foam::primitiveEntry::expandFunction
bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
{ {
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"primitiveEntry::readData(const dictionary&, Istream&)"
);
label blockCount = 0; label blockCount = 0;
token currToken; token currToken;
@ -145,10 +142,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
} }
} }
is.fatalCheck is.fatalCheck(FUNCTION_NAME);
(
"primitiveEntry::readData(const dictionary&, Istream&)"
);
if (currToken.good()) if (currToken.good())
{ {

View File

@ -477,9 +477,8 @@ Foam::Istream& Foam::dimensionSet::read
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
// Check state of Istream
is.check("Istream& operator>>(Istream&, dimensionSet&)");
is.check(FUNCTION_NAME);
return is; return is;
} }
@ -617,9 +616,7 @@ Foam::Istream& Foam::dimensionSet::read
} }
} }
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, dimensionSet&)");
return is; return is;
} }
@ -691,9 +688,7 @@ Foam::Ostream& Foam::dimensionSet::write
os << token::END_SQR; os << token::END_SQR;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const dimensionSet&)");
return os; return os;
} }
@ -722,9 +717,7 @@ Foam::Istream& Foam::operator>>(Istream& is, dimensionSet& dset)
<< exit(FatalIOError); << exit(FatalIOError);
} }
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, dimensionSet&)");
return is; return is;
} }
@ -734,9 +727,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dimensionSet& dset)
scalar multiplier; scalar multiplier;
dset.write(os, multiplier); dset.write(os, multiplier);
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const dimensionSet&)");
return os; return os;
} }

View File

@ -339,12 +339,7 @@ Foam::dimensioned<Type>::read(Istream& is, const dictionary& readSet)
is >> value_; is >> value_;
value_ *= mult; value_ *= mult;
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Istream& dimensioned<Type>::read(Istream& is, const dictionary&)"
);
return is; return is;
} }
@ -367,13 +362,7 @@ Foam::Istream& Foam::dimensioned<Type>::read
is >> value_; is >> value_;
value_ *= mult; value_ *= mult;
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Istream& dimensioned<Type>::read"
"(Istream& is, const HashTable<dimensionedScalar>&)"
);
return is; return is;
} }
@ -392,12 +381,7 @@ Foam::Istream& Foam::dimensioned<Type>::read(Istream& is)
is >> value_; is >> value_;
value_ *= mult; value_ *= mult;
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Istream& dimensioned<Type>::read(Istream& is)"
);
return is; return is;
} }
@ -612,9 +596,7 @@ Foam::Istream& Foam::operator>>(Istream& is, dimensioned<Type>& dt)
is >> dt.value_; is >> dt.value_;
dt.value_ *= multiplier; dt.value_ *= multiplier;
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, dimensioned<Type>&)");
return is; return is;
} }
@ -634,9 +616,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dimensioned<Type>& dt)
// Write the value // Write the value
os << dt.value()/mult; os << dt.value()/mult;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const dimensioned<Type>&)");
return os; return os;
} }

View File

@ -117,10 +117,8 @@ bool Foam::DimensionedField<Type, GeoMesh>::writeData
Field<Type>::writeEntry(fieldDictEntry, os); Field<Type>::writeEntry(fieldDictEntry, os);
// Check state of Ostream
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
return os.good();
return (os.good());
} }

View File

@ -573,12 +573,7 @@ writeEntry(const word& keyword, Ostream& os) const
this->writeEntries(os); this->writeEntries(os);
os.endBlock() << flush; os.endBlock() << flush;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check
(
"GeometricField<Type, PatchField, GeoMesh>::Boundary::"
"writeEntry(const word& keyword, Ostream& os) const"
);
} }

View File

@ -1292,14 +1292,8 @@ Foam::Ostream& Foam::operator<<
os << nl; os << nl;
gf.boundaryField().writeEntry("boundaryField", os); gf.boundaryField().writeEntry("boundaryField", os);
// Check state of IOstream os.check(FUNCTION_NAME);
os.check return os;
(
"Ostream& operator<<(Ostream&, "
"const GeometricField<Type, PatchField, GeoMesh>&)"
);
return (os);
} }

View File

@ -329,7 +329,7 @@ Foam::Ostream& Foam::operator<<
{ {
ptf.write(os); ptf.write(os);
os.check("Ostream& operator<<(Ostream&, const pointPatchField<Type>&)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -54,6 +54,7 @@ SourceFiles
#include "profilingTrigger.H" #include "profilingTrigger.H"
#include "HashPtrTable.H" #include "HashPtrTable.H"
#include "Tuple2.H"
#include "LIFOStack.H" #include "LIFOStack.H"
#include "Map.H" #include "Map.H"
#include "Time.H" #include "Time.H"

View File

@ -63,7 +63,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const curve& c)
<< c.style_ << nl << c.style_ << nl
<< static_cast<const scalarField&>(c); << static_cast<const scalarField&>(c);
os.check("Ostream& operator>>(Ostream&, const curve&)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -298,7 +298,7 @@ void Foam::graph::write
Foam::Ostream& Foam::operator<<(Ostream& os, const graph& g) Foam::Ostream& Foam::operator<<(Ostream& os, const graph& g)
{ {
g.writeTable(os); g.writeTable(os);
os.check("Ostream& operator<<(Ostream&, const graph&)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -123,10 +123,10 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
const scalar lookupValue const scalar lookupValue
) const ) const
{ {
label n = data.size(); const label n = data.size();
scalar minLimit = data.first().first(); const scalar minLimit = data.first().first();
scalar maxLimit = data.last().first(); const scalar maxLimit = data.last().first();
if (lookupValue < minLimit) if (lookupValue < minLimit)
{ {
@ -147,7 +147,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
<< "bound (" << minLimit << ")" << nl << "bound (" << minLimit << ")" << nl
<< " Continuing with the first entry" << " Continuing with the first entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return data.first().second();
break;
} }
case interpolation2DTable::CLAMP: case interpolation2DTable::CLAMP:
{ {
@ -175,7 +177,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue
<< "bound (" << maxLimit << ")" << nl << "bound (" << maxLimit << ")" << nl
<< " Continuing with the last entry" << " Continuing with the last entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return data.last().second();
break;
} }
case interpolation2DTable::CLAMP: case interpolation2DTable::CLAMP:
{ {
@ -251,16 +255,19 @@ Foam::label Foam::interpolation2DTable<Type>::Xi
WarningInFunction WarningInFunction
<< "value (" << valueX << ") out of bounds" << "value (" << valueX << ") out of bounds"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return limitI;
break;
} }
case interpolation2DTable::CLAMP: case interpolation2DTable::CLAMP:
{ {
return limitI; return limitI;
break;
} }
default: default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Un-handled enumeration " << boundsHandling_ << "Unhandled enumeration " << boundsHandling_
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -299,7 +306,7 @@ Type Foam::interpolation2DTable<Type>::operator()
) const ) const
{ {
// Considers all of the list in Y being equal // Considers all of the list in Y being equal
label nX = this->size(); const label nX = this->size();
const table& t = *this; const table& t = *this;
@ -320,8 +327,8 @@ Type Foam::interpolation2DTable<Type>::operator()
// have 2-D data, interpolate // have 2-D data, interpolate
// find low and high indices in the X range that bound valueX // find low and high indices in the X range that bound valueX
label x0i = Xi(lessOp<scalar>(), valueX, false); const label x0i = Xi(lessOp<scalar>(), valueX, false);
label x1i = Xi(greaterOp<scalar>(), valueX, true); const label x1i = Xi(greaterOp<scalar>(), valueX, true);
if (x0i == x1i) if (x0i == x1i)
{ {
@ -333,8 +340,8 @@ Type Foam::interpolation2DTable<Type>::operator()
Type y1(interpolateValue(t[x1i].second(), valueY)); Type y1(interpolateValue(t[x1i].second(), valueY));
// gradient in X // gradient in X
scalar x0 = t[x0i].first(); const scalar x0 = t[x0i].first();
scalar x1 = t[x1i].first(); const scalar x1 = t[x1i].first();
Type mX = (y1 - y0)/(x1 - x0); Type mX = (y1 - y0)/(x1 - x0);
// interpolate // interpolate
@ -420,7 +427,7 @@ Foam::interpolation2DTable<Type>::outOfBounds
template<class Type> template<class Type>
void Foam::interpolation2DTable<Type>::checkOrder() const void Foam::interpolation2DTable<Type>::checkOrder() const
{ {
label n = this->size(); const label n = this->size();
const table& t = *this; const table& t = *this;
scalar prevValue = t[0].first(); scalar prevValue = t[0].first();
@ -445,10 +452,8 @@ void Foam::interpolation2DTable<Type>::checkOrder() const
template<class Type> template<class Type>
void Foam::interpolation2DTable<Type>::write(Ostream& os) const void Foam::interpolation2DTable<Type>::write(Ostream& os) const
{ {
os.writeKeyword("file") os.writeEntry("file", fileName_);
<< fileName_ << token::END_STATEMENT << nl; os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_));
os.writeKeyword("outOfBounds")
<< boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
os << *this; os << *this;
} }

View File

@ -66,7 +66,7 @@ public:
CLAMP //!< Clamp value to the start/end value CLAMP //!< Clamp value to the start/end value
}; };
//- Cconvenience typedef //- Convenience typedef
typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table; typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table;
@ -156,7 +156,7 @@ public:
const List<Tuple2<scalar, Type>>& operator[](const label) const; const List<Tuple2<scalar, Type>>& operator[](const label) const;
//- Return an interpolated value //- Return an interpolated value
Type operator()(const scalar, const scalar) const; Type operator()(const scalar valueX, const scalar valueY) const;
}; };

View File

@ -205,8 +205,8 @@ Foam::interpolationTable<Type>::outOfBounds
template<class Type> template<class Type>
void Foam::interpolationTable<Type>::check() const void Foam::interpolationTable<Type>::check() const
{ {
label n = this->size(); const label n = this->size();
scalar prevValue = List<Tuple2<scalar, Type>>::operator[](0).first(); scalar prevValue = this->first().first();
for (label i=1; i<n; ++i) for (label i=1; i<n; ++i)
{ {
@ -229,10 +229,8 @@ void Foam::interpolationTable<Type>::check() const
template<class Type> template<class Type>
void Foam::interpolationTable<Type>::write(Ostream& os) const void Foam::interpolationTable<Type>::write(Ostream& os) const
{ {
os.writeKeyword("file") os.writeEntry("file", fileName_);
<< fileName_ << token::END_STATEMENT << nl; os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_));
os.writeKeyword("outOfBounds")
<< boundsHandlingToWord(boundsHandling_) << token::END_STATEMENT << nl;
if (reader_.valid()) if (reader_.valid())
{ {
reader_->write(os); reader_->write(os);
@ -251,8 +249,8 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
return 0; return 0;
} }
scalar minLimit = List<Tuple2<scalar, Type>>::operator[](0).first(); const scalar minLimit = this->first().first();
scalar maxLimit = List<Tuple2<scalar, Type>>::operator[](n-1).first(); const scalar maxLimit = this->last().first();
scalar lookupValue = value; scalar lookupValue = value;
if (lookupValue < minLimit) if (lookupValue < minLimit)
@ -272,7 +270,9 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
<< "value (" << lookupValue << ") underflow" << nl << "value (" << lookupValue << ") underflow" << nl
<< " Zero rate of change." << " Zero rate of change."
<< endl; << endl;
// fall-through to 'CLAMP' // behaviour as per 'CLAMP'
return 0;
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
@ -305,7 +305,9 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
<< "value (" << lookupValue << ") overflow" << nl << "value (" << lookupValue << ") overflow" << nl
<< " Zero rate of change." << " Zero rate of change."
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return 0;
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
@ -346,7 +348,7 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
} }
else if (hi == 0) else if (hi == 0)
{ {
// this treatment should should only occur under these conditions: // this treatment should only occur under these conditions:
// -> the 'REPEAT' treatment // -> the 'REPEAT' treatment
// -> (0 <= value <= minLimit) // -> (0 <= value <= minLimit)
// -> minLimit > 0 // -> minLimit > 0
@ -414,7 +416,9 @@ Foam::interpolationTable<Type>::operator[](const label i) const
<< "index (" << ii << ") underflow" << nl << "index (" << ii << ") underflow" << nl
<< " Continuing with the first entry" << " Continuing with the first entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
ii = 0;
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
@ -448,7 +452,9 @@ Foam::interpolationTable<Type>::operator[](const label i) const
<< "index (" << ii << ") overflow" << nl << "index (" << ii << ") overflow" << nl
<< " Continuing with the last entry" << " Continuing with the last entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
ii = n - 1;
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
@ -477,11 +483,11 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
if (n <= 1) if (n <= 1)
{ {
return List<Tuple2<scalar, Type>>::operator[](0).second(); return this->first().second();
} }
scalar minLimit = List<Tuple2<scalar, Type>>::operator[](0).first(); const scalar minLimit = this->first().first();
scalar maxLimit = List<Tuple2<scalar, Type>>::operator[](n-1).first(); const scalar maxLimit = this->last().first();
scalar lookupValue = value; scalar lookupValue = value;
if (lookupValue < minLimit) if (lookupValue < minLimit)
@ -501,17 +507,19 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
<< "value (" << lookupValue << ") underflow" << nl << "value (" << lookupValue << ") underflow" << nl
<< " Continuing with the first entry" << " Continuing with the first entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return this->first().second();
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
return List<Tuple2<scalar, Type>>::operator[](0).second(); return this->first().second();
break; break;
} }
case interpolationTable::REPEAT: case interpolationTable::REPEAT:
{ {
// adjust lookupValue to >= minLimit // adjust lookupValue to >= minLimit
scalar span = maxLimit-minLimit; const scalar span = maxLimit-minLimit;
lookupValue = fmod(lookupValue-minLimit, span) + minLimit; lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
break; break;
} }
@ -534,17 +542,19 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
<< "value (" << lookupValue << ") overflow" << nl << "value (" << lookupValue << ") overflow" << nl
<< " Continuing with the last entry" << " Continuing with the last entry"
<< endl; << endl;
// fall-through to 'CLAMP' // Behaviour as per 'CLAMP'
return this->last().second();
break;
} }
case interpolationTable::CLAMP: case interpolationTable::CLAMP:
{ {
return List<Tuple2<scalar, Type>>::operator[](n-1).second(); return this->last().second();
break; break;
} }
case interpolationTable::REPEAT: case interpolationTable::REPEAT:
{ {
// adjust lookupValue <= maxLimit // adjust lookupValue <= maxLimit
scalar span = maxLimit-minLimit; const scalar span = maxLimit-minLimit;
lookupValue = fmod(lookupValue-minLimit, span) + minLimit; lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
break; break;
} }
@ -575,7 +585,7 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
} }
else if (hi == 0) else if (hi == 0)
{ {
// this treatment should should only occur under these conditions: // this treatment should only occur under these conditions:
// -> the 'REPEAT' treatment // -> the 'REPEAT' treatment
// -> (0 <= value <= minLimit) // -> (0 <= value <= minLimit)
// -> minLimit > 0 // -> minLimit > 0

View File

@ -363,7 +363,7 @@ Foam::Ostream& Foam::operator<<
<< endl << endl; << endl << endl;
} }
os.check("Ostream& operator<<(Ostream&, const LduMatrix&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -48,7 +48,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Form, Type>& M)
// Anull matrix // Anull matrix
M.clear(); M.clear();
is.fatalCheck("operator>>(Istream&, Matrix<Form, Type>&)"); is.fatalCheck(FUNCTION_NAME);
token firstToken(is); token firstToken(is);
@ -250,9 +250,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
} }
} }
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const Matrix&)");
return os; return os;
} }

View File

@ -338,7 +338,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const lduMatrix& ldum)
os << ldum.upper(); os << ldum.upper();
} }
os.check("Ostream& operator<<(Ostream&, const lduMatrix&"); os.check(FUNCTION_NAME);
return os; return os;
} }
@ -398,7 +398,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<lduMatrix>& ip)
// os << endl; // os << endl;
//} //}
os.check("Ostream& operator<<(Ostream&, const lduMatrix&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -142,9 +142,7 @@ Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& dynId)
<< dynId.name() << token::SPACE << dynId.index() << dynId.name() << token::SPACE << dynId.index()
<< token::END_LIST; << token::END_LIST;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&)");
return os; return os;
} }

View File

@ -82,7 +82,7 @@ Foam::patchIdentifier::~patchIdentifier()
bool Foam::patchIdentifier::inGroup(const word& name) const bool Foam::patchIdentifier::inGroup(const word& name) const
{ {
return inGroups_.size() && findIndex(inGroups_, name) != -1; return findIndex(inGroups_, name) != -1;
} }

View File

@ -106,48 +106,39 @@ void Foam::surfZoneIdentifier::write(Ostream& os) const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
// needed for list output bool Foam::operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b)
bool Foam::surfZoneIdentifier::operator!=
(
const surfZoneIdentifier& rhs
) const
{
return !(*this == rhs);
}
bool Foam::surfZoneIdentifier::operator==
(
const surfZoneIdentifier& rhs
) const
{ {
return return
( (
(index() == rhs.index()) (a.index() == b.index())
&& (name() == rhs.name()) && (a.name() == b.name())
&& (geometricType() == rhs.geometricType()) && (a.geometricType() == b.geometricType())
); );
} }
bool Foam::operator!=(const surfZoneIdentifier& a, const surfZoneIdentifier& b)
{
return !(a == b);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj) Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj)
{ {
is >> obj.name_ >> obj.geometricType_; is >> obj.name_ >> obj.geometricType_;
return is; return is;
} }
Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj) Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj)
{ {
// newlines to separate, since that is what triSurface currently expects // Newlines to separate, since that is what triSurface currently expects
os << nl << obj.name_ << nl << obj.geometricType_; os << nl << obj.name_ << nl << obj.geometricType_;
os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const surfZoneIdentifier&)");
return os; return os;
} }

View File

@ -51,8 +51,8 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class surfZoneIdentifier; class surfZoneIdentifier;
Istream& operator>>(Istream&, surfZoneIdentifier&); Istream& operator>>(Istream& is, surfZoneIdentifier& p);
Ostream& operator<<(Ostream&, const surfZoneIdentifier&); Ostream& operator<<(Ostream& os, const surfZoneIdentifier& p);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfZoneIdentifier Declaration Class surfZoneIdentifier Declaration
@ -94,21 +94,20 @@ public:
const word& name, const word& name,
const label index, const label index,
const word& geometricType = word::null const word& geometricType = word::null
); );
//- Construct from dictionary //- Construct from dictionary
surfZoneIdentifier surfZoneIdentifier
( (
const word& name, const word& name,
const dictionary&, const dictionary& dict,
const label index const label index
); );
//- Construct from another zone identifier, resetting the index //- Copy construct from another zone identifier, resetting the index
surfZoneIdentifier surfZoneIdentifier
( (
const surfZoneIdentifier&, const surfZoneIdentifier& p,
const label index const label index
); );
@ -156,14 +155,8 @@ public:
} }
//- Write surfZoneIdentifier as a dictionary //- Write identifier as a dictionary
void write(Ostream&) const; void write(Ostream& os) const;
// Member Operators
bool operator!=(const surfZoneIdentifier&) const;
bool operator==(const surfZoneIdentifier&) const;
// Ostream Operator // Ostream Operator
@ -171,20 +164,29 @@ public:
//- Read name/type. //- Read name/type.
friend Istream& operator>> friend Istream& operator>>
( (
Istream&, Istream& is,
surfZoneIdentifier& surfZoneIdentifier& ob
); );
//- Write name/type. //- Write name/type.
friend Ostream& operator<< friend Ostream& operator<<
( (
Ostream&, Ostream& os,
const surfZoneIdentifier& const surfZoneIdentifier& obj
); );
}; };
// Global Operators
//- Compare zone indentifiers for equality
bool operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b);
//- Compare zone indentifiers for inequality
bool operator!=(const surfZoneIdentifier& a, const surfZoneIdentifier& b);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -259,8 +259,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
); );
} }
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const boundBox&)");
return os; return os;
} }
@ -280,8 +279,7 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
); );
} }
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, boundBox&)");
return is; return is;
} }

View File

@ -139,7 +139,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<lduMesh>& ip)
} }
} }
os.check("Ostream& operator<<(Ostream&, const lduMesh&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -176,9 +176,7 @@ inline Foam::Istream& Foam::operator>>(Istream& is, face& f)
is >> static_cast<labelList&>(f); is >> static_cast<labelList&>(f);
} }
// Check state of Ostream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, face&)");
return is; return is;
} }

View File

@ -137,9 +137,7 @@ inline Foam::Istream& Foam::operator>>(Istream& is, labelledTri& t)
is.read(reinterpret_cast<char*>(&t), sizeof(labelledTri)); is.read(reinterpret_cast<char*>(&t), sizeof(labelledTri));
} }
// Check state of Ostream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, labelledTri&)");
return is; return is;
} }
@ -161,9 +159,7 @@ inline Foam::Ostream& Foam::operator<<(Ostream& os, const labelledTri& t)
); );
} }
// Check state of Ostream
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -545,7 +545,7 @@ void Foam::mapDistribute::operator=(const mapDistribute& rhs)
Foam::Istream& Foam::operator>>(Istream& is, mapDistribute& map) Foam::Istream& Foam::operator>>(Istream& is, mapDistribute& map)
{ {
is.fatalCheck("operator>>(Istream&, mapDistribute&)"); is.fatalCheck(FUNCTION_NAME);
is >> static_cast<mapDistributeBase&>(map) is >> static_cast<mapDistributeBase&>(map)
>> map.transformElements_ >> map.transformStart_; >> map.transformElements_ >> map.transformStart_;

View File

@ -1248,7 +1248,7 @@ void Foam::mapDistributeBase::operator=(const mapDistributeBase& rhs)
Foam::Istream& Foam::operator>>(Istream& is, mapDistributeBase& map) Foam::Istream& Foam::operator>>(Istream& is, mapDistributeBase& map)
{ {
is.fatalCheck("operator>>(Istream&, mapDistributeBase&)"); is.fatalCheck(FUNCTION_NAME);
is >> map.constructSize_ >> map.subMap_ >> map.constructMap_ is >> map.constructSize_ >> map.subMap_ >> map.constructMap_
>> map.subHasFlip_ >> map.constructHasFlip_; >> map.subHasFlip_ >> map.constructHasFlip_;

View File

@ -309,7 +309,7 @@ void Foam::mapDistributePolyMesh::operator=(const mapDistributePolyMesh& rhs)
Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map) Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map)
{ {
is.fatalCheck("operator>>(Istream&, mapDistributePolyMesh&)"); is.fatalCheck(FUNCTION_NAME);
is >> map.nOldPoints_ is >> map.nOldPoints_
>> map.nOldFaces_ >> map.nOldFaces_

View File

@ -58,8 +58,7 @@ inline objectMap::objectMap(Istream& is)
// Read master of objectMap // Read master of objectMap
is.readEnd("objectMap"); is.readEnd("objectMap");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("objectMap::objectMap(Istream&)");
} }
@ -115,9 +114,7 @@ inline Ostream& operator<<(Ostream& os, const objectMap& a)
<< a.masterObjects_ << a.masterObjects_
<< token::END_LIST; << token::END_LIST;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const objectMap&)");
return os; return os;
} }
@ -128,9 +125,7 @@ inline Istream& operator>>(Istream& is, objectMap& a)
is >> a.index_ >> a.masterObjects_; is >> a.index_ >> a.masterObjects_;
is.readEnd("objectMap"); is.readEnd("objectMap");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, objectMap&)");
return is; return is;
} }

View File

@ -86,12 +86,7 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
); );
} }
// Check state of IOstream is.check(FUNCTION_NAME);
is.check
(
"polyBoundaryMesh::polyBoundaryMesh"
"(const IOobject&, const polyMesh&)"
);
close(); close();
} }
@ -155,12 +150,7 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
); );
} }
// Check state of IOstream is.check(FUNCTION_NAME);
is.check
(
"polyBoundaryMesh::polyBoundaryMesh"
"(const IOobject&, const polyMesh&, const polyPatchList&)"
);
close(); close();
} }
@ -1121,9 +1111,7 @@ bool Foam::polyBoundaryMesh::writeData(Ostream& os) const
os << decrIndent << token::END_LIST; os << decrIndent << token::END_LIST;
// Check state of IOstream os.check(FUNCTION_NAME);
os.check("polyBoundaryMesh::writeData(Ostream& os) const");
return os.good(); return os.good();
} }

View File

@ -114,12 +114,7 @@ Foam::Istream& Foam::operator>>(Istream& is, tetIndices& tI)
>> tI.facePtB() >> tI.facePtB()
>> tI.tetPt(); >> tI.tetPt();
// Check state of Istream is.check(FUNCTION_NAME);
is.check
(
"Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::tetIndices&)"
);
return is; return is;
} }
@ -134,13 +129,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const tetIndices& tI)
<< tI.tetPt() << token::SPACE << tI.tetPt() << token::SPACE
<< endl; << endl;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check
(
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
"const Foam::tetIndices&)"
);
return os; return os;
} }

View File

@ -421,7 +421,7 @@ void Foam::polyPatch::operator=(const polyPatch& p)
Foam::Ostream& Foam::operator<<(Ostream& os, const polyPatch& p) Foam::Ostream& Foam::operator<<(Ostream& os, const polyPatch& p)
{ {
p.write(os); p.write(os);
os.check("Ostream& operator<<(Ostream& os, const polyPatch& p"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -173,7 +173,7 @@ void Foam::cellZone::operator=(const Xfer<labelList>& addr)
Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& zn) Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& zn)
{ {
zn.write(os); zn.write(os);
os.check("Ostream& operator<<(Ostream&, const cellZone&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -544,7 +544,7 @@ void Foam::faceZone::writeDict(Ostream& os) const
Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& zn) Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& zn)
{ {
zn.write(os); zn.write(os);
os.check("Ostream& operator<<(Ostream&, const faceZone&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -225,7 +225,7 @@ void Foam::pointZone::operator=(const Xfer<labelList>& addr)
Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& zn) Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& zn)
{ {
zn.write(os); zn.write(os);
os.check("Ostream& operator<<(Ostream&, const pointZone&"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -242,7 +242,7 @@ void Foam::zone::write(Ostream& os) const
Foam::Ostream& Foam::operator<<(Ostream& os, const zone& z) Foam::Ostream& Foam::operator<<(Ostream& os, const zone& z)
{ {
z.write(os); z.write(os);
os.check("Ostream& operator<<(Ostream& f, const zone& z"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -280,7 +280,7 @@ inline Foam::Istream& Foam::operator>>
is >> l.a_ >> l.b_; is >> l.a_ >> l.b_;
is.readEnd("line"); is.readEnd("line");
is.check("Istream& operator>>(Istream&, line&)"); is.check(FUNCTION_NAME);
return is; return is;
} }

View File

@ -212,12 +212,11 @@ public:
); );
} }
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const PointIndexHit&)");
return os; return os;
} }
friend Istream& operator>>(Istream& is, PointIndexHit& pHit) friend Istream& operator>>(Istream& is, PointIndexHit& pHit)
{ {
if (is.format() == IOstream::ASCII) if (is.format() == IOstream::ASCII)
@ -233,9 +232,7 @@ public:
); );
} }
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, PointIndexHit&)");
return is; return is;
} }

View File

@ -45,7 +45,7 @@ template<class Point, class PointRef, class polygonRef>
inline Foam::pyramid<Point, PointRef, polygonRef>::pyramid(Istream& is) inline Foam::pyramid<Point, PointRef, polygonRef>::pyramid(Istream& is)
{ {
is >> base_ >> apex_; is >> base_ >> apex_;
is.check("pyramid::pyramid(Istream&)"); is.check(FUNCTION_NAME);
} }
@ -105,7 +105,7 @@ inline Foam::Istream& Foam::operator>>
) )
{ {
is >> p.base_ >> p.apex_; is >> p.base_ >> p.apex_;
is.check("Istream& operator>>(Istream&, pyramid&)"); is.check(FUNCTION_NAME);
return is; return is;
} }

View File

@ -967,7 +967,7 @@ inline Foam::Istream& Foam::operator>>
is >> t.a_ >> t.b_ >> t.c_ >> t.d_; is >> t.a_ >> t.b_ >> t.c_ >> t.d_;
is.readEnd("tetrahedron"); is.readEnd("tetrahedron");
is.check("Istream& operator>>(Istream&, tetrahedron&)"); is.check(FUNCTION_NAME);
return is; return is;
} }

View File

@ -869,7 +869,7 @@ inline Foam::Istream& Foam::operator>>
is >> t.a_ >> t.b_ >> t.c_; is >> t.a_ >> t.b_ >> t.c_;
is.readEnd("triangle"); is.readEnd("triangle");
is.check("Istream& operator>>(Istream&, triangle&)"); is.check(FUNCTION_NAME);
return is; return is;
} }

View File

@ -111,9 +111,7 @@ Istream& operator>>(Istream& is, Scalar& s)
return is; return is;
} }
// Check state of Istream is.check(FUNCTION_NAME);
is.check("Istream& operator>>(Istream&, Scalar&)");
return is; return is;
} }
@ -121,7 +119,7 @@ Istream& operator>>(Istream& is, Scalar& s)
Ostream& operator<<(Ostream& os, const Scalar s) Ostream& operator<<(Ostream& os, const Scalar s)
{ {
os.write(s); os.write(s);
os.check("Ostream& operator<<(Ostream&, const Scalar&)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -234,9 +234,7 @@ inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
is >> t2.f_ >> t2.s_; is >> t2.f_ >> t2.s_;
is.readEnd("Tuple2"); is.readEnd("Tuple2");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("operator>>(Istream&, Tuple2<Type1, Type2>&)");
return is; return is;
} }

View File

@ -48,7 +48,7 @@ Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>"); is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
// Check state of Istream // Check state of Istream
is.check("VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(Istream&)"); is.check(FUNCTION_NAME);
} }
@ -94,7 +94,7 @@ Foam::Istream& Foam::operator>>
is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>"); is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
// Check state of Istream // Check state of Istream
is.check("operator>>(Istream&, VectorSpace<Form, Cmpt, Ncmpts>&)"); is.check(FUNCTION_NAME);
return is; return is;
} }
@ -116,9 +116,7 @@ Foam::Ostream& Foam::operator<<
os << token::END_LIST; os << token::END_LIST;
// Check state of Ostream os.check(FUNCTION_NAME);
os.check("operator<<(Ostream&, const VectorSpace<Form, Cmpt, Ncmpts>&)");
return os; return os;
} }

View File

@ -39,7 +39,7 @@ char Foam::readChar(Istream& is)
Foam::Istream& Foam::operator>>(Istream& is, char& c) Foam::Istream& Foam::operator>>(Istream& is, char& c)
{ {
is.read(c); is.read(c);
is.check("Istream& operator>>(Istream&, char&)"); is.check(FUNCTION_NAME);
return is; return is;
} }
@ -47,7 +47,7 @@ Foam::Istream& Foam::operator>>(Istream& is, char& c)
Foam::Ostream& Foam::operator<<(Ostream& os, const char c) Foam::Ostream& Foam::operator<<(Ostream& os, const char c)
{ {
os.write(c); os.write(c);
os.check("Ostream& operator<<(Ostream&, const char)"); os.check(FUNCTION_NAME);
return os; return os;
} }
@ -55,7 +55,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const char c)
Foam::Ostream& Foam::operator<<(Ostream& os, const char* s) Foam::Ostream& Foam::operator<<(Ostream& os, const char* s)
{ {
os.write(s); os.write(s);
os.check("Ostream& operator<<(Ostream&, const char*)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -95,7 +95,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t wc)
os.write(char(0xBD)); os.write(char(0xBD));
} }
os.check("Ostream& operator<<(Ostream&, const wchar_t)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -64,9 +64,7 @@ Foam::Istream& Foam::operator>>(Istream& is, complex& c)
// Read end of complex // Read end of complex
is.readEnd("complex"); is.readEnd("complex");
// Check state of Istream is.check(FUNCTION_NAME);
is.check("operator>>(Istream&, complex&)");
return is; return is;
} }

View File

@ -0,0 +1,238 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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 "Enum.H"
#include "dictionary.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class EnumType>
Foam::label Foam::Enum<EnumType>::getIndex(const word& enumName) const
{
const label n = size();
for (label idx=0; idx < n; ++idx)
{
if (names_[idx] == enumName)
{
return idx;
}
}
return -1;
}
template<class EnumType>
Foam::label Foam::Enum<EnumType>::getIndex(const EnumType e) const
{
const int val = int(e);
const label n = size();
for (label idx=0; idx < n; ++idx)
{
if (values_[idx] == val)
{
return idx;
}
}
return -1;
}
template<class EnumType>
EnumType Foam::Enum<EnumType>::getEnum(const word& enumName) const
{
const label idx = getIndex(enumName);
if (idx < 0)
{
FatalErrorInFunction
<< enumName << " is not in enumeration: "
<< names_ << exit(FatalError);
}
return EnumType(values_[idx]);
}
template<class EnumType>
const Foam::word& Foam::Enum<EnumType>::getName(const EnumType e) const
{
const label idx = getIndex(e);
if (idx < 0)
{
return word::null;
}
else
{
return names_[idx];
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class EnumType>
Foam::Enum<EnumType>::Enum
(
std::initializer_list<std::pair<EnumType, word>> lst
)
:
names_(lst.size()),
values_(lst.size())
{
int idx = 0;
for (const auto& pair : lst)
{
names_[idx] = pair.second;
values_[idx] = int(pair.first);
++idx;
}
}
template<class EnumType>
Foam::Enum<EnumType>::Enum
(
const EnumType start,
std::initializer_list<word> lst
)
:
names_(lst.size()),
values_(lst.size())
{
int val = int(start);
int idx = 0;
for (const auto& key : lst)
{
names_[idx] = key;
values_[idx] = val;
++val;
++idx;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class EnumType>
Foam::List<Foam::word> Foam::Enum<EnumType>::sortedToc() const
{
wordList lst(names_);
Foam::sort(lst);
return lst;
}
template<class EnumType>
EnumType Foam::Enum<EnumType>::read(Istream& is) const
{
const word enumName(is);
const label idx = getIndex(enumName);
if (idx < 0)
{
FatalIOErrorInFunction(is)
<< enumName << " is not in enumeration: "
<< names_ << nl
<< exit(FatalIOError);
}
return EnumType(values_[idx]);
}
template<class EnumType>
void Foam::Enum<EnumType>::write(const EnumType e, Ostream& os) const
{
const label idx = getIndex(e);
if (idx >= 0)
{
os << names_[idx];
}
}
template<class EnumType>
EnumType Foam::Enum<EnumType>::lookup
(
const word& key,
const dictionary& dict
) const
{
const word enumName(dict.lookup(key));
const label idx = getIndex(enumName);
if (idx < 0)
{
FatalIOErrorInFunction(dict)
<< enumName << " is not in enumeration: "
<< names_ << nl
<< exit(FatalIOError);
}
return EnumType(values_[idx]);
}
template<class EnumType>
EnumType Foam::Enum<EnumType>::lookupOrDefault
(
const word& key,
const dictionary& dict,
const EnumType deflt
) const
{
if (dict.found(key))
{
return lookup(key, dict);
}
else
{
return deflt;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class EnumType>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const Enum<EnumType>& wrapped
)
{
return wrapped.names().writeList(os, 10);
}
// ************************************************************************* //

View File

@ -0,0 +1,220 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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::Enum
Description
A Enum is a wrapper around a list of names/values that represent
particular enumeration values.
SourceFiles
Enum.C
\*---------------------------------------------------------------------------*/
#ifndef Enum_H
#define Enum_H
#include "wordList.H"
#include <initializer_list>
#include <utility>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class dictionary;
template<class EnumType> class Enum;
template<class EnumType>
Ostream& operator<<(Ostream& os, const Enum<EnumType>& wrapped);
/*---------------------------------------------------------------------------*\
Class Enum Declaration
\*---------------------------------------------------------------------------*/
template<class EnumType>
class Enum
{
// Private Member Data
//- The names for the enum
List<word> names_;
//- The values for the enum
List<int> values_;
// Private Member Functions
//- The index for the given name. -1 if not found.
label getIndex(const word& enumName) const;
//- The index for the given enumeration. -1 if not found.
label getIndex(const EnumType e) const;
//- Lookup enumeration corresponding to the given name.
// FatalError if not found.
EnumType getEnum(const word& enumName) const;
//- Lookup name corresponding to the given enumeration.
// Return empty word if not found.
const word& getName(const EnumType e) const;
//- Disallow default bitwise copy construct
Enum(const Enum&) = delete;
//- Disallow default bitwise assignment
void operator=(const Enum&) = delete;
public:
//- The type of enumeration wrapped by Enum
typedef EnumType value_type;
// Constructors
//- Construct from a values/names list.
// Duplicate values are permitted (eg, for aliases).
// Duplicate names are permitted, but won't make much sense.
explicit Enum(std::initializer_list<std::pair<EnumType, word>> lst);
//- Construct from a list of names with values incremented from the
// specified start value.
Enum(const EnumType start, std::initializer_list<word> lst);
// Member Functions
// Access
//- The number of lookup names for the enumeration
inline label size() const;
//- The list of enum names, in construction order
inline const List<word>& names() const;
//- The list of enum names, in construction order
inline const List<word>& toc() const;
//- The sorted list of enum names
List<word> sortedToc() const;
//- The list of enum values, in construction order
inline const List<int>& values() const;
// Query
//- Test if there is an enumeration corresponding to the given name.
inline bool hasEnum(const word& enumName) const;
//- Test if there is a name corresponding to the given enumeration.
inline bool hasName(const EnumType e) const;
// Lookup
//- Lookup the key in the dictionary and return the corresponding
// enumeration element based on its name.
// Fatal if anything is incorrect.
EnumType lookup
(
const word& key,
const dictionary& dict
) const;
//- Find the key in the dictionary and return the corresponding
// enumeration element based on its name.
// Return the default value if the key was not found in the dictionary.
// Fatal if the enumerated name was incorrect.
EnumType lookupOrDefault
(
const word& key,
const dictionary& dict,
const EnumType deflt
) const;
// IO
//- Read a word from Istream and return the corresponding enumeration
EnumType read(Istream& is) const;
//- Write the name representation of the enumeration to an Ostream
// A noop if the enumeration wasn't found.
void write(const EnumType e, Ostream& os) const;
//- Write the names as a list to an Ostream
inline Ostream& writeList
(
Ostream& os,
const label shortListLen=0
) const;
// Member Operators
//- Return the enumeration corresponding to the given name
// Fatal if the name cannot be found.
inline const EnumType operator[](const word& name) const;
//- Return the first name corresponding to the given enumeration.
// Returns an empty word on failure.
inline const word& operator[](const EnumType e) const;
// IOstream operators
//- Write names to Ostream, as per writeList() with shortListLen=10
friend Ostream& operator<< <EnumType>
(
Ostream& os,
const Enum<EnumType>& wrapped
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "EnumI.H"
#ifdef NoRepository
#include "Enum.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class EnumType>
inline Foam::label Foam::Enum<EnumType>::size() const
{
return names_.size();
}
template<class EnumType>
inline const Foam::wordList& Foam::Enum<EnumType>::names() const
{
return names_;
}
template<class EnumType>
inline const Foam::wordList& Foam::Enum<EnumType>::toc() const
{
return names_;
}
template<class EnumType>
inline const Foam::List<int>& Foam::Enum<EnumType>::values() const
{
return values_;
}
template<class EnumType>
inline bool Foam::Enum<EnumType>::hasEnum(const word& enumName) const
{
return getIndex(enumName) >= 0;
}
template<class EnumType>
inline bool Foam::Enum<EnumType>::hasName(const EnumType e) const
{
return getIndex(e) >= 0;
}
template<class EnumType>
inline Foam::Ostream& Foam::Enum<EnumType>::writeList
(
Ostream& os,
const label shortListLen
) const
{
return names_.writeList(os, shortListLen);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class EnumType>
inline const EnumType Foam::Enum<EnumType>::operator[]
(
const word& name
) const
{
return getEnum(name);
}
template<class EnumType>
inline const Foam::word& Foam::Enum<EnumType>::operator[]
(
const EnumType e
) const
{
return getName(e);
}
// ************************************************************************* //

View File

@ -0,0 +1,212 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "NamedEnum.H"
#include "dictionary.H"
#include "stdFoam.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class EnumType, int nEnum>
Foam::NamedEnum<EnumType, nEnum>::NamedEnum()
:
lookup_(2*nEnum)
{
for (int enumi=0; enumi < nEnum; ++enumi)
{
if (names[enumi] && names[enumi][0])
{
lookup_.insert(names[enumi], enumi);
}
else
{
// Bad name - generate error message
List<string> goodNames(enumi);
for (int i = 0; i < enumi; ++i)
{
goodNames[i] = names[i];
}
FatalErrorInFunction
<< "Illegal enumeration name at position " << enumi << nl
<< "after entries " << goodNames << nl
<< "Possibly your NamedEnum<EnumType, nEnum>::names array"
<< " is not of size " << nEnum << endl
<< abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class EnumType, int nEnum>
Foam::wordList Foam::NamedEnum<EnumType, nEnum>::words() const
{
List<word> lst(nEnum);
label count = 0;
for (int enumi=0; enumi < nEnum; ++enumi)
{
if (names[enumi] && names[enumi][0])
{
lst[count++] = names[enumi];
}
}
lst.setSize(count);
return lst;
}
template<class EnumType, int nEnum>
Foam::List<int> Foam::NamedEnum<EnumType, nEnum>::values() const
{
List<int> lst(nEnum);
label count = 0;
for (int enumi=0; enumi < nEnum; ++enumi)
{
if (names[enumi] && names[enumi][0])
{
auto iter = lookup_.cfind(names[enumi]);
if (iter.found())
{
lst[count++] = iter.object();
}
}
}
lst.setSize(count);
return lst;
}
template<class EnumType, int nEnum>
bool Foam::NamedEnum<EnumType, nEnum>::hasName(const EnumType e) const
{
const int enumValue(e);
forAllConstIters(lookup_, iter)
{
if (iter.object() == enumValue)
{
return true;
}
}
return false;
}
template<class EnumType, int nEnum>
EnumType Foam::NamedEnum<EnumType, nEnum>::lookup
(
const word& key,
const dictionary& dict
) const
{
const word enumName(dict.lookup(key));
auto iter = lookup_.cfind(enumName);
if (!iter.found())
{
FatalIOErrorInFunction(dict)
<< enumName << " is not in enumeration: "
<< lookup_.sortedToc() << nl
<< exit(FatalIOError);
}
return EnumType(iter.object());
}
template<class EnumType, int nEnum>
EnumType Foam::NamedEnum<EnumType, nEnum>::lookupOrDefault
(
const word& key,
const dictionary& dict,
const EnumType deflt
) const
{
if (dict.found(key))
{
return lookup(key, dict);
}
else
{
return deflt;
}
}
template<class EnumType, int nEnum>
EnumType Foam::NamedEnum<EnumType, nEnum>::read(Istream& is) const
{
const word enumName(is);
auto iter = lookup_.cfind(enumName);
if (!iter.found())
{
FatalIOErrorInFunction(is)
<< enumName << " is not in enumeration: "
<< lookup_.sortedToc() << nl
<< exit(FatalIOError);
}
return EnumType(iter.object());
}
template<class EnumType, int nEnum>
void Foam::NamedEnum<EnumType, nEnum>::write
(
const EnumType e,
Ostream& os
) const
{
const int idx = int(e);
if (idx >= 0 && idx < nEnum)
{
os << names[idx];
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class EnumType, int nEnum>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const NamedEnum<EnumType, nEnum>& wrapped
)
{
return wrapped.lookup_.writeKeys(os, 10);
}
// ************************************************************************* //

View File

@ -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) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,8 @@ Class
Foam::NamedEnum Foam::NamedEnum
Description Description
Initialise the NamedEnum HashTable from the static list of names. A NamedEnum is a wrapper around a list of names that represent
particular enumeration values.
SourceFiles SourceFiles
NamedEnum.C NamedEnum.C
@ -36,7 +37,6 @@ SourceFiles
#define NamedEnum_H #define NamedEnum_H
#include "HashTable.H" #include "HashTable.H"
#include "stringList.H"
#include "wordList.H" #include "wordList.H"
#include <type_traits> #include <type_traits>
@ -44,22 +44,30 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations
class dictionary;
template<class EnumType, int nEnum> class NamedEnum;
template<class EnumType, int nEnum>
Ostream& operator<<(Ostream& os, const NamedEnum<EnumType, nEnum>& wrapped);
// Forward declaration
template<class Enum, int> class NamedEnum;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class NamedEnum Declaration Class NamedEnum Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Enum, int nEnum> template<class EnumType, int nEnum>
class NamedEnum class NamedEnum
:
public HashTable<int>
{ {
//- nEnum must be positive (non-zero) //- The nEnum must be positive (non-zero)
static_assert(nEnum > 0, "nEnum must be positive (non-zero)"); static_assert(nEnum > 0, "nEnum must be positive (non-zero)");
// Private Member Data
//- The values for the enum
HashTable<int> lookup_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
@ -71,9 +79,13 @@ class NamedEnum
public: public:
//- The type of enumeration wrapped by NamedEnum
typedef EnumType value_type;
// Static data members // Static data members
//- The set of names corresponding to the enumeration Enum //- The set of names corresponding to the enumeration EnumType
static const char* names[nEnum]; static const char* names[nEnum];
@ -85,42 +97,84 @@ public:
// Member Functions // Member Functions
//- Read a word from Istream and return the corresponding // Access
// enumeration element
Enum read(Istream&) const; //- The number of lookup names for the enumeration
inline label size() const;
//- The list of enum names
inline wordList toc() const;
//- The sorted list of enum names
inline wordList sortedToc() const;
//- The list of enum names, in construction order
wordList words() const;
//- The list of enum values, in construction order
List<int> values() const;
// Query
//- Test if there is an enumeration corresponding to the given name.
inline bool hasEnum(const word& enumName) const;
//- Test if there is a name corresponding to the given enumeration.
bool hasName(const EnumType e) const;
// Lookup
//- Lookup the key in the dictionary and return the corresponding
// enumeration element based on its name.
// Fatal if anything is incorrect.
EnumType lookup
(
const word& key,
const dictionary& dict
) const;
//- Find the key in the dictionary and return the corresponding
// enumeration element based on its name.
// Return the default value if the key was not found in the dictionary.
// Fatal if enumerated name was incorrect.
EnumType lookupOrDefault
(
const word& key,
const dictionary& dict,
const EnumType deflt
) const;
// IO
//- Read a word from Istream and return the corresponding enumeration
EnumType read(Istream& is) const;
//- Write the name representation of the enumeration to an Ostream //- Write the name representation of the enumeration to an Ostream
void write(const Enum e, Ostream&) const; // A noop if the enumeration wasn't found.
void write(const EnumType e, Ostream& os) const;
//- The set of names as a list of strings
static stringList strings();
//- The set of names as a list of words
static wordList words();
//- List of enumerations
static List<Enum> enums();
// Member Operators // Member Operators
//- Return the enumeration element corresponding to the given name //- Return the enumeration element corresponding to the given name
const Enum operator[](const char* name) const inline const EnumType operator[](const word& name) const;
{
return Enum(HashTable<int>::operator[](name));
}
//- Return the enumeration element corresponding to the given name
const Enum operator[](const word& name) const
{
return Enum(HashTable<int>::operator[](name));
}
//- Return the name of the given enumeration element //- Return the name of the given enumeration element
const char* operator[](const Enum e) const inline const char* operator[](const EnumType e) const;
{
return names[int(e)];
} // IOstream operators
//- Write names to Ostream, as per writeKeys() with shortListLen=10
friend Ostream& operator<< <EnumType, nEnum>
(
Ostream& os,
const NamedEnum<EnumType, nEnum>& wrapped
);
}; };
@ -130,6 +184,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "NamedEnumI.H"
#ifdef NoRepository #ifdef NoRepository
#include "NamedEnum.C" #include "NamedEnum.C"
#endif #endif

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class EnumType, int nEnum>
inline Foam::label Foam::NamedEnum<EnumType, nEnum>::size() const
{
return lookup_.size();
}
template<class EnumType, int nEnum>
inline Foam::wordList Foam::NamedEnum<EnumType, nEnum>::toc() const
{
return lookup_.toc();
}
template<class EnumType, int nEnum>
inline Foam::wordList Foam::NamedEnum<EnumType, nEnum>::sortedToc() const
{
return lookup_.sortedToc();
}
template<class EnumType, int nEnum>
inline bool Foam::NamedEnum<EnumType, nEnum>::hasEnum
(
const word& enumName
) const
{
return lookup_.found(enumName);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class EnumType, int nEnum>
inline const EnumType Foam::NamedEnum<EnumType, nEnum>::operator[]
(
const word& name
) const
{
return EnumType(lookup_[name]);
}
template<class EnumType, int nEnum>
inline const char* Foam::NamedEnum<EnumType, nEnum>::operator[]
(
const EnumType e
) const
{
return names[int(e)];
}
// ************************************************************************* //

Some files were not shown because too many files have changed in this diff Show More