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

COMP: avoid compiler warnings about phasePairKey friend functions

- improve alignment of various phasePairKey implementations
parent d25dd342
Branches
Tags
No related merge requests found
......@@ -27,14 +27,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::phasePairKey::hash::hash()
{}
Foam::phasePairKey::phasePairKey()
{}
Foam::phasePairKey::phasePairKey
(
const word& name1,
......@@ -71,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
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 label c = Pair<word>::compare(a,b);
const auto cmp = Pair<word>::compare(a,b);
return
(
(a.ordered_ == b.ordered_)
&& (
(a.ordered_ && (c == 1))
|| (!a.ordered_ && (c != 0))
);
&& (a.ordered_ ? (cmp == 1) : cmp)
);
}
......@@ -121,7 +108,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
{
key.ordered_ = false;
}
else if(temp[1] == "to")
else if (temp[1] == "to")
{
key.ordered_ = true;
}
......@@ -130,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
FatalErrorInFunction
<< "Phase pair type is not recognised. "
<< temp
<< "Use (phaseDispersed to phaseContinuous) for an ordered"
<< "pair, or (phase1 and pase2) for an unordered pair."
<< "Use (phaseDispersed to phaseContinuous) for an ordered pair, "
<< "or (phase1 and phase2) for an unordered pair."
<< exit(FatalError);
}
......
......@@ -40,6 +40,15 @@ SourceFiles
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
\*---------------------------------------------------------------------------*/
......@@ -48,29 +57,6 @@ class phasePairKey
:
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
//- Flag to indicate whether ordering is important
......@@ -79,12 +65,20 @@ private:
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
//- Construct null
phasePairKey();
phasePairKey() {} // = default
//- Construct from names and the ordering flag
//- Construct from names and optional ordering flag
phasePairKey
(
const word& name1,
......@@ -93,7 +87,7 @@ public:
);
// Destructor
//- Destructor
virtual ~phasePairKey() = default;
......@@ -105,16 +99,16 @@ public:
// Friend Operators
//- Test if keys are equal
//- Test for equality
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);
//- Read from stdin
//- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout
//- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
};
......
......@@ -63,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
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 label cmp = Pair<word>::compare(a,b);
const auto cmp = Pair<word>::compare(a,b);
return
(
(a.ordered_ == b.ordered_)
&& (
(a.ordered_ && (cmp == 1))
|| (!a.ordered_ && (cmp != 0))
);
&& (a.ordered_ ? (cmp == 1) : cmp)
);
}
......
......@@ -41,14 +41,13 @@ namespace Foam
{
// Forward declarations
class phasePairKey;
bool operator==(const phasePairKey&, const phasePairKey&);
bool operator!=(const phasePairKey&, const phasePairKey&);
bool operator==(const phasePairKey& a, const phasePairKey& b);
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);
/*---------------------------------------------------------------------------*\
......@@ -64,11 +63,13 @@ class phasePairKey
//- Flag to indicate whether ordering is important
bool ordered_;
public:
//- Ordered or unordered hashing of word pair
struct hash
{
// Generate a hash from a phase pair key
//- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const;
};
......@@ -78,7 +79,7 @@ public:
//- Construct null
phasePairKey() {} // = default
//- Construct from names and the ordering flag
//- Construct from names and optional ordering flag
phasePairKey
(
const word& name1,
......@@ -87,7 +88,7 @@ public:
);
// Destructor
//- Destructor
virtual ~phasePairKey() = default;
......@@ -99,16 +100,16 @@ public:
// Friend Operators
//- Test if keys are equal
//- Test for equality
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);
//- Read from stdin
//- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout
//- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
};
......
......@@ -39,6 +39,14 @@ Foam::phasePairKey::phasePairKey
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::phasePairKey::ordered() const
{
return ordered_;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::label Foam::phasePairKey::hash::operator()
......@@ -55,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator()
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 label cmp = Pair<word>::compare(a,b);
const auto cmp = Pair<word>::compare(a,b);
return
(
(a.ordered_ == b.ordered_)
&& (
(a.ordered_ && (cmp == 1))
|| (!a.ordered_ && (cmp != 0))
);
&& (a.ordered_ ? (cmp == 1) : cmp)
);
}
......@@ -114,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
FatalErrorInFunction
<< "Phase pair type is not recognised. "
<< temp
<< "Use (phaseDispersed in phaseContinuous) for an ordered"
<< "pair, or (phase1 and pase2) for an unordered pair."
<< "Use (phaseDispersed in phaseContinuous) for an ordered pair, "
<< "or (phase1 and phase2) for an unordered pair."
<< exit(FatalError);
}
......
......@@ -41,15 +41,13 @@ namespace Foam
{
// Forward declarations
class phasePairKey;
bool operator==(const phasePairKey&, const phasePairKey&);
bool operator!=(const phasePairKey&, const phasePairKey&);
Istream& operator>>(Istream&, phasePairKey&);
Ostream& operator<<(Ostream&, const 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
......@@ -66,9 +64,10 @@ class phasePairKey
public:
//- Ordered or unordered hashing of word pair
struct hash
{
// Generate a hash from a phase pair key
//- Generate a hash from a phase pair key
label operator()(const phasePairKey& key) const;
};
......@@ -78,31 +77,37 @@ public:
//- Construct null
phasePairKey() {} // = default
//- Construct from names and the ordering flag
//- Construct from names and optional ordering flag
phasePairKey
(
const word& name1,
const word& name2,
const bool ordered
const bool ordered = false
);
// Destructor
//- Destructor
virtual ~phasePairKey() = default;
// Access
//- Return the ordered flag
bool ordered() const;
// Friend Operators
//- Test if keys are equal
//- Test for equality
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);
//- Read from stdin
//- Read from Istream
friend Istream& operator>>(Istream& is, phasePairKey& key);
//- Write to stdout
//- Write to Ostream
friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
};
......
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