From 3894e689e9d3cad32cdc0cb84b548281232bf43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Wed, 16 Sep 2015 08:22:08 +0300 Subject: [PATCH] Refactor: PrivateAutoPtr must be initialized with a value This avoid the pitfall of forgetting to instantiate the private implementation. --- doomsday/sdk/libcore/include/de/libcore.h | 10 +++++----- doomsday/sdk/libcore/src/data/info.cpp | 6 +++--- doomsday/sdk/libcore/src/data/pathtreenode.cpp | 4 ++-- doomsday/sdk/libgui/src/graphics/modelbank.cpp | 4 +++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/doomsday/sdk/libcore/include/de/libcore.h b/doomsday/sdk/libcore/include/de/libcore.h index b535edb460..e65804522a 100644 --- a/doomsday/sdk/libcore/include/de/libcore.h +++ b/doomsday/sdk/libcore/include/de/libcore.h @@ -14,7 +14,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #ifndef LIBCORE_H @@ -118,7 +118,7 @@ * must use the platform-specific functions. */ #if defined(UNIX) && defined(DENG2_C_API_ONLY) -# include // strcasecmp etc. +# include // strcasecmp etc. #endif /* @@ -180,7 +180,7 @@ * Macro for determining the name of a type (using RTTI). */ #define DENG2_TYPE_NAME(t) (typeid(t).name()) - + /** * Macro for hiding the warning about an unused parameter. */ @@ -351,7 +351,7 @@ class PrivateAutoPtr DENG2_NO_ASSIGN(PrivateAutoPtr) public: - PrivateAutoPtr(InstType *p = 0) : ptr(p) {} + PrivateAutoPtr(InstType *p) : ptr(p) {} ~PrivateAutoPtr() { reset(); } InstType &operator * () const { return *ptr; } @@ -507,7 +507,7 @@ struct LoopResult operator int () const { return value; } operator GenericLoopResult () const { return GenericLoopResult(value); } }; - + /** * All serialization in all contexts use a common protocol version number. * Whenever anything changes in serialization, the protocol version needs to be diff --git a/doomsday/sdk/libcore/src/data/info.cpp b/doomsday/sdk/libcore/src/data/info.cpp index 68fd5e4670..a616ace65b 100644 --- a/doomsday/sdk/libcore/src/data/info.cpp +++ b/doomsday/sdk/libcore/src/data/info.cpp @@ -779,21 +779,21 @@ void Info::BlockElement::moveContents(BlockElement &destination) Info::Info() : d(new Instance(this)) {} -Info::Info(String const &source) +Info::Info(String const &source) : d(nullptr) { QScopedPointer inst(new Instance(this)); // parsing may throw exception inst->parse(source); d.reset(inst.take()); } -Info::Info(File const &file) +Info::Info(File const &file) : d(nullptr) { QScopedPointer inst(new Instance(this)); // parsing may throw exception inst->parse(file); d.reset(inst.take()); } -Info::Info(String const &source, IIncludeFinder const &finder) +Info::Info(String const &source, IIncludeFinder const &finder) : d(nullptr) { QScopedPointer inst(new Instance(this)); // parsing may throw exception inst->finder = &finder; diff --git a/doomsday/sdk/libcore/src/data/pathtreenode.cpp b/doomsday/sdk/libcore/src/data/pathtreenode.cpp index b41910809c..328aed180a 100644 --- a/doomsday/sdk/libcore/src/data/pathtreenode.cpp +++ b/doomsday/sdk/libcore/src/data/pathtreenode.cpp @@ -14,7 +14,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #include "de/PathTree" @@ -50,7 +50,7 @@ DENG2_PIMPL_NOREF(PathTree::Node) } }; -PathTree::Node::Node(PathTree::NodeArgs const &args) +PathTree::Node::Node(PathTree::NodeArgs const &args) : d(nullptr) { d.reset(new Instance(args.tree, args.type == PathTree::Leaf, args.segmentId, args.parent)); diff --git a/doomsday/sdk/libgui/src/graphics/modelbank.cpp b/doomsday/sdk/libgui/src/graphics/modelbank.cpp index 5653b4e331..228bbc3b57 100644 --- a/doomsday/sdk/libgui/src/graphics/modelbank.cpp +++ b/doomsday/sdk/libgui/src/graphics/modelbank.cpp @@ -46,7 +46,9 @@ DENG2_PIMPL(ModelBank) Instance(Public *i) : Base(i) {} }; -ModelBank::ModelBank() : Bank("ModelBank", BackgroundThread) +ModelBank::ModelBank() + : Bank("ModelBank", BackgroundThread) + , d(new Instance(this)) {} void ModelBank::add(DotPath const &id, String const &sourcePath)