STYLE: rename toLabel, toLabelRange classes -> labelOp, labelRangeOp

- make purpose as functors _slightly_ clearer.

- base definition removed for stricter enforcement of the specialization
  requirement.
This commit is contained in:
Mark Olesen
2018-04-11 22:48:03 +02:00
parent 97dc9f4029
commit fc5895f1df
8 changed files with 33 additions and 20 deletions

View File

@ -426,7 +426,7 @@ int main(int argc, char *argv[])
auto output = ListOps::create<label> auto output = ListOps::create<label>
( (
input, input,
toLabel<int64_t>() labelOp<int64_t>()
); );
Info<< "label (from int64): " << flatOutput(output) << endl; Info<< "label (from int64): " << flatOutput(output) << endl;
} }
@ -438,7 +438,7 @@ int main(int argc, char *argv[])
auto output = ListOps::create<label> auto output = ListOps::create<label>
( (
input, input,
toLabel<int32_t>() labelOp<int32_t>()
); );
Info<< "label (from int32): " << flatOutput(output) << endl; Info<< "label (from int32): " << flatOutput(output) << endl;
} }

View File

@ -1010,7 +1010,7 @@ Foam::label Foam::checkGeometry
ListOps::create<label> ListOps::create<label>
( (
UPstream::procID(UPstream::worldComm), UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label labelOp<int>() // int -> label
), ),
ami.srcWeightsSum(), ami.srcWeightsSum(),
mergedWeights mergedWeights
@ -1064,7 +1064,7 @@ Foam::label Foam::checkGeometry
ListOps::create<label> ListOps::create<label>
( (
UPstream::procID(UPstream::worldComm), UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label labelOp<int>() // int -> label
), ),
ami.tgtWeightsSum(), ami.tgtWeightsSum(),
mergedWeights mergedWeights

View File

@ -87,7 +87,7 @@ void writeWeights
ListOps::create<label> ListOps::create<label>
( (
UPstream::procID(UPstream::worldComm), UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label labelOp<int>() // int -> label
), ),
wghtSum, wghtSum,
mergedWeights mergedWeights

View File

@ -478,7 +478,7 @@ void setValue
// auto labels = ListOps::create<label> // auto labels = ListOps::create<label>
// ( // (
// ints, // ints,
// toLabel<int>() // labelOp<int>()
// ); // );
// //
// auto vectors = ListOps::create<vector> // auto vectors = ListOps::create<vector>

View File

@ -426,9 +426,9 @@ public:
// Global Functions // Global Functions
//- Get the labelRange for a polyPatch //- The labelRange of a polyPatch
template<> template<>
struct toLabelRange<polyPatch> struct labelRangeOp<polyPatch>
{ {
labelRange operator()(const polyPatch& pp) const labelRange operator()(const polyPatch& pp) const
{ {

View File

@ -122,15 +122,16 @@ inline label component(const label l, const direction)
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Struct toLabel Declaration Struct labelOp Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- Conversion to label structure //- Conversion/extraction to label operation
template<class Type> struct toLabel {}; // Specialization of this shall provide a corresponding \c operator().
template<class> struct labelOp;
//- Convert (likely promote) from int32_t to label //- Convert (likely promote) from int32_t to label
template<> template<>
struct toLabel<int32_t> struct labelOp<int32_t>
{ {
constexpr label operator()(const int32_t& val) const noexcept constexpr label operator()(const int32_t& val) const noexcept
{ {
@ -141,7 +142,7 @@ struct toLabel<int32_t>
//- Convert (possibly truncate) from int64_t to label //- Convert (possibly truncate) from int64_t to label
template<> template<>
struct toLabel<int64_t> struct labelOp<int64_t>
{ {
constexpr label operator()(const int64_t& val) const noexcept constexpr label operator()(const int64_t& val) const noexcept
{ {

View File

@ -25,7 +25,7 @@ Class
Foam::labelRange Foam::labelRange
Description Description
A range of labels defined by a start and a size. An range or interval of labels defined by a start and a size.
SourceFiles SourceFiles
labelRange.C labelRange.C
@ -248,14 +248,14 @@ public:
public: public:
// Constructors // Constructors
//- Construct from range at given local index. //- Construct from range at given local index.
// If the local index is out of range (eg, negaative), // If the local index is out of range (eg, negaative),
// this creates the 'end' iterator // this creates the 'end' iterator
inline const_iterator(const labelRange* range, const label i=0); inline const_iterator(const labelRange* range, const label i=0);
// Member operators // Member Operators
//- Return the current (global) value //- Return the current (global) value
inline label operator*() const; inline label operator*() const;
@ -293,8 +293,20 @@ public:
// Global Functions // Global Functions
//- Conversion to labelRange operations //- Conversion/extraction to labelRange operation (functor).
template<class Type> struct toLabelRange {}; // Specializations shall provide a corresponding \c operator().
// For example,
// \code
// template<>
// struct labelRangeOp<polyPatch>
// {
// labelRange operator()(const polyPatch& pp) const
// {
// return labelRange(pp.start(), pp.size());
// }
// };
// \endcode
template<class> struct labelRangeOp;
// Global Operators // Global Operators

View File

@ -183,9 +183,9 @@ public:
// Global Functions // Global Functions
//- Get the labelRange for a surfZone //- The labelRange of a surfZone
template<> template<>
struct toLabelRange<surfZone> struct labelRangeOp<surfZone>
{ {
labelRange operator()(const surfZone& zone) const labelRange operator()(const surfZone& zone) const
{ {