From: Konrad Rosenbaum Date: Thu, 16 Feb 2012 18:23:27 +0000 (+0100) Subject: make ctor with values explicit; make operator= self-assignment safe X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=570b2e8463020d802eb922ff014ade3505ab05c9;p=web%2Fkonrad%2Fpack.git make ctor with values explicit; make operator= self-assignment safe --- diff --git a/woc/qt/qtclass.cpp b/woc/qt/qtclass.cpp index 271abee..df29844 100644 --- a/woc/qt/qtclass.cpp +++ b/woc/qt/qtclass.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2011 by Konrad Rosenbaum +// Copyright (C) 2009-2012 by Konrad Rosenbaum // protected under the GNU GPL version 3 or at your option any newer. // See COPYING.GPL file that comes with this distribution. // @@ -231,6 +231,7 @@ void WocQtClass::classDeserializer(const WocClass&cls,MFile&hdr,MFile&src,QStrin scd+="}\n"; hcd+="\t"+cn+"& operator=(const "+cn+"&);\n"; scd+=cn+"& "+cn+"::operator=(const "+cn+"&o)\n{\n"; + scd+="\tif(this == &o)return *this;\n"; scd+="\t"+cnb+"::operator=(o);\n"; for(int i=0;i +// Copyright (C) 2009-2012 by Konrad Rosenbaum // protected under the GNU GPL version 3 or at your option any newer. // See COPYING.GPL file that comes with this distribution. // diff --git a/woc/qt/qtctrans.cpp b/woc/qt/qtctrans.cpp index c978e56..03a48d2 100644 --- a/woc/qt/qtctrans.cpp +++ b/woc/qt/qtctrans.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2011 by Konrad Rosenbaum +// Copyright (C) 2009-2012 by Konrad Rosenbaum // protected under the GNU GPL version 3 or at your option any newer. // See COPYING.GPL file that comes with this distribution. // @@ -161,7 +161,7 @@ void WocQtClientTransaction::genTors(QtCTrans&ct) { //define parametric constructor ct.hcd+=" protected:\n"; - ct.hcd+="\t"+ct.cn+"("+ct.xinlist+");\n"; + ct.hcd+="\texplicit "+ct.cn+"("+ct.xinlist+");\n"; //parametric constructor implementation ct.scd+=ct.cn+"::"+ct.cn+"("+ct.xinlist+")\n\t:"+m_transbase+"(iface)\n{\n"; ct.scd+="\tnew "+ct.cnp+"(this);\n"; @@ -183,12 +183,13 @@ void WocQtClientTransaction::genTors(QtCTrans&ct) ct.hcd+="\t"+ct.cn+"& operator=(const "+ct.cn+"&);\n"; //copy operator implemented ct.scd+=ct.cn+"& "+ct.cn+"::operator=(const "+ct.cn+"&t)\n{\n"; + ct.scd+="\tif(this == &t)return *this;\n"; ct.scd+="\t"+m_transbase+"::operator=(t);\n"; ct.scd+="\tp->detach(this);t.p->attach(this);\n"; ct.scd+="\treturn *this;\n}\n\n"; //destructor - ct.hcd+="\t~"+ct.cn+"();\n"; + ct.hcd+="\tvirtual ~"+ct.cn+"();\n"; ct.scd+=ct.cn+"::~"+ct.cn+"()\n{\n\tp->detach(this);\n}\n\n"; } diff --git a/woc/qt/qtstrans.cpp b/woc/qt/qtstrans.cpp index e438ff8..a4ca2cc 100644 --- a/woc/qt/qtstrans.cpp +++ b/woc/qt/qtstrans.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2011 by Konrad Rosenbaum +// Copyright (C) 2009-2012 by Konrad Rosenbaum // protected under the GNU GPL version 3 or at your option any newer. // See COPYING.GPL file that comes with this distribution. // @@ -143,7 +143,7 @@ void WocQtServerTransaction::genTors(QtSTrans&ct) //define parametric constructor ct.hcd+=" protected:\n"; ct.hcd+="\tfriend class "+m_parent->ifaceClassName()+";\n"; - ct.hcd+="\t"+ct.cn+"(QString,const WServerRequest&);\n"; + ct.hcd+="\texplicit "+ct.cn+"(QString,const WServerRequest&);\n"; //parametric constructor implementation ct.scd+=ct.cn+"::"+ct.cn+"(QString iface,const WServerRequest&request)\n"; ct.scd+="\t:"+m_transbase+"(iface)\n{\n"; @@ -165,6 +165,7 @@ void WocQtServerTransaction::genTors(QtSTrans&ct) ct.hcd+="\t"+ct.cn+"& operator=(const "+ct.cn+"&);\n"; //copy operator implemented ct.scd+=ct.cn+"& "+ct.cn+"::operator=(const "+ct.cn+"&t)\n{\n"; + ct.scd+="\tif(this==&t)return *this;\n"; ct.scd+="\t"+m_transbase+"::operator=(t);\n"; ct.scd+="\tp->detach(this);t.p->attach(this);\n"; ct.scd+="\treturn *this;\n}\n\n";