COMP: avoid compiler warnings about phasePairKey friend functions

- improve alignment of various phasePairKey implementations
This commit is contained in:
Mark Olesen 2018-07-24 10:51:12 +02:00
parent d25dd342fa
commit b1996f348c
6 changed files with 87 additions and 102 deletions

View File

@ -27,14 +27,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::phasePairKey::hash::hash()
{}
Foam::phasePairKey::phasePairKey()
{}
Foam::phasePairKey::phasePairKey Foam::phasePairKey::phasePairKey
( (
const word& name1, const word& name1,
@ -71,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
word::hash()(key.second()) word::hash()(key.second())
); );
} }
else
{ return word::hash()(key.first()) + word::hash()(key.second());
return
word::hash()(key.first())
+ word::hash()(key.second());
}
} }
@ -88,14 +76,13 @@ bool Foam::operator==
const phasePairKey& b const phasePairKey& b
) )
{ {
const label c = Pair<word>::compare(a,b); const auto cmp = Pair<word>::compare(a,b);
return return
(
(a.ordered_ == b.ordered_) (a.ordered_ == b.ordered_)
&& ( && (a.ordered_ ? (cmp == 1) : cmp)
(a.ordered_ && (c == 1)) );
|| (!a.ordered_ && (c != 0))
);
} }
@ -121,7 +108,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
{ {
key.ordered_ = false; key.ordered_ = false;
} }
else if(temp[1] == "to") else if (temp[1] == "to")
{ {
key.ordered_ = true; key.ordered_ = true;
} }
@ -130,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
FatalErrorInFunction FatalErrorInFunction
<< "Phase pair type is not recognised. " << "Phase pair type is not recognised. "
<< temp << temp
<< "Use (phaseDispersed to phaseContinuous) for an ordered" << "Use (phaseDispersed to phaseContinuous) for an ordered pair, "
<< "pair, or (phase1 and pase2) for an unordered pair." << "or (phase1 and phase2) for an unordered pair."
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -40,6 +40,15 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations
class phasePairKey;
bool operator==(const phasePairKey& a, const phasePairKey& b);
bool operator!=(const phasePairKey& a, const phasePairKey& b);
Istream& operator>>(Istream& is, phasePairKey& key);
Ostream& operator<<(Ostream& os, const phasePairKey& key);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class phasePairKey Declaration Class phasePairKey Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -48,29 +57,6 @@ class phasePairKey
: :
public Pair<word> public Pair<word>
{ {
public:
class hash
:
public Hash<phasePairKey>
{
public:
// Constructors
//- Construct null
hash();
// Member operators
//- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const;
};
private:
// Private data // Private data
//- Flag to indicate whether ordering is important //- Flag to indicate whether ordering is important
@ -79,12 +65,20 @@ private:
public: public:
//- Ordered or unordered hashing of word pair
struct hash
{
//- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const;
};
// Constructors // Constructors
//- Construct null //- Construct null
phasePairKey(); phasePairKey() {} // = default
//- Construct from names and the ordering flag //- Construct from names and optional ordering flag
phasePairKey phasePairKey
( (
const word& name1, const word& name1,
@ -93,7 +87,7 @@ public:
); );
// Destructor //- Destructor
virtual ~phasePairKey() = default; virtual ~phasePairKey() = default;
@ -105,16 +99,16 @@ public:
// Friend Operators // Friend Operators
//- Test if keys are equal //- Test for equality
friend bool operator==(const phasePairKey& a, const phasePairKey& b); friend bool operator==(const phasePairKey& a, const phasePairKey& b);
//- Test if keys are unequal //- Test for inequality
friend bool operator!=(const phasePairKey& a, const phasePairKey& b); friend bool operator!=(const phasePairKey& a, const phasePairKey& b);
//- Read from stdin //- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key); friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout //- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key); friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
}; };

View File

@ -63,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
word::hash()(key.second()) word::hash()(key.second())
); );
} }
else
{ return word::hash()(key.first()) + word::hash()(key.second());
return
word::hash()(key.first())
+ word::hash()(key.second());
}
} }
@ -80,14 +76,13 @@ bool Foam::operator==
const phasePairKey& b const phasePairKey& b
) )
{ {
const label cmp = Pair<word>::compare(a,b); const auto cmp = Pair<word>::compare(a,b);
return return
(
(a.ordered_ == b.ordered_) (a.ordered_ == b.ordered_)
&& ( && (a.ordered_ ? (cmp == 1) : cmp)
(a.ordered_ && (cmp == 1)) );
|| (!a.ordered_ && (cmp != 0))
);
} }

View File

@ -41,14 +41,13 @@ namespace Foam
{ {
// Forward declarations // Forward declarations
class phasePairKey; class phasePairKey;
bool operator==(const phasePairKey&, const phasePairKey&); bool operator==(const phasePairKey& a, const phasePairKey& b);
bool operator!=(const phasePairKey&, const phasePairKey&); bool operator!=(const phasePairKey& a, const phasePairKey& b);
Istream& operator>>(Istream&, phasePairKey&); Istream& operator>>(Istream& is, phasePairKey& key);
Ostream& operator<<(Ostream&, const phasePairKey&); Ostream& operator<<(Ostream& os, const phasePairKey& key);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -64,11 +63,13 @@ class phasePairKey
//- Flag to indicate whether ordering is important //- Flag to indicate whether ordering is important
bool ordered_; bool ordered_;
public: public:
//- Ordered or unordered hashing of word pair
struct hash struct hash
{ {
// Generate a hash from a phase pair key //- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const; label operator()(const phasePairKey& key) const;
}; };
@ -78,7 +79,7 @@ public:
//- Construct null //- Construct null
phasePairKey() {} // = default phasePairKey() {} // = default
//- Construct from names and the ordering flag //- Construct from names and optional ordering flag
phasePairKey phasePairKey
( (
const word& name1, const word& name1,
@ -87,7 +88,7 @@ public:
); );
// Destructor //- Destructor
virtual ~phasePairKey() = default; virtual ~phasePairKey() = default;
@ -99,16 +100,16 @@ public:
// Friend Operators // Friend Operators
//- Test if keys are equal //- Test for equality
friend bool operator==(const phasePairKey& a, const phasePairKey& b); friend bool operator==(const phasePairKey& a, const phasePairKey& b);
//- Test if keys are unequal //- Test for inequality
friend bool operator!=(const phasePairKey& a, const phasePairKey& b); friend bool operator!=(const phasePairKey& a, const phasePairKey& b);
//- Read from stdin //- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key); friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout //- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key); friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
}; };

View File

@ -39,6 +39,14 @@ Foam::phasePairKey::phasePairKey
{} {}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::phasePairKey::ordered() const
{
return ordered_;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::label Foam::phasePairKey::hash::operator() Foam::label Foam::phasePairKey::hash::operator()
@ -55,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
word::hash()(key.second()) word::hash()(key.second())
); );
} }
else
{ return word::hash()(key.first()) + word::hash()(key.second());
return
word::hash()(key.first())
+ word::hash()(key.second());
}
} }
@ -72,14 +76,13 @@ bool Foam::operator==
const phasePairKey& b const phasePairKey& b
) )
{ {
const label cmp = Pair<word>::compare(a,b); const auto cmp = Pair<word>::compare(a,b);
return return
(
(a.ordered_ == b.ordered_) (a.ordered_ == b.ordered_)
&& ( && (a.ordered_ ? (cmp == 1) : cmp)
(a.ordered_ && (cmp == 1)) );
|| (!a.ordered_ && (cmp != 0))
);
} }
@ -114,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
FatalErrorInFunction FatalErrorInFunction
<< "Phase pair type is not recognised. " << "Phase pair type is not recognised. "
<< temp << temp
<< "Use (phaseDispersed in phaseContinuous) for an ordered" << "Use (phaseDispersed in phaseContinuous) for an ordered pair, "
<< "pair, or (phase1 and pase2) for an unordered pair." << "or (phase1 and phase2) for an unordered pair."
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -41,15 +41,13 @@ namespace Foam
{ {
// Forward declarations // Forward declarations
class phasePairKey; class phasePairKey;
bool operator==(const phasePairKey&, const phasePairKey&); bool operator==(const phasePairKey& a, const phasePairKey& b);
bool operator!=(const phasePairKey&, const phasePairKey&); bool operator!=(const phasePairKey& a, const phasePairKey& b);
Istream& operator>>(Istream&, phasePairKey&);
Ostream& operator<<(Ostream&, const phasePairKey&);
Istream& operator>>(Istream& is, phasePairKey& key);
Ostream& operator<<(Ostream& os, const phasePairKey& key);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class phasePairKey Declaration Class phasePairKey Declaration
@ -66,9 +64,10 @@ class phasePairKey
public: public:
//- Ordered or unordered hashing of word pair
struct hash struct hash
{ {
// Generate a hash from a phase pair key //- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const; label operator()(const phasePairKey& key) const;
}; };
@ -78,31 +77,37 @@ public:
//- Construct null //- Construct null
phasePairKey() {} // = default phasePairKey() {} // = default
//- Construct from names and the ordering flag //- Construct from names and optional ordering flag
phasePairKey phasePairKey
( (
const word& name1, const word& name1,
const word& name2, const word& name2,
const bool ordered const bool ordered = false
); );
// Destructor //- Destructor
virtual ~phasePairKey() = default; virtual ~phasePairKey() = default;
// Access
//- Return the ordered flag
bool ordered() const;
// Friend Operators // Friend Operators
//- Test if keys are equal //- Test for equality
friend bool operator==(const phasePairKey& a, const phasePairKey& b); friend bool operator==(const phasePairKey& a, const phasePairKey& b);
//- Test if keys are unequal //- Test for inequality
friend bool operator!=(const phasePairKey& a, const phasePairKey& b); friend bool operator!=(const phasePairKey& a, const phasePairKey& b);
//- Read from stdin //- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key); friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout //- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key); friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
}; };