diff --git a/ide/msvc2017/HourglassII/HourglassII/HourglassII.vcxproj b/ide/msvc2017/HourglassII/HourglassII/HourglassII.vcxproj
index f441fd40..1fadf3ad 100644
--- a/ide/msvc2017/HourglassII/HourglassII/HourglassII.vcxproj
+++ b/ide/msvc2017/HourglassII/HourglassII/HourglassII.vcxproj
@@ -254,6 +254,9 @@
CppHeader
+
+ CppHeader
+
CppHeader
diff --git a/ide/msvc2017/HourglassII/HourglassIIUnity/HourglassIIUnity.vcxproj b/ide/msvc2017/HourglassII/HourglassIIUnity/HourglassIIUnity.vcxproj
index fc8870af..8397516c 100644
--- a/ide/msvc2017/HourglassII/HourglassIIUnity/HourglassIIUnity.vcxproj
+++ b/ide/msvc2017/HourglassII/HourglassIIUnity/HourglassIIUnity.vcxproj
@@ -72,6 +72,7 @@
stdcpp17
false
true
+ /bigobj
true
@@ -315,6 +316,9 @@
CppHeader
+
+ CppHeader
+
CppHeader
diff --git a/src/BoxGlitzAdder.h b/src/BoxGlitzAdder.h
index 5af332c1..68ee4f52 100644
--- a/src/BoxGlitzAdder.h
+++ b/src/BoxGlitzAdder.h
@@ -8,6 +8,7 @@
#include "ImageGlitz.h"
#include "multi_thread_allocator.h"
#include "RectangleGlitz.h"
+#include "mt/std/memory"
namespace hg {
class BoxGlitzAdder final {
public:
@@ -26,14 +27,12 @@ class BoxGlitzAdder final {
int size,
TimeDirection timeDirection) const
{
- Glitz sameDirectionGlitz(
- new (multi_thread_tag{}) ImageGlitz(
+ Glitz sameDirectionGlitz(mt::std::make_unique(
500, mt::std::string("global.box"),
position.x, position.y,
size, size));
- Glitz oppositeDirectionGlitz(
- new (multi_thread_tag{}) ImageGlitz(
+ Glitz oppositeDirectionGlitz(mt::std::make_unique(
500, mt::std::string("global.box_r"),
position.x, position.y,
size, size));
@@ -53,23 +52,23 @@ class BoxGlitzAdder final {
{
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
+ mt::std::make_unique(
Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
- 1500,
- x,
- y,
- size,
- size,
- timeDirection == TimeDirection::FORWARDS ? 0xFF000000u : 0x00FFFF00u)),
+ mt::std::make_unique(
+ 1500,
+ x,
+ y,
+ size,
+ size,
+ timeDirection == TimeDirection::FORWARDS ? 0xFF000000u : 0x00FFFF00u)),
Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
- 1500,
- x,
- y,
- size,
- size,
- timeDirection == TimeDirection::REVERSE ? 0xFF000000u : 0x00FFFF00u)),
+ mt::std::make_unique(
+ 1500,
+ x,
+ y,
+ size,
+ size,
+ timeDirection == TimeDirection::REVERSE ? 0xFF000000u : 0x00FFFF00u)),
60,
timeDirection)));
}
diff --git a/src/DirectLuaTriggerSystem.cpp b/src/DirectLuaTriggerSystem.cpp
index fa421d9d..23a852ad 100644
--- a/src/DirectLuaTriggerSystem.cpp
+++ b/src/DirectLuaTriggerSystem.cpp
@@ -284,7 +284,7 @@ GlitzPersister toGlitzPersister(lua_State *L) {
}
TimeDirection timeDirection = readField(L, "timeDirection");
return GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
+ mt::std::make_unique(
std::move(forwardsGlitz), std::move(reverseGlitz), lifetime, timeDirection));
}
else if (type == "audio") {
@@ -292,7 +292,7 @@ GlitzPersister toGlitzPersister(lua_State *L) {
int duration = readField(L, "duration");
TimeDirection timeDirection = readField(L, "timeDirection");
return GlitzPersister(
- new (multi_thread_tag{}) AudioGlitzPersister(std::move(key), duration, timeDirection));
+ mt::std::make_unique(std::move(key), duration, timeDirection));
}
std::stringstream ss;
ss << "Unknown Glitz Persister Type: " << type;
diff --git a/src/Glitz.h b/src/Glitz.h
index 00a5a5cb..8a134c6e 100644
--- a/src/Glitz.h
+++ b/src/Glitz.h
@@ -6,16 +6,18 @@
#include "clone_ptr.h"
#include "memory_source_clone.h"
#include "multi_thread_memory_source.h"
+#include "multi_thread_allocator.h"
+#include "multi_thread_deleter.h"
#include "GlitzImplementation.h"
+#include "mt/std/memory"
#include
namespace hg {
class Glitz final : boost::totally_ordered {
public:
- //TODO: Don't use raw pointer here?
- explicit Glitz(GlitzImplementation *impl)
- : impl(impl)
+ explicit Glitz(mt::std::unique_ptr impl)
+ : impl(impl.release())
{
- assert(impl);
+ assert(this->impl);
}
void display(LayeredCanvas &canvas) const {
diff --git a/src/GlitzPersister.cpp b/src/GlitzPersister.cpp
index 64e04b89..ff547d5d 100644
--- a/src/GlitzPersister.cpp
+++ b/src/GlitzPersister.cpp
@@ -1,5 +1,6 @@
#include "GlitzPersister.h"
#include "Frame.h"
+#include "mt/std/memory"
#include
#include
#include
@@ -16,7 +17,7 @@ ObjectAndTime StaticGlitzPersister::runStep(Frame *fram
{
return ObjectAndTime(
GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
+ mt::std::make_unique(
forwardsGlitz, reverseGlitz,
framesLeft - 1, timeDirection)),
framesLeft ? nextFrame(frame, timeDirection) : nullptr);
@@ -43,6 +44,7 @@ AudioGlitzPersister::AudioGlitzPersister(
{}
AudioGlitzPersister::AudioGlitzPersister(
+ AudioGlitzPersister_access,
mt::std::string key,
unsigned duration,
unsigned currentFrame,
@@ -55,15 +57,13 @@ AudioGlitzPersister::AudioGlitzPersister(
Glitz AudioGlitzPersister::getForwardsGlitz() const {
mt::std::string suffix = timeDirection == TimeDirection::FORWARDS ? "" : "_r";
- return Glitz(
- new (multi_thread_tag{}) AudioGlitz(
+ return Glitz(mt::std::make_unique(
key+suffix,
timeDirection == TimeDirection::FORWARDS ? currentFrame : duration-currentFrame));
}
Glitz AudioGlitzPersister::getReverseGlitz() const {
mt::std::string suffix = timeDirection == TimeDirection::REVERSE ? "" : "_r";
- return Glitz(
- new (multi_thread_tag{}) AudioGlitz(
+ return Glitz(mt::std::make_unique(
key+suffix,
timeDirection == TimeDirection::REVERSE ? currentFrame : duration-currentFrame));
}
@@ -72,7 +72,8 @@ ObjectAndTime AudioGlitzPersister::runStep(Frame *frame
{
return ObjectAndTime(
GlitzPersister(
- new (multi_thread_tag{}) AudioGlitzPersister(
+ mt::std::make_unique(
+ AudioGlitzPersister_access{},
key,
duration,
currentFrame + 1,
diff --git a/src/GlitzPersister.h b/src/GlitzPersister.h
index f7d78c97..ff4f158c 100644
--- a/src/GlitzPersister.h
+++ b/src/GlitzPersister.h
@@ -3,6 +3,7 @@
#include "TimeDirection.h"
#include
#include "mt/std/string"
+#include "mt/std/memory"
#include
#include "ObjectAndTime.h"
#include "Glitz.h"
@@ -29,10 +30,10 @@ struct GlitzPersisterImpl : private boost::totally_ordered
class GlitzPersister final : boost::totally_ordered
{
public:
- GlitzPersister(GlitzPersisterImpl *impl) :
- impl(impl)
+ explicit GlitzPersister(mt::std::unique_ptr impl) :
+ impl(impl.release())
{
- assert(impl);
+ assert(this->impl);
}
ObjectAndTime runStep(Frame *frame) const {
@@ -63,7 +64,7 @@ class GlitzPersister final : boost::totally_ordered
class GlitzPersisterConstPtr final : boost::totally_ordered
{
public:
- GlitzPersisterConstPtr(GlitzPersister const &glitzPersister) : glitzPersister(&glitzPersister) {}
+ explicit GlitzPersisterConstPtr(GlitzPersister const &glitzPersister) : glitzPersister(&glitzPersister) {}
typedef GlitzPersister base_type;
GlitzPersister const &get() const { return *glitzPersister; }
@@ -85,7 +86,7 @@ struct ConstPtr_of {
class StaticGlitzPersister final : public GlitzPersisterImpl
{
public:
- StaticGlitzPersister(
+ explicit StaticGlitzPersister(
Glitz const &forwardsGlitz, Glitz const &reverseGlitz,
unsigned lifetime, TimeDirection timeDirection);
ObjectAndTime runStep(Frame *frame) const override;
@@ -119,8 +120,13 @@ class StaticGlitzPersister final : public GlitzPersisterImpl
class AudioGlitzPersister final : public GlitzPersisterImpl
{
+ struct AudioGlitzPersister_access final{
+ friend class AudioGlitzPersister;
+ private:
+ AudioGlitzPersister_access(){}
+ };
public:
- AudioGlitzPersister(
+ explicit AudioGlitzPersister(
mt::std::string key,
unsigned duration,
TimeDirection timeDirection);
@@ -141,12 +147,16 @@ class AudioGlitzPersister final : public GlitzPersisterImpl
}
bool operator==(GlitzPersisterImpl const &o) const override;
bool operator<(GlitzPersisterImpl const &o) const override;
-private:
+
+ //Mostly private. Only accessible via AudioGlitzPersister_access key, which can only be created by
+ //AudioGlitzPersister.
AudioGlitzPersister(
+ AudioGlitzPersister_access,
mt::std::string key,
unsigned duration,
unsigned currentFrame,
TimeDirection timeDirection);
+private:
mt::std::string key;
unsigned duration;
unsigned currentFrame;
diff --git a/src/GuyGlitzAdder.h b/src/GuyGlitzAdder.h
index e81ba3ed..3557d894 100644
--- a/src/GuyGlitzAdder.h
+++ b/src/GuyGlitzAdder.h
@@ -3,6 +3,7 @@
#include "Glitz.h"
#include "mt/std/vector"
#include "mp/std/vector"
+#include "mt/std/memory"
#include "vector2.h"
#include "multi_thread_allocator.h"
#include "RectangleGlitz.h"
@@ -16,8 +17,7 @@ inline void addCurrentGuyArrow(
int tipy = top - 400;
int width = 200;
glitzList.push_back(
- Glitz(
- new (multi_thread_tag{}) LineGlitz(
+ Glitz(mt::std::make_unique(
650,
tipx,
top - size.y/2 - 400,
@@ -27,8 +27,7 @@ inline void addCurrentGuyArrow(
0xFF000000u)));
glitzList.push_back(
- Glitz(
- new (multi_thread_tag{}) LineGlitz(
+ Glitz(mt::std::make_unique(
650,
tipx+halfwidth/2,
top - size.y/4 - 400,
@@ -38,8 +37,7 @@ inline void addCurrentGuyArrow(
0xFF000000u)));
glitzList.push_back(
- Glitz(
- new (multi_thread_tag{}) LineGlitz(
+ Glitz(mt::std::make_unique(
650,
tipx-halfwidth/2,
top - size.y/4 - 400,
@@ -82,25 +80,24 @@ class GuyGlitzAdder final {
timeDirection == TimeDirection::FORWARDS ?
PNC(position.x, position.y, 0x96960000u) :
PNC(position.x, position.y, 0x00009600u);
-
+
int const left(pnc.x);
int const top(pnc.y);
int const halfwidth(size.x/2);
//int const halfheight(size.y/2);
int const hmid(pnc.x+halfwidth);
-
- forwardsGlitz->push_back(Glitz(new (multi_thread_tag{}) ImageGlitz(
+
+ forwardsGlitz->push_back(Glitz(mt::std::make_unique(
600,
facing == FacingDirection::RIGHT ?
(timeDirection == TimeDirection::FORWARDS ? "global.rhino_right_stop" : "global.rhino_right_stop_r") :
(timeDirection == TimeDirection::FORWARDS ? "global.rhino_left_stop" : "global.rhino_left_stop_r"),
left, top, size.x, size.y)));
-
+
if (boxCarrying)
{
forwardsGlitz->push_back(
- Glitz(
- new (multi_thread_tag{}) ImageGlitz(
+ Glitz(mt::std::make_unique(
600,
boxCarryDirection == TimeDirection::FORWARDS ?
"global.box" : "global.box_r",
@@ -129,7 +126,7 @@ class GuyGlitzAdder final {
//int const halfheight(size.y/2);
int const hmid(pnc.x+halfwidth);
- reverseGlitz->push_back(Glitz(new (multi_thread_tag{}) ImageGlitz(
+ reverseGlitz->push_back(Glitz(mt::std::make_unique(
600,
facing == FacingDirection::RIGHT ?
(timeDirection == TimeDirection::REVERSE ? "global.rhino_right_stop" : "global.rhino_right_stop_r") :
@@ -138,8 +135,7 @@ class GuyGlitzAdder final {
if (boxCarrying)
{
reverseGlitz->push_back(
- Glitz(
- new (multi_thread_tag{}) ImageGlitz(
+ Glitz(mt::std::make_unique(
600,
boxCarryDirection == TimeDirection::REVERSE ?
"global.box" : "global.box_r",
@@ -154,7 +150,7 @@ class GuyGlitzAdder final {
if (justPickedUpBox) {
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) AudioGlitzPersister(
+ mt::std::make_unique(
"global.box_pickup",
16,
timeDirection)));
@@ -173,9 +169,8 @@ class GuyGlitzAdder final {
int width = 100;
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
- Glitz(
- new (multi_thread_tag{}) LineGlitz(
+ mt::std::make_unique(
+ Glitz(mt::std::make_unique(
1500,
x1,
y1,
@@ -183,8 +178,7 @@ class GuyGlitzAdder final {
y2,
width,
timeDirection == TimeDirection::FORWARDS ? 0xFF000000u : 0x00FFFF00u)),
- Glitz(
- new (multi_thread_tag{}) LineGlitz(
+ Glitz(mt::std::make_unique(
1500,
x1,
y1,
@@ -196,17 +190,15 @@ class GuyGlitzAdder final {
timeDirection)));
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
- Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
+ mt::std::make_unique(
+ Glitz(mt::std::make_unique(
1500,
xAim-200,
yAim-200,
400,
400,
timeDirection == TimeDirection::FORWARDS ? 0xFF000000u : 0x00FFFF00u)),
- Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
+ Glitz(mt::std::make_unique(
1500,
xAim-200,
yAim-200,
@@ -218,7 +210,7 @@ class GuyGlitzAdder final {
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) AudioGlitzPersister(
+ mt::std::make_unique(
"global.laser_shoot",
24,
timeDirection)));
@@ -233,9 +225,9 @@ class GuyGlitzAdder final {
{
persistentGlitz->push_back(
GlitzPersister(
- new (multi_thread_tag{}) StaticGlitzPersister(
+ mt::std::make_unique(
Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
+ mt::std::make_unique(
1500,
x,
y,
@@ -243,7 +235,7 @@ class GuyGlitzAdder final {
height,
timeDirection == TimeDirection::FORWARDS ? 0xFF000000u : 0x00FFFF00u)),
Glitz(
- new (multi_thread_tag{}) RectangleGlitz(
+ mt::std::make_unique(
1500,
x,
y,
diff --git a/src/LuaUtilities.cpp b/src/LuaUtilities.cpp
index bd12f264..a463336b 100644
--- a/src/LuaUtilities.cpp
+++ b/src/LuaUtilities.cpp
@@ -5,6 +5,7 @@
#include "lua/lualib.h"
#include "lua/lauxlib.h"
#include "multi_vector.h"
+#include "mt/std/memory"
#include "ImageGlitz.h"
#include "TextGlitz.h"
@@ -625,7 +626,7 @@ Glitz to(lua_State *L, int index) {
int const width(readField(L, "width", index));
int const height(readField(L, "height", index));
unsigned const colour(readColourField(L, "colour"));
- return Glitz(new (multi_thread_tag{}) RectangleGlitz(layer, x, y, width, height, colour));
+ return Glitz(mt::std::make_unique(layer, x, y, width, height, colour));
}
else if (strcmp(type, "text") == 0) {
lua_pop(L, 1);
@@ -635,7 +636,7 @@ Glitz to(lua_State *L, int index) {
int const y(readField(L, "y", index));
int const size(readField(L, "size", index));
unsigned const colour(readColourField(L, "colour"));
- return Glitz(new (multi_thread_tag{}) TextGlitz(layer, std::move(text), x, y, size, colour));
+ return Glitz(mt::std::make_unique(layer, std::move(text), x, y, size, colour));
}
else if (strcmp(type, "image") == 0) {
lua_pop(L, 1);
@@ -646,7 +647,7 @@ Glitz to(lua_State *L, int index) {
int const width(readField(L, "width"));
int const height(readField(L, "height"));
- return Glitz(new (multi_thread_tag{}) ImageGlitz(layer, std::move(key), x, y, width, height));
+ return Glitz(mt::std::make_unique(layer, std::move(key), x, y, width, height));
}
std::stringstream ss;
ss << "Unknown Glitz Type: " << type;
diff --git a/src/SimpleConfiguredTriggerSystem.cpp b/src/SimpleConfiguredTriggerSystem.cpp
index ae77266b..78783ed8 100644
--- a/src/SimpleConfiguredTriggerSystem.cpp
+++ b/src/SimpleConfiguredTriggerSystem.cpp
@@ -9,6 +9,7 @@
#include "LuaError.h"
#include "LuaStackManager.h"
#include "LuaSandbox.h"
+#include "mt/std/memory"
#include "lua\lauxlib.h"
#include
@@ -25,13 +26,13 @@ namespace hg {
unsigned const forwardsColour,
unsigned const reverseColour)
{
- Glitz sameDirectionGlitz(new (multi_thread_tag{}) RectangleGlitz(
+ Glitz sameDirectionGlitz(mt::std::make_unique(
layer,
x - xspeed, y - yspeed,
width, height,
forwardsColour
));
- Glitz oppositeDirectionGlitz(new (multi_thread_tag{}) RectangleGlitz(
+ Glitz oppositeDirectionGlitz(mt::std::make_unique(
layer,
x - xspeed, y - yspeed,
width, height,
@@ -326,7 +327,7 @@ namespace hg {
int size,
unsigned colour
*/
- auto textGlitz = Glitz(new (multi_thread_tag{}) TextGlitz(
+ auto textGlitz = Glitz(mt::std::make_unique(
440,
text,
portal.getX()+portal.getWidth()/2-1600,
@@ -794,7 +795,7 @@ namespace hg {
int const triggerID(lua_index_to_C_index(readField(L, "triggerID")));
assert(triggerID < triggerOffsetsAndDefaults.size());
assert(0 < triggerOffsetsAndDefaults[triggerID].second.size());
- return new (multi_thread_tag{}) ProtoPickupImpl(
+ return ProtoMutator(mt::std::make_unique(
timeDirection,
attachment,
width,
@@ -802,7 +803,7 @@ namespace hg {
pickupType,
pickupNumber,
triggerID
- );
+ ));
}
ProtoMutator toProtoSpikes(
@@ -812,12 +813,12 @@ namespace hg {
Attachment const attachment(readField(L, "attachment"));
int const width(readField(L, "width"));
int const height(readField(L, "height"));
- return new (multi_thread_tag{}) ProtoSpikesImpl(
+ return ProtoMutator(mt::std::make_unique(
timeDirection,
attachment,
width,
height
- );
+ ));
}
ProtoMutator toProtoMutator(
@@ -946,7 +947,7 @@ namespace hg {
}
lua_pop(L, 1);
- return new (multi_thread_tag{}) ProtoMomentarySwitchImpl(
+ return ProtoButton(mt::std::make_unique(
timeDirection,
attachment,
width,
@@ -954,7 +955,7 @@ namespace hg {
triggerID,
stateTriggerID,
std::move(extraTriggerIDs)
- );
+ ));
}
ProtoButton toProtoStickySwitch(
@@ -995,7 +996,7 @@ namespace hg {
}
lua_pop(L, 1);
- return new (multi_thread_tag{}) ProtoStickySwitchImpl(
+ return ProtoButton(mt::std::make_unique(
timeDirection,
attachment,
width,
@@ -1003,7 +1004,7 @@ namespace hg {
triggerID,
stateTriggerID,
std::move(extraTriggerIDs)
- );
+ ));
}
ProtoButton toProtoButton(
@@ -1154,7 +1155,7 @@ namespace hg {
assert(proto->pickupType != Ability::NO_ABILITY);
if (active) {
forwardsGlitz.push_back(
- Glitz(new (multi_thread_tag{}) ImageGlitz(
+ Glitz(mt::std::make_unique(
430,
pickupGlitzNameMap.find(proto->pickupType)->second,//TODO: Avoid undefined behaviour on unfound ability
x_, y_,
@@ -1162,7 +1163,7 @@ namespace hg {
))
);
reverseGlitz.push_back(
- Glitz(new (multi_thread_tag{}) ImageGlitz(
+ Glitz(mt::std::make_unique(
430,
pickupGlitzNameMap.find(proto->pickupType)->second,//TODO: Avoid undefined behaviour on unfound ability
x_, y_,
@@ -1173,7 +1174,7 @@ namespace hg {
if (justTaken) {
//TODO: Avoid possible memory leak here!
persistentGlitz.push_back(
- GlitzPersister(new (multi_thread_tag{}) AudioGlitzPersister(
+ GlitzPersister(mt::std::make_unique(
"global.pickup_pickup",
9,
proto->timeDirection
@@ -1507,12 +1508,12 @@ namespace hg {
if (justPressed) {
persistentGlitz.push_back(
- GlitzPersister(new (multi_thread_tag{}) AudioGlitzPersister("global.switch_push_down", 10, proto->timeDirection))
+ GlitzPersister(mt::std::make_unique("global.switch_push_down", 10, proto->timeDirection))
);
}
if (justReleased) {
persistentGlitz.push_back(
- GlitzPersister(new (multi_thread_tag{}) AudioGlitzPersister("global.switch_push_up", 10, proto->timeDirection))
+ GlitzPersister(mt::std::make_unique("global.switch_push_up", 10, proto->timeDirection))
);
}
}
@@ -1563,7 +1564,7 @@ namespace hg {
if (justPressed) {
persistentGlitz.push_back(
- GlitzPersister(new (multi_thread_tag{}) AudioGlitzPersister("global.switch_push_down", 10, proto->timeDirection))
+ GlitzPersister(mt::std::make_unique("global.switch_push_down", 10, proto->timeDirection))
);
}
}
diff --git a/src/SimpleConfiguredTriggerSystem.h b/src/SimpleConfiguredTriggerSystem.h
index 57422b5c..54264f74 100644
--- a/src/SimpleConfiguredTriggerSystem.h
+++ b/src/SimpleConfiguredTriggerSystem.h
@@ -437,10 +437,12 @@ namespace hg {
return comparison_tuple_type(pimpl_->order_ranking(), *pimpl_);
}
public:
- template
- ProtoButton(ProtoButtonImpl *impl)
- : pimpl_(impl)
- {}
+
+ explicit ProtoButton(mt::std::unique_ptr impl)
+ : pimpl_(impl.release())
+ {
+ assert(pimpl_);
+ }
ButtonFrameState getFrameState(hg::memory_pool & pool) const {
assert(pimpl_);
return pimpl_->getFrameState(pool);
@@ -734,10 +736,11 @@ namespace hg {
return comparison_tuple_type(pimpl_->order_ranking(), *pimpl_);
}
public:
- template
- ProtoMutator(ProtoMutatorImpl *impl)
- : pimpl_(impl)
- {}
+ explicit ProtoMutator(mt::std::unique_ptr impl)
+ : pimpl_(impl.release())
+ {
+ assert(pimpl_);
+ }
MutatorFrameState getFrameState(hg::memory_pool &pool) const {
assert(pimpl_);
diff --git a/src/move_function.h b/src/move_function.h
index 081ff48f..b3c7cac3 100644
--- a/src/move_function.h
+++ b/src/move_function.h
@@ -1,8 +1,7 @@
#ifndef HG_MOVE_FUNCTION_H
#define HG_MOVE_FUNCTION_H
#include
-#include
-#include "multi_thread_deleter.h"
+#include "mt/std/memory"
#include
#include
#include
@@ -71,14 +70,13 @@ class move_function final
move_function &operator=(move_function &&o) noexcept = default;
template>, move_function>>>
move_function(F &&f) :
- f(new (multi_thread_tag{}) function::detail::function_obj(std::forward(f)))
+ f(mt::std::make_unique>(std::forward(f)))
{
}
template
move_function &operator=(F &&f)
{
- this->f = function_obj_ptr_t(
- new (multi_thread_tag{}) function::detail::function_obj(std::forward(f)));
+ this->f = mt::std::make_unique>(std::forward(f));
return *this;
}
R operator()(ArgTypes &&...args) const {
@@ -88,10 +86,7 @@ class move_function final
explicit operator bool() const noexcept { return f.get(); }
private:
- typedef std::unique_ptr<
- function::detail::function_base,
- multi_thread_deleter>> function_obj_ptr_t;
- function_obj_ptr_t f;
+ mt::std::unique_ptr> f;
};
} //namespace hg
diff --git a/src/mt/std/memory b/src/mt/std/memory
new file mode 100644
index 00000000..2ba8ba4b
--- /dev/null
+++ b/src/mt/std/memory
@@ -0,0 +1,21 @@
+#ifndef HG_MT_STD_MEMORY
+#define HG_MT_STD_MEMORY
+#include "../../multi_thread_deleter.h"
+#include "../../multi_thread_allocator.h"
+#include
+namespace hg {
+namespace mt {
+namespace std{
+
+template
+using unique_ptr = ::std::unique_ptr>;
+
+template
+unique_ptr make_unique(Args &&...args) {
+ return unique_ptr(new (multi_thread_tag{}) T(::std::forward(args)...));
+}
+
+}
+}
+}
+#endif //HG_MT_STD_MEMORY
diff --git a/src/multi_thread_allocator.h b/src/multi_thread_allocator.h
index 88ecf601..a785202b 100644
--- a/src/multi_thread_allocator.h
+++ b/src/multi_thread_allocator.h
@@ -71,11 +71,11 @@ namespace hg {
// new T(args...),
//except that it performs its allocation
//using `multi_thread_operator_new`.
-inline void* operator new(std::size_t count, hg::multi_thread_tag) {
+inline void* operator new(std::size_t const count, hg::multi_thread_tag) {
return hg::multi_thread_operator_new(count);
}
-inline void operator delete(void *p, hg::multi_thread_tag) noexcept {
+inline void operator delete(void * const p, hg::multi_thread_tag) noexcept {
hg::multi_thread_operator_delete(p);
}
diff --git a/src/multi_thread_deleter.h b/src/multi_thread_deleter.h
index b2f42e04..52e01e14 100644
--- a/src/multi_thread_deleter.h
+++ b/src/multi_thread_deleter.h
@@ -2,9 +2,14 @@
#define HG_MULTI_THREAD_DELETER_H
#include "multi_thread_allocator.h"
namespace hg {
- template
- struct multi_thread_deleter final {
- void operator()(T *ptr) const { multi_thread_delete(ptr); }
+ template
+ struct multi_thread_deleter {
+ constexpr multi_thread_deleter() noexcept = default;
+ template >>
+ multi_thread_deleter(multi_thread_deleter const &) noexcept {}
+ void operator()(T * const ptr) const {
+ multi_thread_delete(ptr);
+ }
};
template
struct multi_thread_deleter;