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

STYLE: provide coordinateSystems names() method for consistency

parent bdb616de
Branches
Tags
No related merge requests found
......@@ -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;
}
......
......@@ -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
);
......
......@@ -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);
}
......
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment