Skip to content

Commit

Permalink
Refactor: PrivateAutoPtr must be initialized with a value
Browse files Browse the repository at this point in the history
This avoid the pitfall of forgetting to instantiate the private
implementation.
  • Loading branch information
skyjake committed Sep 16, 2015
1 parent a75624a commit 3894e68
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions doomsday/sdk/libcore/include/de/libcore.h
Expand Up @@ -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</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBCORE_H
Expand Down Expand Up @@ -118,7 +118,7 @@
* must use the platform-specific functions.
*/
#if defined(UNIX) && defined(DENG2_C_API_ONLY)
# include <strings.h> // strcasecmp etc.
# include <strings.h> // strcasecmp etc.
#endif

/*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libcore/src/data/info.cpp
Expand Up @@ -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<Instance> 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<Instance> 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<Instance> inst(new Instance(this)); // parsing may throw exception
inst->finder = &finder;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/data/pathtreenode.cpp
Expand Up @@ -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</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/PathTree"
Expand Down Expand Up @@ -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));

Expand Down
4 changes: 3 additions & 1 deletion doomsday/sdk/libgui/src/graphics/modelbank.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 3894e68

Please sign in to comment.