STYLE: use 'is_sorted()' instead of 'sorted()' for readers, Pair, ...

- avoids naming ambiguity between querying sorted state vs returning a
  sorted list (for example)

ENH: add 'good()' method to a few more classes
This commit is contained in:
Mark Olesen
2023-07-17 09:53:44 +02:00
parent 8562f4d7a4
commit 779c3fe11e
37 changed files with 147 additions and 183 deletions

View File

@ -78,7 +78,7 @@ void Foam::conformalVoronoiMesh::timeCheck
memInfo m;
if (m.valid())
if (m.good())
{
PrintTable<word, label> memoryTable
(

View File

@ -212,7 +212,7 @@ void Foam::PDRmeshArrays::classify
{
const auto& limits = faceLimits[cmpt];
if (!limits.valid())
if (!limits.good())
{
// This should be impossible
FatalErrorInFunction

View File

@ -239,7 +239,7 @@ Foam::volumeType Foam::PDRobstacle::trim(const boundBox& bb)
{
volumeType::type vt = volumeType::UNKNOWN;
if (!bb.valid() || !typeId)
if (!bb.good() || !typeId)
{
return vt;
}

View File

@ -68,7 +68,7 @@ static triSurface pack
f[1] = pointMap[f[1]];
f[2] = pointMap[f[2]];
if (f.valid())
if (f.good())
{
newTriangles[nNewTris++] = f;
}

View File

@ -117,7 +117,7 @@ int main(int argc, char *argv[])
zoneBb.min() = markedZone[0];
zoneBb.max() = markedZone[1];
if (!zoneBb.valid())
if (!zoneBb.good())
{
WarningInFunction
<< "Defined zone is invalid: " << zoneBb << nl;
@ -191,7 +191,7 @@ int main(int argc, char *argv[])
// Faces with centre inside "zone"
//
if (zoneBb.valid())
if (zoneBb.good())
{
Info<< "Using zone " << zoneBb << endl;

View File

@ -94,7 +94,7 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::dynamicCodeContext::valid() const noexcept
bool Foam::dynamicCodeContext::good() const noexcept
{
return &(dict_.get()) != &(dictionary::null);
}

View File

@ -119,8 +119,11 @@ public:
// Member Functions
//- Considered valid if not using dictionary::null as the context
bool valid() const noexcept;
//- Not using dummy code context (dictionary::null)
bool good() const noexcept;
//- Same as good()
bool valid() const noexcept { return good(); }
//- Set code context from a dictionary
void setCodeContext(const dictionary& dict);

View File

@ -124,10 +124,10 @@ public:
}
//- Is there a valid inverse of the selected unit
bool valid() const noexcept
{
return valid_;
}
bool good() const noexcept { return valid_; }
//- Is there a valid inverse of the selected unit
bool valid() const noexcept { return valid_; }
//- (if valid) obtain set of coefficients of unitNames
void coefficients(scalarField& exponents) const;

View File

@ -40,7 +40,7 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
if (!valid())
if (!good())
{
FatalErrorInFunction
<< "Invalid coupleGroup patch group"

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef coupleGroupIdentifier_H
#define coupleGroupIdentifier_H
#ifndef Foam_coupleGroupIdentifier_H
#define Foam_coupleGroupIdentifier_H
#include "word.H"
#include "label.H"
@ -97,16 +97,13 @@ public:
// Member Functions
//- Name of patchGroup
const word& name() const noexcept
{
return name_;
}
const word& name() const noexcept { return name_; }
//- Is a valid patchGroup (non-empty) name
bool valid() const noexcept
{
return !name_.empty();
}
//- The patchGroup has a non-empty name
bool good() const noexcept { return !name_.empty(); }
//- The patchGroup has a non-empty name
bool valid() const noexcept { return good(); }
//- Find other patch in same region.
// \return index of patch or -1.

View File

@ -426,7 +426,7 @@ void Foam::coordinateSystem::rotation(autoPtr<coordinateRotation>&& crot)
void Foam::coordinateSystem::write(Ostream& os) const
{
if (!valid())
if (!good())
{
return;
}
@ -450,7 +450,7 @@ void Foam::coordinateSystem::writeEntry(Ostream& os) const
void Foam::coordinateSystem::writeEntry(const word& keyword, Ostream& os) const
{
if (!valid())
if (!good())
{
return;
}

View File

@ -558,17 +558,14 @@ public:
// Characteristics
//- Consider valid if it has a specification
virtual bool valid() const
{
return bool(spec_);
}
//- Consider good if it has a specification
virtual bool good() const { return bool(spec_); }
//- True if the rotation tensor is uniform for all locations
virtual bool uniform() const
{
return true;
}
virtual bool uniform() const { return true; }
//- Same as good() - 2023-07
virtual bool valid() const { return this->good(); }
// Access

View File

@ -100,7 +100,7 @@ void Foam::coordSystem::indirect::writeEntry
Ostream& os
) const
{
if (!valid())
if (!good())
{
return;
}

View File

@ -161,18 +161,18 @@ public:
// Characteristics
//- Is coordinate system valid?
virtual bool valid() const
{
return backend_ && backend_->valid();
}
//- Is coordinate system good/valid?
virtual bool good() const { return backend_ && backend_->good(); }
//- True if the rotation tensor is uniform for all positions
virtual bool uniform() const
{
return backend_->uniform();
return !backend_ || backend_->uniform();
}
//- Same as good() - 2023-07
virtual bool valid() const { return this->good(); }
// Access

View File

@ -132,8 +132,8 @@ public:
// Queries
//- True if first() is less-than second()
inline bool sorted() const;
//- True if first() is less-than-equal second()
inline bool is_sorted() const;
// Editing
@ -174,6 +174,13 @@ public:
}
}
};
// Housekeeping
//- Deprecated(2023-07) Use is_sorted() method
// \deprecated(2023-07) Use is_sorted() method
bool sorted() const { return is_sorted(); }
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -148,7 +148,7 @@ inline void Foam::Pair<T>::flip()
template<class T>
inline bool Foam::Pair<T>::sorted() const
inline bool Foam::Pair<T>::is_sorted() const
{
return !(second() < first());
}

View File

@ -117,11 +117,14 @@ public:
}
//- True if all internal ids are non-negative
bool valid() const
bool good() const noexcept
{
return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1);
}
//- Same as good()
bool valid() const noexcept { return good(); }
//- Canonical name for boundary 0
word canonicalName0() const
@ -218,7 +221,7 @@ public:
//- Add (valid) interface entry
bool add(const interfaceEntry& entry)
{
return (entry.valid() && map().set(entry.id, entry));
return (entry.good() && map().set(entry.id, entry));
}

View File

@ -50,7 +50,7 @@ Foam::glTF::sceneWriter::~sceneWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::glTF::sceneWriter::valid() const noexcept
bool Foam::glTF::sceneWriter::good() const noexcept
{
return (ofile_ && scene_);
}

View File

@ -94,15 +94,15 @@ public:
// Member Functions
//- True if output file and scene exist
bool valid() const noexcept;
bool good() const noexcept;
//- The json file name. Empty with !valid()
//- The json file name. Empty with !good()
const fileName& path() const;
//- Const access to the scene. Error if valid() is not true!
//- Const access to the scene. Error if good() is not true!
const scene& getScene() const;
//- Non-const access to the scene. Error if valid() is not true!
//- Non-const access to the scene. Error if good() is not true!
scene& getScene();
@ -111,6 +111,9 @@ public:
//- Write scene and close file
void close();
//- Same as good()
bool valid() const noexcept { return good(); }
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,8 +34,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef STLAsciiParse_H
#define STLAsciiParse_H
#ifndef Foam_STLAsciiParse_H
#define Foam_STLAsciiParse_H
#include "DynamicList.H"
#include "HashTable.H"
@ -122,20 +122,20 @@ public:
inline void clear();
//- Do all the solid groups appear in order?
inline bool sorted() const;
bool is_sorted() const noexcept { return sorted_; }
//- A list of unstitched triangle points
inline DynamicList<STLpoint>& points();
DynamicList<STLpoint>& points() noexcept { return points_; }
//- A list of facet IDs (group IDs)
//- corresponds to the number of triangles
inline DynamicList<label>& facets();
DynamicList<label>& facets() noexcept { return facets_; }
//- Solid names in the order of their appearance.
inline DynamicList<word>& names();
DynamicList<word>& names() noexcept { return names_; }
//- Solid sizes in the order of their appearance.
inline DynamicList<label>& sizes();
DynamicList<label>& sizes() noexcept { return sizes_; }
};

View File

@ -232,7 +232,7 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
normal.x() = strtof(YYText(), &endPtr);
normal.y() = strtof(endPtr, &endPtr);
normal.z() = strtof(endPtr, &endPtr);
normals_.append(normal);
normals_.push_back(normal);
*/
BEGIN(readFacet);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,12 +48,13 @@ inline void Foam::Detail::STLAsciiParse::beginSolid(word solidName)
groupId_ = sizes_.size();
if (nameLookup_.insert(solidName, groupId_))
{
names_.append(solidName);
sizes_.append(0);
names_.push_back(std::move(solidName));
sizes_.push_back(0);
}
else
{
FatalErrorInFunction<< "Duplicate solid-name: " << solidName
FatalErrorInFunction
<< "Duplicate solid-name: " << solidName << nl
<< exit(FatalError);
}
}
@ -79,7 +80,7 @@ inline bool Foam::Detail::STLAsciiParse::addVertexComponent(float val)
if (++nVertexCmpt_ == 3)
{
points_.append(currVertex_);
points_.push_back(currVertex_);
nVertexCmpt_ = 0;
++nFacetPoints_;
}
@ -95,7 +96,7 @@ inline bool Foam::Detail::STLAsciiParse::addVertexComponent(const char* text)
if (++nVertexCmpt_ == 3)
{
points_.append(currVertex_);
points_.push_back(currVertex_);
nVertexCmpt_ = 0;
++nFacetPoints_;
}
@ -108,8 +109,8 @@ inline void Foam::Detail::STLAsciiParse::endFacet()
{
if (nFacetPoints_ == 3)
{
facets_.append(groupId_);
sizes_[groupId_]++;
facets_.push_back(groupId_);
++sizes_[groupId_];
}
else
{
@ -161,34 +162,4 @@ inline void Foam::Detail::STLAsciiParse::clear()
}
inline bool Foam::Detail::STLAsciiParse::sorted() const
{
return sorted_;
}
inline Foam::DynamicList<Foam::STLpoint>& Foam::Detail::STLAsciiParse::points()
{
return points_;
}
inline Foam::DynamicList<Foam::label>& Foam::Detail::STLAsciiParse::facets()
{
return facets_;
}
inline Foam::DynamicList<Foam::word>& Foam::Detail::STLAsciiParse::names()
{
return names_;
}
inline Foam::DynamicList<Foam::label>& Foam::Detail::STLAsciiParse::sizes()
{
return sizes_;
}
// ************************************************************************* //

View File

@ -80,7 +80,7 @@ class STLAsciiParseManual
typedef std::pair<const char*, const char*> tokenType;
// Tokenized line
DynamicList<tokenType, 16> tokens_;
DynamicList<tokenType> tokens_;
//- Tokenize
inline std::string::size_type tokenize(const char *p, const char *pe)
@ -107,7 +107,7 @@ class STLAsciiParseManual
{
++p;
}
tokens_.append(tokenType(beg, p));
tokens_.emplace_back(beg, p);
// Find next
while (p < pe && isspace(*p))
@ -250,7 +250,11 @@ void Foam::Detail::STLAsciiParseManual::execute(std::istream& is)
{
beginSolid
(
word::validate(tokens_[1].first, tokens_[1].second)
word::validate
(
tokens_[1].first,
tokens_[1].second
)
);
}
@ -305,8 +309,8 @@ void Foam::Detail::STLAsciiParseManual::execute(std::istream& is)
{
if (tokens_.size() > 3)
{
// Although tokens are not nul-terminated,
// they are space delimited and thus good enough for atof()
// The tokens are space-delimited and thus okay
// for atof()
addVertexComponent(tokens_[1].first);
addVertexComponent(tokens_[2].first);
addVertexComponent(tokens_[3].first);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -49,7 +49,7 @@ void Foam::fileFormats::STLReader::transfer
Detail::STLAsciiParse& parsed
)
{
sorted_ = parsed.sorted();
sorted_ = parsed.is_sorted();
points_.transfer(parsed.points());
zoneIds_.transfer(parsed.facets());
@ -143,7 +143,7 @@ bool Foam::fileFormats::STLReader::readBINARY
{
zoneI = dynSizes.size();
lookup.insert(origId, zoneI);
dynSizes.append(0);
dynSizes.push_back(0);
}
zoneIds_[facei] = zoneI;

View File

@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef STLReader_H
#define STLReader_H
#ifndef Foam_STLReader_H
#define Foam_STLReader_H
#include "STLCore.H"
#include "labelledTri.H"
@ -132,7 +132,7 @@ public:
//- Read from file, filling in the information.
// Auto-detect ASCII/BINARY format.
STLReader(const fileName& filename);
explicit STLReader(const fileName& filename);
//- Read from file, filling in the information.
// Manually selected choice of ASCII/BINARY/UNKNOWN(detect) formats.
@ -158,40 +158,22 @@ public:
label mergePointsMap(const scalar mergeTol, labelList& pointMap) const;
//- File read was already sorted?
inline bool sorted() const
{
return sorted_;
}
bool is_sorted() const noexcept { return sorted_; }
//- Return full access to the points
inline List<STLpoint>& points()
{
return points_;
}
List<STLpoint>& points() noexcept { return points_; }
//- Return full access to the zoneIds
inline List<label>& zoneIds()
{
return zoneIds_;
}
List<label>& zoneIds() noexcept { return zoneIds_; }
//- The list of solid names in the order of their first appearance
inline List<word>& names()
{
return names_;
}
List<word>& names() noexcept { return names_; }
//- The list of solid sizes in the order of their first appearance
inline List<label>& sizes()
{
return sizes_;
}
List<label>& sizes() noexcept { return sizes_; }
//- The STL format used (ASCII or BINARY)
inline enum STLFormat stlFormat() const
{
return format_;
}
enum STLFormat stlFormat() const noexcept { return format_; }
};

View File

@ -40,8 +40,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef lumpedPointInterpolator_H
#define lumpedPointInterpolator_H
#ifndef Foam_lumpedPointInterpolator_H
#define Foam_lumpedPointInterpolator_H
#include "Pair.H"
#include "triFace.H"
@ -90,19 +90,22 @@ public:
// Access
//- Valid if there is an associated nearest point
inline bool valid() const;
//- True if there is an associated nearest point
inline bool good() const;
//- The nearest control point, or -1 if invalid
//- Same as good()
bool valid() const { return good(); }
//- The nearest control point, or -1 if !good()
inline label nearest() const;
//- The first neighbour control point - identical to next1()
inline label next() const;
//- The first neighbour control point, or -1 if invalid
//- The first neighbour control point, or -1 if !good()
inline label next1() const;
//- The second neighbour control point, or -1 if invalid
//- The second neighbour control point, or -1 if !good()
inline label next2() const;
//- The weighting for the nearest point

View File

@ -45,7 +45,7 @@ inline Foam::lumpedPointInterpolator::lumpedPointInterpolator(const label id)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::lumpedPointInterpolator::valid() const
inline bool Foam::lumpedPointInterpolator::good() const
{
return nearest_ != -1;
}

View File

@ -192,7 +192,7 @@ public:
// Member Functions
//- Has positions and consistent number of rotations?
inline bool valid() const;
inline bool good() const;
//- If no points were specified
inline bool empty() const;
@ -200,6 +200,9 @@ public:
//- The number of points
inline label size() const;
//- Same as good()
bool valid() const { return good(); }
//- The points corresponding to mass centres
inline const pointField& points() const;

View File

@ -25,7 +25,7 @@ License
\*---------------------------------------------------------------------------*/
inline bool Foam::lumpedPointState::valid() const
inline bool Foam::lumpedPointState::good() const
{
return points_.size() && points_.size() == angles_.size();
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -177,7 +177,7 @@ static Ostream& serializeProjectEdge
{
os << indent << projKeyword << token::SPACE;
if (e.sorted())
if (e.is_sorted())
{
os << e.first() << token::SPACE << e.second();
}

View File

@ -42,8 +42,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef blockEdge_H
#define blockEdge_H
#ifndef Foam_blockEdge_H
#define Foam_blockEdge_H
#include "searchableSurfaces.H"
#include "edge.H"
@ -196,7 +196,10 @@ public:
// Member Functions
//- True if first/last indices are unique and non-negative.
inline bool valid() const noexcept;
inline bool good() const noexcept;
//- Same as good()
bool valid() const noexcept { return good(); }
//- Index of start (first) point
inline label start() const noexcept;

View File

@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::blockEdge::valid() const noexcept
inline bool Foam::blockEdge::good() const noexcept
{
return (start_ != end_ && start_ >= 0 && end_ >= 0);
}

View File

@ -304,7 +304,7 @@ Foam::blockMesh::blockMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::blockMesh::valid() const noexcept
bool Foam::blockMesh::good() const noexcept
{
return bool(topologyPtr_);
}

View File

@ -315,7 +315,10 @@ public:
}
//- True if the blockMesh topology exists
bool valid() const noexcept;
bool good() const noexcept;
//- Same as good()
bool valid() const noexcept { return good(); }
//- Return the patch names
wordList patchNames() const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -148,7 +148,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
// Generate the (sorted) faces
List<Face> faceLst(zoneIds.size());
if (reader.sorted())
if (reader.is_sorted())
{
// Already sorted - generate directly
forAll(faceLst, facei)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef TRIReader_H
#define TRIReader_H
#ifndef Foam_TRIReader_H
#define Foam_TRIReader_H
#include "STLpoint.H"
#include "labelList.H"
@ -90,7 +90,7 @@ public:
// Constructors
//- Read from file, filling in the information
TRIReader(const fileName& filename);
explicit TRIReader(const fileName& filename);
//- Destructor
@ -112,35 +112,20 @@ public:
label mergePointsMap(const scalar mergeTol, labelList& pointMap) const;
//- File read was already sorted
bool sorted() const
{
return sorted_;
}
//- File read was already in sorted order
bool is_sorted() const noexcept { return sorted_; }
//- Return full access to the points
List<STLpoint>& points()
{
return points_;
}
List<STLpoint>& points() noexcept { return points_; }
//- Return full access to the zones
List<label>& zoneIds()
{
return zoneIds_;
}
List<label>& zoneIds() noexcept { return zoneIds_; }
//- The list of solid names in the order of their first appearance
List<word>& names()
{
return names_;
}
List<word>& names() noexcept { return names_; }
//- The list of zone sizes in the order of their first appearance
List<label>& sizes()
{
return sizes_;
}
List<label>& sizes() noexcept { return sizes_; }
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,7 +108,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
// Generate the (sorted) faces
List<Face> faceLst(zoneIds.size());
if (reader.sorted())
if (reader.is_sorted())
{
// Already sorted - generate directly
forAll(faceLst, facei)