diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index 3cfa28e6d7eb7c95f2930de3ccbcd413e0f4851e..65877be82434cc08937550f97796d5e851958c03 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -124,32 +124,34 @@ template<class ZoneType, class MeshType> template<class UnaryMatchPredicate> Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::namesImpl ( - const PtrList<ZoneType>& zones, + const PtrList<ZoneType>& list, const UnaryMatchPredicate& matcher, const bool doSort ) { - wordList lst(zones.size()); + const label len = list.size(); + + wordList output(len); label count = 0; - forAll(zones, zonei) + for (label i = 0; i < len; ++i) { - const word& zname = zones[zonei].name(); + const word& itemName = list[i].name(); - if (matcher(zname)) + if (matcher(itemName)) { - lst[count++] = zname; + output[count++] = itemName; } } - lst.setSize(count); + output.resize(count); if (doSort) { - Foam::sort(lst); + Foam::sort(output); } - return lst; + return output; } diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 232e87ce593b8ae6139d09009f7ca8d55007d1c5..bee3ca172fb0d4cfc68e7def3e8926a9d039a98d 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -87,7 +87,7 @@ class ZoneMesh template<class UnaryMatchPredicate> static wordList namesImpl ( - const PtrList<ZoneType>& zones, + const PtrList<ZoneType>& list, const UnaryMatchPredicate& matcher, const bool doSort ); diff --git a/src/meshTools/coordinateSystems/coordinateSystems.C b/src/meshTools/coordinateSystems/coordinateSystems.C index 16020e0d188d3a6bdce68802f59363aa3ae2f71e..0e56466f3249b39822ecdfc1991482dde6999c22 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.C +++ b/src/meshTools/coordinateSystems/coordinateSystems.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +36,48 @@ namespace Foam defineTemplateTypeNameAndDebug(IOPtrList<coordinateSystem>, 0); } + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + // Templated implementation for names() - file-scope + template<class UnaryMatchPredicate> + static wordList namesImpl + ( + const IOPtrList<coordinateSystem>& list, + const UnaryMatchPredicate& matcher, + const bool doSort + ) + { + const label len = list.size(); + + wordList output(len); + + label count = 0; + for (label i = 0; i < len; ++i) + { + const word& itemName = list[i].name(); + + if (matcher(itemName)) + { + output[count++] = itemName; + } + } + + output.resize(count); + + if (doSort) + { + Foam::sort(output); + } + + return output; + } + +} // End namespace Foam + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::coordinateSystems::coordinateSystems(const IOobject& io) @@ -66,33 +108,36 @@ Foam::coordinateSystems::coordinateSystems // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -// Read construct from registry, or return previously registered const Foam::coordinateSystems& Foam::coordinateSystems::New ( const objectRegistry& obr ) { - if (obr.foundObject<coordinateSystems>(typeName)) + // Previously registered? + + const coordinateSystems* ptr = + obr.lookupObjectPtr<coordinateSystems>(typeName); + + if (ptr) { - return obr.lookupObject<coordinateSystems>(typeName); + return *ptr; } - else - { - return obr.store + + // Read construct from registry + return obr.store + ( + new coordinateSystems ( - new coordinateSystems + IOobject ( - IOobject - ( - typeName, - obr.time().constant(), - obr, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE - ) + typeName, + obr.time().constant(), + obr, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE ) - ); - } + ) + ); } @@ -107,7 +152,7 @@ Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const } else if (key.isPattern()) { - indices = findStrings(key, this->toc()); + indices = findStrings(key, this->names()); } else { @@ -163,16 +208,39 @@ bool Foam::coordinateSystems::found(const keyType& key) const } -Foam::wordList Foam::coordinateSystems::toc() const +Foam::wordList Foam::coordinateSystems::names() const { - wordList keywords(size()); + wordList output(size()); forAll(*this, i) { - keywords[i] = operator[](i).name(); + output[i] = operator[](i).name(); } - return keywords; + return output; +} + + +Foam::wordList Foam::coordinateSystems::names(const keyType& matcher) const +{ + return + ( + matcher.isPattern() + ? namesImpl(*this, regExp(matcher), false) + : namesImpl(*this, matcher, false) + ); +} + + +Foam::wordList Foam::coordinateSystems::names(const wordRe& matcher) const +{ + return namesImpl(*this, matcher, false); +} + + +Foam::wordList Foam::coordinateSystems::names(const wordRes& matcher) const +{ + return namesImpl(*this, matcher, false); } diff --git a/src/meshTools/coordinateSystems/coordinateSystems.H b/src/meshTools/coordinateSystems/coordinateSystems.H index 9c33082eff9fdbf393b2eeeae680633afd32cff2..2576d1a664930223809a2bb0a4d4ad61fabc1ee4 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.H +++ b/src/meshTools/coordinateSystems/coordinateSystems.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,6 +59,7 @@ SourceFiles #include "coordinateSystem.H" #include "IOPtrList.H" +#include "wordRes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -73,14 +74,13 @@ class coordinateSystems : public IOPtrList<coordinateSystem> { - // Private Member Functions //- Disallow default bitwise copy construct - coordinateSystems(const coordinateSystems&); + coordinateSystems(const coordinateSystems&) = delete; //- Disallow default bitwise assignment - void operator=(const coordinateSystems&); + void operator=(const coordinateSystems&) = delete; public: @@ -125,8 +125,23 @@ public: //- Search for given key bool found(const keyType& key) const; - //- Return the table of contents (list of all keywords) - wordList toc() const; + //- A list of the coordinate-system names + wordList names() const; + + //- A list of the coordinate-system names satisfying the input matcher + wordList names(const keyType& matcher) const; + + //- A list of the coordinate-system names satisfying the input matcher + wordList names(const wordRe& matcher) const; + + //- A list of the coordinate-system names satisfying the input matcher + wordList names(const wordRes& matcher) const; + + //- Identical to names() + inline wordList toc() const + { + return names(); + } //- Write data bool writeData(Ostream&) const;