Commit 665b1f82 authored by Henry Weller's avatar Henry Weller
Browse files

Provide consistency in assignment operators

Always return void to avoid various bugs associated with automatic
type conversion.

Resolves request http://openfoam.org/mantisbt/view.php?id=1973
parent 7f67b3e4
......@@ -258,7 +258,7 @@ public:
//- Fix the vertex so that it can't be moved
inline bool& fixed();
inline indexedVertex& operator=(const indexedVertex& rhs)
inline void operator=(const indexedVertex& rhs)
{
Vb::operator=(rhs);
......@@ -268,8 +268,6 @@ public:
this->alignment_ = rhs.alignment();
this->targetCellSize_ = rhs.targetCellSize();
this->vertexFixed_ = rhs.fixed();
return *this;
}
inline bool operator==(const indexedVertex& rhs) const
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -286,8 +286,7 @@ Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const Foam::UList<bool>& lst)
void Foam::PackedBoolList::operator=(const Foam::UList<bool>& lst)
{
this->setSize(lst.size());
......@@ -296,8 +295,6 @@ Foam::PackedBoolList::operator=(const Foam::UList<bool>& lst)
{
set(elemI, lst[elemI]);
}
return *this;
}
......
......@@ -191,24 +191,24 @@ public:
// Member Operators
//- Assignment of all entries to the given value.
inline PackedBoolList& operator=(const bool val);
inline void operator=(const bool val);
//- Assignment operator.
inline PackedBoolList& operator=(const PackedBoolList&);
inline void operator=(const PackedBoolList&);
//- Assignment operator.
inline PackedBoolList& operator=(const PackedList<1>&);
inline void operator=(const PackedList<1>&);
//- Assignment operator.
PackedBoolList& operator=(const Foam::UList<bool>&);
void operator=(const Foam::UList<bool>&);
//- Assignment operator,
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator=(const labelUList& indices);
inline void operator=(const labelUList& indices);
//- Assignment operator,
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator=(const UIndirectList<label>&);
inline void operator=(const UIndirectList<label>&);
//- Complement operator
inline PackedBoolList operator~() const;
......
......@@ -126,47 +126,35 @@ inline Foam::Xfer<Foam::PackedBoolList> Foam::PackedBoolList::xfer()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const bool val)
inline void Foam::PackedBoolList::operator=(const bool val)
{
PackedList<1>::operator=(val);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const PackedBoolList& lst)
inline void Foam::PackedBoolList::operator=(const PackedBoolList& lst)
{
PackedList<1>::operator=(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const PackedList<1>& lst)
inline void Foam::PackedBoolList::operator=(const PackedList<1>& lst)
{
PackedList<1>::operator=(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const labelUList& indices)
inline void Foam::PackedBoolList::operator=(const labelUList& indices)
{
clear();
set(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const UIndirectList<label>& indices)
inline void Foam::PackedBoolList::operator=(const UIndirectList<label>& indices)
{
clear();
set(indices);
return *this;
}
......
......@@ -513,18 +513,15 @@ void Foam::PackedList<nBits>::writeEntry
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
{
StorageList::operator=(lst);
size_ = lst.size();
return *this;
}
template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const labelUList& lst)
void Foam::PackedList<nBits>::operator=(const labelUList& lst)
{
setCapacity(lst.size());
size_ = lst.size();
......@@ -533,13 +530,11 @@ Foam::PackedList<nBits>::operator=(const labelUList& lst)
{
set(i, lst[i]);
}
return *this;
}
template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const UIndirectList<label>& lst)
void Foam::PackedList<nBits>::operator=(const UIndirectList<label>& lst)
{
setCapacity(lst.size());
size_ = lst.size();
......@@ -548,7 +543,6 @@ Foam::PackedList<nBits>::operator=(const UIndirectList<label>& lst)
{
set(i, lst[i]);
}
return *this;
}
......
......@@ -398,16 +398,16 @@ public:
inline iteratorBase operator[](const label);
//- Assignment of all entries to the given value. Takes linear time.
inline PackedList<nBits>& operator=(const unsigned int val);
inline void operator=(const unsigned int val);
//- Assignment operator.
PackedList<nBits>& operator=(const PackedList<nBits>&);
void operator=(const PackedList<nBits>&);
//- Assignment operator.
PackedList<nBits>& operator=(const labelUList&);
void operator=(const labelUList&);
//- Assignment operator.
PackedList<nBits>& operator=(const UIndirectList<label>&);
void operator=(const UIndirectList<label>&);
// Iterators and helpers
......@@ -468,11 +468,11 @@ public:
//- Assign value, not position.
// This allows packed[0] = packed[3] for assigning values
inline unsigned int operator=(const iteratorBase&);
inline void operator=(const iteratorBase&);
//- Assign value.
// A non-existent entry will be auto-vivified.
inline unsigned int operator=(const unsigned int val);
inline void operator=(const unsigned int val);
//- Conversion operator
// Never auto-vivify entries.
......@@ -522,7 +522,7 @@ public:
//- Assign from iteratorBase, eg iter = packedlist[i]
// An out-of-range iterator is assigned end()
inline iterator& operator=(const iteratorBase&);
inline void operator=(const iteratorBase&);
//- Return value
inline unsigned int operator*() const;
......@@ -583,7 +583,7 @@ public:
//- Assign from iteratorBase or derived
// eg, iter = packedlist[i] or even iter = list.begin()
inline const_iterator& operator=(const iteratorBase&);
inline void operator=(const iteratorBase&);
//- Return referenced value directly
inline unsigned int operator*() const;
......
......@@ -356,18 +356,21 @@ inline bool Foam::PackedList<nBits>::iteratorBase::operator!=
template<unsigned nBits>
inline unsigned int
Foam::PackedList<nBits>::iteratorBase::operator=(const iteratorBase& iter)
inline void Foam::PackedList<nBits>::iteratorBase::operator=
(
const iteratorBase& iter
)
{
const unsigned int val = iter.get();
this->set(val);
return val;
}
template<unsigned nBits>
inline unsigned int
Foam::PackedList<nBits>::iteratorBase::operator=(const unsigned int val)
inline void Foam::PackedList<nBits>::iteratorBase::operator=
(
const unsigned int val
)
{
// lazy evaluation - increase size on assigment
if (index_ >= list_->size_)
......@@ -376,7 +379,6 @@ Foam::PackedList<nBits>::iteratorBase::operator=(const unsigned int val)
}
this->set(val);
return val;
}
......@@ -517,8 +519,10 @@ inline bool Foam::PackedList<nBits>::const_iterator::operator!=
template<unsigned nBits>
inline typename Foam::PackedList<nBits>::iterator&
Foam::PackedList<nBits>::iterator::operator=(const iteratorBase& iter)
inline void Foam::PackedList<nBits>::iterator::operator=
(
const iteratorBase& iter
)
{
this->list_ = iter.list_;
this->index_ = iter.index_;
......@@ -529,14 +533,14 @@ Foam::PackedList<nBits>::iterator::operator=(const iteratorBase& iter)
{
this->index_ = this->list_->size_;
}
return *this;
}
template<unsigned nBits>
inline typename Foam::PackedList<nBits>::const_iterator&
Foam::PackedList<nBits>::const_iterator::operator=(const iteratorBase& iter)
inline void Foam::PackedList<nBits>::const_iterator::operator=
(
const iteratorBase& iter
)
{
this->list_ = iter.list_;
this->index_ = iter.index_;
......@@ -1066,8 +1070,7 @@ Foam::PackedList<nBits>::operator[](const label i)
template<unsigned nBits>
inline Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const unsigned int val)
inline void Foam::PackedList<nBits>::operator=(const unsigned int val)
{
const label packLen = packedLength();
......@@ -1111,8 +1114,6 @@ Foam::PackedList<nBits>::operator=(const unsigned int val)
StorageList::operator[](i) = 0u;
}
}
return *this;
}
......
......@@ -258,7 +258,7 @@ void Foam::PtrList<T>::reorder(const labelUList& oldToNew)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
Foam::PtrList<T>& Foam::PtrList<T>::operator=(const PtrList<T>& a)
void Foam::PtrList<T>::operator=(const PtrList<T>& a)
{
if (this == &a)
{
......@@ -290,9 +290,6 @@ Foam::PtrList<T>& Foam::PtrList<T>::operator=(const PtrList<T>& a)
<< " for type " << typeid(T).name()
<< abort(FatalError);
}
return *this;
}
......
......@@ -252,9 +252,8 @@ public:
//- Return element const pointer.
inline const T* operator()(const label) const;
//- Assignment.
PtrList<T>& operator=(const PtrList<T>&);
void operator=(const PtrList<T>&);
// STL type definitions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -188,17 +188,15 @@ public:
}
//- Assignment from enumerated value
const Switch& operator=(const switchType sw)
void operator=(const switchType sw)
{
switch_ = sw;
return *this;
}
//- Assignment from bool
const Switch& operator=(const bool b)
void operator=(const bool b)
{
switch_ = (b ? Switch::TRUE : Switch::FALSE);
return *this;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -126,13 +126,13 @@ public:
// Member operators
inline const complex& operator=(const complex&);
inline void operator=(const complex&);
inline void operator+=(const complex&);
inline void operator-=(const complex&);
inline void operator*=(const complex&);
inline void operator/=(const complex&);
inline const complex& operator=(const scalar);
inline void operator=(const scalar);
inline void operator+=(const scalar);
inline void operator-=(const scalar);
inline void operator*=(const scalar);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -75,11 +75,10 @@ inline complex complex::conjugate() const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline const complex& complex::operator=(const complex& c)
inline void complex::operator=(const complex& c)
{
re = c.re;
im = c.im;
return *this;
}
......@@ -109,11 +108,10 @@ inline void complex::operator/=(const complex& c)
}
inline const complex& complex::operator=(const scalar s)
inline void complex::operator=(const scalar s)
{
re = s;
im = 0.0;
return *this;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -51,11 +51,11 @@ class NullObject
NullObject()
{}
//- Prevent copy-construction
//- Disallow default bitwise copy construct
NullObject(const NullObject&);
//- Prevent assignment
NullObject& operator=(const NullObject&);
//- Disallow default bitwise assignment
void operator=(const NullObject&);
public:
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -26,7 +26,6 @@ License
#include "fileName.H"
#include "wordList.H"
#include "DynamicList.H"
#include "debug.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -35,6 +34,7 @@ const char* const Foam::fileName::typeName = "fileName";
int Foam::fileName::debug(debug::debugSwitch(fileName::typeName, 0));
const Foam::fileName Foam::fileName::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileName::fileName(const wordList& lst)
......@@ -74,32 +74,18 @@ Foam::fileName& Foam::fileName::toAbsolute()
}
//
// * remove repeated slashes
// /abc////def --> /abc/def
//
// * remove '/./'
// /abc/def/./ghi/. --> /abc/def/./ghi
// abc/def/./ --> abc/def
//
// * remove '/../'
// /abc/def/../ghi/jkl/nmo/.. --> /abc/ghi/jkl
// abc/../def/ghi/../jkl --> abc/../def/jkl
//
// * remove trailing '/'
//
bool Foam::fileName::clean()
{
// the top slash - we are never allowed to go above it
// The top slash - we are never allowed to go above it
string::size_type top = this->find('/');
// no slashes - nothing to do
// No slashes - nothing to do
if (top == string::npos)
{
return false;
}
// start with the '/' found:
// Start with the '/' found:
char prev = '/';
string::size_type nChar = top+1;
string::size_type maxLen = this->size();
......@@ -108,47 +94,46 @@ bool Foam::fileName::clean()
(
string::size_type src = nChar;
src < maxLen;
/*nil*/
)
{
char c = operator[](src++);
if (prev == '/')
{
// repeated '/' - skip it
// Repeated '/' - skip it
if (c == '/')
{
continue;
}
// could be '/./' or '/../'
// Could be '/./' or '/../'
if (c == '.')
{
// found trailing '/.' - skip it
// Found trailing '/.' - skip it
if (src >= maxLen)
{
continue;
}
// peek at the next character
// Peek at the next character
char c1 = operator[](src);
// found '/./' - skip it
// Found '/./' - skip it
if (c1 == '/')
{
src++;
continue;
}
// it is '/..' or '/../'
// It is '/..' or '/../'
if (c1 == '.' && (src+1 >= maxLen || operator[](src+1) == '/'))
{
string::size_type parent;
// backtrack to find the parent directory
// minimum of 3 characters: '/x/../'
// strip it, provided it is above the top point
// Backtrack to find the parent directory
// Minimum of 3 characters: '/x/../'
// Strip it, provided it is above the top point
if
(
nChar > 2
......@@ -156,13 +141,13 @@ bool Foam::fileName::clean()
&& parent >= top
)
{
nChar = parent + 1; // retain '/' from the parent
nChar = parent + 1; // Ret