From acdfcad30de8dcf59515b688a1310ba2c1ca6947 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Thu, 16 Oct 2014 05:49:48 -0400 Subject: base: Use shared_ptr for stat Node This patch transitions the stat Node and its derived classes from the ad-hoc RefCountingPtr to the c++11 shared_ptr. There are no changes in behaviour, and the code modifications are mainly replacing "new" with "make_shared". --- src/base/statistics.hh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/base/statistics.hh') diff --git a/src/base/statistics.hh b/src/base/statistics.hh index f4b12e847..658652f05 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,6 @@ #include "base/cast.hh" #include "base/cprintf.hh" #include "base/intmath.hh" -#include "base/refcnt.hh" #include "base/str.hh" #include "base/types.hh" @@ -2050,7 +2050,7 @@ class DistProxy * Base class for formula statistic node. These nodes are used to build a tree * that represents the formula. */ -class Node : public RefCounted +class Node { public: /** @@ -2075,8 +2075,8 @@ class Node : public RefCounted virtual std::string str() const = 0; }; -/** Reference counting pointer to a function Node. */ -typedef RefCountingPtr NodePtr; +/** Shared pointer to a function Node. */ +typedef std::shared_ptr NodePtr; class ScalarStatNode : public Node { @@ -2989,7 +2989,9 @@ class Temp * Copy the given pointer to this class. * @param n A pointer to a Node object to copy. */ - Temp(NodePtr n) : node(n) { } + Temp(const NodePtr &n) : node(n) { } + + Temp(NodePtr &&n) : node(std::move(n)) { } /** * Return the node pointer. @@ -3155,51 +3157,51 @@ class Temp inline Temp operator+(Temp l, Temp r) { - return NodePtr(new BinaryNode >(l, r)); + return Temp(std::make_shared > >(l, r)); } inline Temp operator-(Temp l, Temp r) { - return NodePtr(new BinaryNode >(l, r)); + return Temp(std::make_shared > >(l, r)); } inline Temp operator*(Temp l, Temp r) { - return NodePtr(new BinaryNode >(l, r)); + return Temp(std::make_shared > >(l, r)); } inline Temp operator/(Temp l, Temp r) { - return NodePtr(new BinaryNode >(l, r)); + return Temp(std::make_shared > >(l, r)); } inline Temp operator-(Temp l) { - return NodePtr(new UnaryNode >(l)); + return Temp(std::make_shared > >(l)); } template inline Temp constant(T val) { - return NodePtr(new ConstNode(val)); + return Temp(std::make_shared >(val)); } template inline Temp constantVector(T val) { - return NodePtr(new ConstVectorNode(val)); + return Temp(std::make_shared >(val)); } inline Temp sum(Temp val) { - return NodePtr(new SumNode >(val)); + return Temp(std::make_shared > >(val)); } /** Dump all statistics data to the registered outputs */ -- cgit v1.2.3