/*
Copyright 2016, 2017 Michele "King_DuckZ" Santullo
This file is part of MyCurry.
MyCurry is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MyCurry is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MyCurry. If not, see .
*/
#pragma once
#include "kakoune/safe_ptr.hh"
#include
namespace curry {
template
class SafeStackObject {
public:
typedef Kakoune::SafePtr safe_ptr;
SafeStackObject();
SafeStackObject (SafeStackObject&& parOther);
SafeStackObject (const SafeStackObject& parOther) = delete;
template explicit SafeStackObject (Args&&... parArgs);
~SafeStackObject() noexcept = default;
SafeStackObject& operator= (SafeStackObject&& parOther) = delete;
SafeStackObject& operator= (const SafeStackObject& parOther) = delete;
operator Kakoune::SafePtr&();
template
operator Kakoune::SafePtr();
T& operator*();
safe_ptr& operator->();
private:
T m_obj;
safe_ptr m_obj_ptr;
};
template
SafeStackObject::SafeStackObject() :
m_obj(),
m_obj_ptr(&m_obj)
{
}
template
SafeStackObject::SafeStackObject (SafeStackObject&& parOther) :
m_obj(std::move(parOther.m_obj)),
m_obj_ptr(&m_obj)
{
}
template
template
SafeStackObject::SafeStackObject (Args&&... parArgs) :
m_obj(std::forward(parArgs)...),
m_obj_ptr(&m_obj)
{
}
//template
//SafeStackObject& SafeStackObject::operator= (SafeStackObject&& parOther) {
// m_obj = std::move(parOther.m_obj);
// m_obj_ptr = std::move(parOther.m_obj_ptr);
// m_ob
//}
//template
//SafeStackObject& SafeStackObject::operator= (const SafeStackObject& parOther) {
//}
template
SafeStackObject::operator Kakoune::SafePtr&() {
return m_obj_ptr;
}
template
template
SafeStackObject::operator Kakoune::SafePtr() {
return Kakoune::SafePtr(&m_obj);
}
template
T& SafeStackObject::operator*() {
return *m_obj_ptr;
}
template
auto SafeStackObject::operator->() -> safe_ptr& {
return m_obj_ptr;
}
} //namespace curry