Prevent copying of switches: this causes double deletion error

This commit is contained in:
Hrvoje Jasak 2015-06-04 18:04:33 +01:00
parent 50dc19899e
commit 7f92fbcae4
10 changed files with 89 additions and 84 deletions

View file

@ -59,6 +59,15 @@ class constantsSwitch
: :
public controlSwitches<scalar> public controlSwitches<scalar>
{ {
// Private member functions
//- Disallow construct as copy
constantsSwitch(const constantsSwitch&);
//- Disallow default bitwise assignment
void operator=(const constantsSwitch&);
public: public:
// Constructors // Constructors

View file

@ -39,20 +39,6 @@ namespace debug
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::debug::controlSwitches<Type>::controlSwitches()
:
switchValue_(Type(0)),
switchDescription_("")
{}
template<class T>
Foam::debug::controlSwitches<T>::controlSwitches(const T& switchValue)
:
switchValue_(switchValue)
{}
template<class T> template<class T>
Foam::debug::controlSwitches<T>::controlSwitches Foam::debug::controlSwitches<T>::controlSwitches
( (
@ -101,19 +87,6 @@ Foam::debug::controlSwitches<T>::controlSwitches
} }
template<class T>
Foam::debug::controlSwitches<T>::controlSwitches
(
const debug::controlSwitches<T>& csw
)
:
switchName_(csw.switchName_),
switchValue_(csw.switchValue_),
switchDescription_(csw.switchDescription_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class T> template<class T>
@ -137,37 +110,7 @@ Foam::debug::controlSwitches<T>::~controlSwitches()
} }
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
void Foam::debug::controlSwitches<T>::operator=
(
const debug::controlSwitches<T>& rhs
)
{
// Check for assignment to self
if (this == &rhs)
{
std::cerr
<< "Foam::debug::controlSwitches<T>::operator="
<< "(const Foam::controlSwitches<T>&)"
<< "--> FOAM FATAL ERROR: "
<< "Attempted assignment to self"
<< std::endl;
std::abort();
exit(-1);
}
else
{
switchValue_ = rhs.switchValue_;
switchDescription_ = rhs.switchDescription_;
}
}
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
template<class T> template<class T>
void printControlSwitches void printControlSwitches

View file

@ -231,16 +231,19 @@ class controlSwitches
switchValuesTable_; switchValuesTable_;
// Private member functions
//- Disallow construct as copy
controlSwitches(const controlSwitches<T>&);
//- Disallow default bitwise assignment
void operator=(const controlSwitches<T>&);
public: public:
// Constructors // Constructors
//- Construct null
controlSwitches();
//- Construct from components
explicit controlSwitches(const T& data);
controlSwitches controlSwitches
( (
const std::string& switchName, const std::string& switchName,
@ -251,9 +254,6 @@ public:
switchesValues switchesValues
); );
//- Construct as copy
controlSwitches(const controlSwitches&);
//- Destructor //- Destructor
~controlSwitches(); ~controlSwitches();
@ -262,7 +262,7 @@ public:
// Member Functions // Member Functions
// Check // Check
bool boolean_test() const bool test() const
{ {
// Perform Boolean logic here // Perform Boolean logic here
return switchValue_ != 0; return switchValue_ != 0;
@ -274,9 +274,6 @@ public:
//- Assignement operator //- Assignement operator
void operator=(const T&); void operator=(const T&);
//- Assignement operator
void operator=(const controlSwitches&);
//- & operator //- & operator
const T operator&(const T&); const T operator&(const T&);

View file

@ -58,6 +58,15 @@ class debugSwitch
: :
public controlSwitches<int> public controlSwitches<int>
{ {
// Private member functions
//- Disallow construct as copy
debugSwitch(const debugSwitch&);
//- Disallow default bitwise assignment
void operator=(const debugSwitch&);
public: public:
// Constructors // Constructors

View file

@ -54,8 +54,18 @@ ListInfoControlSwitches;
extern ListInfoControlSwitches* infoSwitchValues_; extern ListInfoControlSwitches* infoSwitchValues_;
class infoSwitch class infoSwitch
: public controlSwitches<int> :
public controlSwitches<int>
{ {
// Private member functions
//- Disallow construct as copy
infoSwitch(const infoSwitch&);
//- Disallow default bitwise assignment
void operator=(const infoSwitch&);
public: public:
// Constructors // Constructors

View file

@ -59,6 +59,15 @@ class optimisationSwitch
: :
public controlSwitches<int> public controlSwitches<int>
{ {
// Private member functions
//- Disallow construct as copy
optimisationSwitch(const optimisationSwitch&);
//- Disallow default bitwise assignment
void operator=(const optimisationSwitch&);
public: public:
// Constructors // Constructors

View file

@ -78,7 +78,7 @@ public:
operator boolType() const operator boolType() const
{ {
return (static_cast<const T*>(this))->boolean_test() return (static_cast<const T*>(this))->test()
? &safeBoolBase::thisTypeDoesNotSupportComparisons : 0; ? &safeBoolBase::thisTypeDoesNotSupportComparisons : 0;
} }

View file

@ -58,6 +58,15 @@ class tolerancesSwitch
: :
public controlSwitches<scalar> public controlSwitches<scalar>
{ {
// Private member functions
//- Disallow construct as copy
tolerancesSwitch(const tolerancesSwitch&);
//- Disallow default bitwise assignment
void operator=(const tolerancesSwitch&);
public: public:
// Constructors // Constructors

View file

@ -351,35 +351,54 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const BlockLduMatrix<Type>& ldum)
else else
{ {
// Dummy write for consistency // Dummy write for consistency
os.writeKeyword("diagonal") << typename BlockLduMatrix<Type>::TypeCoeffField os.writeKeyword("diagonal")
(ldum.lduAddr().size()) << token::END_STATEMENT << nl; << typename BlockLduMatrix<Type>::TypeCoeffField
(
ldum.lduAddr().size()
)
<< token::END_STATEMENT << nl;
} }
if (ldum.upperPtr_) if (ldum.upperPtr_)
{ {
os.writeKeyword("upper") << *ldum.upperPtr_ << token::END_STATEMENT << nl; os.writeKeyword("upper")
<< *ldum.upperPtr_
<< token::END_STATEMENT << nl;
} }
else else
{ {
// Dummy write for consistency // Dummy write for consistency
os.writeKeyword("upper") << typename BlockLduMatrix<Type>::TypeCoeffField os.writeKeyword("upper")
(ldum.lduAddr().lowerAddr().size()) << token::END_STATEMENT << nl; << typename BlockLduMatrix<Type>::TypeCoeffField
(
ldum.lduAddr().lowerAddr().size()
)
<< token::END_STATEMENT << nl;
} }
if (ldum.lowerPtr_) if (ldum.lowerPtr_)
{ {
os.writeKeyword("lower") << *ldum.lowerPtr_ << token::END_STATEMENT << nl; os.writeKeyword("lower")
<< *ldum.lowerPtr_ << token::END_STATEMENT << nl;
} }
else else
{ {
// Dummy write for consistency // Dummy write for consistency
os.writeKeyword("lower") << typename BlockLduMatrix<Type>::TypeCoeffField os.writeKeyword("lower")
(ldum.lduAddr().lowerAddr().size()) << token::END_STATEMENT << nl; << typename BlockLduMatrix<Type>::TypeCoeffField
(
ldum.lduAddr().lowerAddr().size()
)
<< token::END_STATEMENT << nl;
} }
os.writeKeyword("coupleUpper") << ldum.coupleUpper_ << token::END_STATEMENT << endl; os.writeKeyword("coupleUpper")
<< ldum.coupleUpper_
<< token::END_STATEMENT << endl;
os.writeKeyword("coupleLower") << ldum.coupleLower_ << token::END_STATEMENT << endl; os.writeKeyword("coupleLower")
<< ldum.coupleLower_
<< token::END_STATEMENT << endl;
os.check("Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&"); os.check("Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&");

View file

@ -209,7 +209,7 @@ void Foam::coarseAmgLevel::solve
} }
// Switch of debug in top-level direct solve // Switch of debug in top-level direct solve
debug::debugSwitch oldDebug = lduMatrix::debug; label oldDebug = lduMatrix::debug();
if (matrixPtr_->matrix().symmetric()) if (matrixPtr_->matrix().symmetric())
{ {