mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add single-parameter PtrListOps::names (ie, no name filtering)
ENH: adjust fileName component method - the location \c npos returns the last component
This commit is contained in:
@ -224,7 +224,8 @@ void testDirname(const fileName& input)
|
||||
<< " path:" << input.path()
|
||||
<< " name:\"" << input.name() << '"'
|
||||
<< " ext:\"" << input.ext() << '"'
|
||||
<< " components: " << flatOutput(input.components()) << nl;
|
||||
<< " components: " << flatOutput(input.components())
|
||||
<< " last: " << input.component(string::npos) << nl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ SourceFiles
|
||||
#ifndef PtrListOps_H
|
||||
#define PtrListOps_H
|
||||
|
||||
#include "predicates.H"
|
||||
#include "PtrList.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
@ -169,6 +170,12 @@ List<word> names
|
||||
);
|
||||
|
||||
|
||||
//- List of names generated by calling \c name() for each list item
|
||||
//- no filtering (ie, predicates::always)
|
||||
template<class T>
|
||||
List<word> names(const UPtrList<T>& list);
|
||||
|
||||
|
||||
//- Find first list item with 'name()' that matches, -1 on failure
|
||||
template<class T, class UnaryMatchPredicate>
|
||||
label firstMatching
|
||||
|
||||
@ -166,6 +166,16 @@ Foam::List<Foam::word> Foam::PtrListOps::names
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::List<Foam::word> Foam::PtrListOps::names
|
||||
(
|
||||
const UPtrList<T>& list
|
||||
)
|
||||
{
|
||||
return PtrListOps::names(list, predicates::always());
|
||||
}
|
||||
|
||||
|
||||
template<class T, class UnaryMatchPredicate>
|
||||
Foam::label Foam::PtrListOps::firstMatching
|
||||
(
|
||||
|
||||
@ -485,9 +485,16 @@ Foam::word Foam::fileName::component
|
||||
{
|
||||
const auto parsed = stringOps::split<string>(*this, delim);
|
||||
|
||||
if (cmpt < parsed.size())
|
||||
if (parsed.size())
|
||||
{
|
||||
return parsed[cmpt].str();
|
||||
if (cmpt == std::string::npos)
|
||||
{
|
||||
return parsed.last().str();
|
||||
}
|
||||
else if (cmpt < parsed.size())
|
||||
{
|
||||
return parsed[cmpt].str();
|
||||
}
|
||||
}
|
||||
|
||||
return word();
|
||||
|
||||
@ -358,7 +358,8 @@ public:
|
||||
// \endverbatim
|
||||
wordList components(const char delim = '/') const;
|
||||
|
||||
//- Return a single component of the path
|
||||
//- Return a single component of the path or empty if out of range
|
||||
// The location \c npos returns the last component
|
||||
word component(const size_type cmpt, const char delim = '/') const;
|
||||
|
||||
|
||||
|
||||
@ -269,7 +269,7 @@ Foam::coordinateSystems::lookup(const word& name) const
|
||||
|
||||
Foam::wordList Foam::coordinateSystems::names() const
|
||||
{
|
||||
return PtrListOps::names(*this, predicates::always{});
|
||||
return PtrListOps::names(*this); // match any/all
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user