diff --git a/toonz/sources/include/tcg/hpp/image_ops.hpp b/toonz/sources/include/tcg/hpp/image_ops.hpp index 38ae9c6..ef95bc2 100644 --- a/toonz/sources/include/tcg/hpp/image_ops.hpp +++ b/toonz/sources/include/tcg/hpp/image_ops.hpp @@ -6,7 +6,6 @@ // tcg includes #include "../image_ops.h" #include "../pixel.h" -#include "../unique_ptr.h" // STD includes #include <assert.h> @@ -177,7 +176,7 @@ void blurRows(const ImgIn &imgIn, ImgOut &imgOut, int radius, Scalar) { outWrap = image_traits<ImgOut>::wrap(imgOut); // Allocate an intermediate line of pixels to store sum values - tcg::unique_ptr<PixSum[]> sums(new PixSum[inLx]); + std::unique_ptr<PixSum[]> sums(new PixSum[inLx]); // Filter rows for (int y = 0; y != inLy; ++y) { @@ -210,8 +209,8 @@ void blurRows(const ImgIn &imgIn, ImgOut &imgOut, int radius, outWrap = image_traits<ImgOut>::wrap(imgOut); // Allocate an intermediate line of pixels to store sum values - tcg::unique_ptr<PixSum[]> sums(new PixSum[inLx]); - tcg::unique_ptr<int[]> counts(new int[inLx]); + std::unique_ptr<PixSum[]> sums(new PixSum[inLx]); + std::unique_ptr<int[]> counts(new int[inLx]); // Filter rows for (int y = 0; y != inLy; ++y) { @@ -244,7 +243,7 @@ void blurCols(const ImgIn &imgIn, ImgOut &imgOut, int radius, Scalar) { outWrap = image_traits<ImgOut>::wrap(imgOut); // Allocate an intermediate line of pixels to store sum values - tcg::unique_ptr<PixSum[]> sums(new PixSum[inLy]); + std::unique_ptr<PixSum[]> sums(new PixSum[inLy]); // Filter columns for (int x = 0; x != inLx; ++x) { @@ -278,8 +277,8 @@ void blurCols(const ImgIn &imgIn, ImgOut &imgOut, int radius, outWrap = image_traits<ImgOut>::wrap(imgOut); // Allocate an intermediate line of pixels to store sum values - tcg::unique_ptr<PixSum[]> sums(new PixSum[inLy]); - tcg::unique_ptr<int[]> counts(new int[inLy]); + std::unique_ptr<PixSum[]> sums(new PixSum[inLy]); + std::unique_ptr<int[]> counts(new int[inLy]); // Filter columns for (int x = 0; x != inLx; ++x) { diff --git a/toonz/sources/include/tcg/tcg_unique_ptr.h b/toonz/sources/include/tcg/tcg_unique_ptr.h deleted file mode 100644 index 1abc7c1..0000000 --- a/toonz/sources/include/tcg/tcg_unique_ptr.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "unique_ptr.h" diff --git a/toonz/sources/include/tcg/unique_ptr.h b/toonz/sources/include/tcg/unique_ptr.h deleted file mode 100644 index 6b5fb79..0000000 --- a/toonz/sources/include/tcg/unique_ptr.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#ifndef TCG_UNIQUE_PTR_H -#define TCG_UNIQUE_PTR_H - -// tcg includes -#include "traits.h" -#include "base.h" -#include "deleter_types.h" - -// STD includes -#include "assert.h" -#include <utility> - -namespace tcg { - -//********************************************************************************** -// unique_ptr definition -//********************************************************************************** - -/*! - \brief The unique_ptr class is a C++03 compatibility class that implements - a \a noncopyable smart pointer, similarly to \p boost::scoped_ptr, - but accepting a custom deleter type as template parameter. - - \details \par Properties - This class provides the following features: -<UL> - <LI>It's noncopyable, like \p boost::scoped_ptr.</LI> - <LI>Unlike \p boost::scoped_ptr, it provides the release() -method.</LI> - <LI>Arrays are valid template types - so <TT>tcg::unique_ptr<int -[]></TT> - is accepted and works as expected.</LI> - <LI>Like \p std::unique_ptr, it accepts custom \a inheritable -deallocators.</LI> -</UL> - \par Incomplete types - Like \p boost::scoped_ptr, incomplete types are accepted as template - parameter, \a provided their definition is completed by the time the -destructor - is invoked. In particular, pointers to incomplete types \b must be -stored in - classes whose destructor is defined in an implementation file - and -<I>remember - that compiler-generated destructors are always implicitly -inlined</I>. - - \par Type erasure - Unlike shared_ptr, this class does not employ <I>type erasure</I> - on the deleter object - which is an explicit template argument by - default. This means that the pointed object type must be \b complete - at the moment the \p unique_ptr is destroyed, \a except if the - supplied deleter is type-erased on its own. - - \remark The C++11 class \p std::unique_ptr should be preferred, if possible. -*/ - -template <typename T, typename D = typename tcg::deleter<T>> -class unique_ptr : private D // Empty Base Optimization -{ -public: - typedef typename tcg::traits<T>::element_type element_type; - typedef typename tcg::traits<element_type>::pointer_type ptr_type; - typedef typename tcg::traits<element_type>::reference_type ref_type; - -public: - explicit unique_ptr(ptr_type ptr = ptr_type()) // Explicit unary constructors - : m_ptr(ptr) {} - explicit unique_ptr(D d) : m_ptr(), D(d) {} // - unique_ptr(ptr_type ptr, D d) : m_ptr(ptr), D(d) {} - - ~unique_ptr() { D::operator()(m_ptr); } - - friend void swap(unique_ptr &a, unique_ptr &b) { - using std::swap; - - swap(static_cast<D &>(a), static_cast<D &>(b)); - swap(a.m_ptr, b.m_ptr); - } - - // Explicitly disabled (safe) conversion to bool - although - // std::unique_ptr could support it, that would just add overhead. - // It's also not compatible with other C++03 smart pointers. - - // typedef ptr_type unique_ptr::* bool_type; - - // operator bool_type() const // Safe bool - // idiom - // { return m_ptr ? &unique_ptr::m_ptr : 0; } // additional - // branching! - - ptr_type operator->() const { return m_ptr; } - ref_type operator*() const { return *m_ptr; } - ref_type operator[](size_t idx) const { return m_ptr[idx]; } - - void reset(ptr_type ptr = ptr_type()) { - D::operator()(m_ptr); - m_ptr = ptr; - } - - void reset(ptr_type ptr, D d) { - reset(ptr); - D::operator=(d); - } - - ptr_type release() { - ptr_type ptr = m_ptr; - m_ptr = ptr_type(); - return ptr; - } - - const ptr_type get() const { return m_ptr; } - ptr_type get() { return m_ptr; } - -private: - ptr_type m_ptr; -}; - -} // namespace tcg - -#endif // TCG_UNIQUE_PTR_H diff --git a/toonz/sources/stdfx/shaderfx.cpp b/toonz/sources/stdfx/shaderfx.cpp index 2b20347..bccff39 100644 --- a/toonz/sources/stdfx/shaderfx.cpp +++ b/toonz/sources/stdfx/shaderfx.cpp @@ -31,7 +31,6 @@ // tcg includes #include "tcg/tcg_function_types.h" -#include "tcg/tcg_unique_ptr.h" // Boost includes #include <boost/any.hpp> @@ -1008,7 +1007,7 @@ void ShaderFx::doCompute(TTile &tile, double frame, // Calculate input tiles ::ContextLocker cLocker(context); - tcg::unique_ptr<TTile[]> inTiles( + std::unique_ptr<TTile[]> inTiles( new TTile[pCount]); // NOTE: Input tiles must be STORED - they cannot // be passed immediately to OpenGL, since *other shader if (pCount > 0) // fxs*, with the very same host context, could lie diff --git a/toonz/sources/tnztools/plastictool_meshedit.cpp b/toonz/sources/tnztools/plastictool_meshedit.cpp index 52752cc..22deeb1 100644 --- a/toonz/sources/tnztools/plastictool_meshedit.cpp +++ b/toonz/sources/tnztools/plastictool_meshedit.cpp @@ -13,8 +13,6 @@ #include "tcg/tcg_point_ops.h" #include "tcg/tcg_iterator_ops.h" #include "tcg/tcg_function_types.h" -#include "tcg/tcg_deleter_types.h" -#include "tcg/tcg_unique_ptr.h" // boost includes #include <boost/unordered_set.hpp> @@ -515,8 +513,7 @@ void splitUnconnectedMesh(TMeshImage &mi, int meshIdx) { static void buildConnectedComponent(const TTextureMesh &mesh, boost::unordered_set<int> &vertexes) { // Prepare BFS algorithm - tcg::unique_ptr<UCHAR, tcg::freer> colorMapP( - (UCHAR *)calloc(mesh.vertices().nodesCount(), sizeof(UCHAR))); + std::unique_ptr<UCHAR[]> colorMapP(new UCHAR[mesh.vertices().nodesCount()]()); locals_::VertexesRecorder vertexesRecorder(vertexes); std::stack<int> verticesQueue; diff --git a/toonz/sources/tnztools/vectorselectiontool.cpp b/toonz/sources/tnztools/vectorselectiontool.cpp index bc413cf..c0c206c 100644 --- a/toonz/sources/tnztools/vectorselectiontool.cpp +++ b/toonz/sources/tnztools/vectorselectiontool.cpp @@ -568,9 +568,9 @@ DragSelectionTool::VectorDeformTool::~VectorDeformTool() { void DragSelectionTool::VectorDeformTool::applyTransform(FourPoints bbox) { SelectionTool *tool = getTool(); - tcg::unique_ptr<VFDScopedBlock> localVfdScopedBlock; - if (!m_vfdScopedBlock.get()) { - tcg::unique_ptr<VFDScopedBlock> &vfdScopedBlock = + std::unique_ptr<VFDScopedBlock> localVfdScopedBlock; + if (!m_vfdScopedBlock) { + std::unique_ptr<VFDScopedBlock> &vfdScopedBlock = m_isDragging ? m_vfdScopedBlock : localVfdScopedBlock; vfdScopedBlock.reset(new VFDScopedBlock(tool)); @@ -584,7 +584,7 @@ void DragSelectionTool::VectorDeformTool::applyTransform(FourPoints bbox) { freeDeformer->setPreserveThickness(tool->isConstantThickness()); freeDeformer->setFlip(isFlip()); - if (!TTool::getApplication()->getCurrentObject()->isSpline() && m_undo.get()) + if (!TTool::getApplication()->getCurrentObject()->isSpline() && m_undo) m_undo->setFlip(isFlip()); freeDeformer->deformImage(); @@ -608,7 +608,7 @@ void DragSelectionTool::VectorDeformTool::addTransformUndo() { ->getXsheet() ->getStageObject(getTool()->getObjectId()) ->getSpline())); - else if (m_undo.get()) { + else if (m_undo) { m_undo->registerStrokes(); TUndoManager::manager()->add(m_undo.release()); } @@ -652,7 +652,7 @@ void DragSelectionTool::VectorDeformTool::transformWholeLevel() { TVectorImageP vi = level->getFrame(fid, true); if (!vi) continue; - tcg::unique_ptr<UndoChangeStrokes> undo( + std::unique_ptr<UndoChangeStrokes> undo( new UndoChangeStrokes(level, fid, tool, tool->levelSelection())); std::set<int> strokesIndices; @@ -704,7 +704,7 @@ bool DragSelectionTool::VectorDeformTool::isFlip() { void DragSelectionTool::VectorDeformTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) { - tcg::unique_ptr<VFDScopedBlock> vfdScopedBlock(m_vfdScopedBlock.release()); + std::unique_ptr<VFDScopedBlock> vfdScopedBlock(std::move(m_vfdScopedBlock)); SelectionTool *tool = getTool(); VectorFreeDeformer *deformer = @@ -1046,7 +1046,7 @@ void DragSelectionTool::VectorChangeThicknessTool::addUndo() { } // Transform fid's selection - tcg::unique_ptr<UndoChangeStrokes> undo( + std::unique_ptr<UndoChangeStrokes> undo( new UndoChangeStrokes(level, fid, vtool, vtool->levelSelection())); setStrokesThickness(*vi); diff --git a/toonz/sources/tnztools/vectorselectiontool.h b/toonz/sources/tnztools/vectorselectiontool.h index 8a40723..94109a1 100644 --- a/toonz/sources/tnztools/vectorselectiontool.h +++ b/toonz/sources/tnztools/vectorselectiontool.h @@ -16,9 +16,6 @@ // Qt includes #include <QSet> -// tcg includes -#include "tcg/tcg_unique_ptr.h" - //============================================================ // Forward declarations @@ -160,7 +157,7 @@ public: bool isFlip(); protected: - tcg::unique_ptr<UndoChangeStrokes> m_undo; + std::unique_ptr<UndoChangeStrokes> m_undo; protected: void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {} @@ -171,7 +168,7 @@ protected: private: struct VFDScopedBlock; - tcg::unique_ptr<VFDScopedBlock> m_vfdScopedBlock; + std::unique_ptr<VFDScopedBlock> m_vfdScopedBlock; }; //============================================================================= @@ -179,7 +176,7 @@ private: //----------------------------------------------------------------------------- class VectorRotationTool final : public VectorDeformTool { - tcg::unique_ptr<Rotation> m_rotation; + std::unique_ptr<Rotation> m_rotation; public: VectorRotationTool(VectorSelectionTool *tool); @@ -194,7 +191,7 @@ public: //----------------------------------------------------------------------------- class VectorFreeDeformTool final : public VectorDeformTool { - tcg::unique_ptr<FreeDeform> m_freeDeform; + std::unique_ptr<FreeDeform> m_freeDeform; public: VectorFreeDeformTool(VectorSelectionTool *tool); @@ -207,7 +204,7 @@ public: //----------------------------------------------------------------------------- class VectorMoveSelectionTool final : public VectorDeformTool { - tcg::unique_ptr<MoveSelection> m_moveSelection; + std::unique_ptr<MoveSelection> m_moveSelection; public: VectorMoveSelectionTool(VectorSelectionTool *tool); @@ -222,7 +219,7 @@ public: //----------------------------------------------------------------------------- class VectorScaleTool final : public VectorDeformTool { - tcg::unique_ptr<Scale> m_scale; + std::unique_ptr<Scale> m_scale; public: VectorScaleTool(VectorSelectionTool *tool, int type); @@ -243,7 +240,7 @@ class VectorChangeThicknessTool final : public DragTool { std::map<int, std::vector<double>> m_strokesThickness; double m_thicknessChange; - tcg::unique_ptr<UndoChangeStrokes> m_undo; + std::unique_ptr<UndoChangeStrokes> m_undo; public: VectorChangeThicknessTool(VectorSelectionTool *tool); diff --git a/toonz/sources/toonz/cellselectioncommand.cpp b/toonz/sources/toonz/cellselectioncommand.cpp index e91fa6c..f971c7d 100644 --- a/toonz/sources/toonz/cellselectioncommand.cpp +++ b/toonz/sources/toonz/cellselectioncommand.cpp @@ -43,7 +43,6 @@ // tcg includes #include "tcg/tcg_macros.h" -#include "tcg/tcg_unique_ptr.h" // STD includes #include <ctime> @@ -352,7 +351,7 @@ class StepUndo final : public TUndo { int m_step; int m_newRows; - tcg::unique_ptr<TXshCell[]> m_cells; + std::unique_ptr<TXshCell[]> m_cells; public: StepUndo(int r0, int c0, int r1, int c1, int step); @@ -381,7 +380,7 @@ StepUndo::StepUndo(int r0, int c0, int r1, int c1, int step) , m_newRows(m_rowsCount * (step - 1)) , m_cells(new TXshCell[m_rowsCount * m_colsCount]) { assert(m_rowsCount > 0 && m_colsCount > 0 && step > 0); - assert(m_cells.get()); + assert(m_cells); int k = 0; for (int r = r0; r <= r1; ++r) @@ -405,7 +404,7 @@ void StepUndo::redo() const { //----------------------------------------------------------------------------- void StepUndo::undo() const { - TCG_ASSERT(m_rowsCount > 0 && m_colsCount > 0 && m_cells.get(), return ); + TCG_ASSERT(m_rowsCount > 0 && m_colsCount > 0 && m_cells, return ); TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); @@ -453,7 +452,7 @@ class EachUndo final : public TUndo { int m_each; int m_newRows; - tcg::unique_ptr<TXshCell[]> m_cells; + std::unique_ptr<TXshCell[]> m_cells; public: EachUndo(int r0, int c0, int r1, int c1, int each); @@ -483,7 +482,7 @@ EachUndo::EachUndo(int r0, int c0, int r1, int c1, int each) : m_rowsCount / each) , m_cells(new TXshCell[m_rowsCount * m_colsCount]) { assert(m_rowsCount > 0 && m_colsCount > 0 && each > 0); - assert(m_cells.get()); + assert(m_cells); int k = 0; for (int r = r0; r <= r1; ++r) @@ -507,7 +506,7 @@ void EachUndo::redo() const { //----------------------------------------------------------------------------- void EachUndo::undo() const { - TCG_ASSERT(m_rowsCount > 0 && m_colsCount > 0 && m_cells.get(), return ); + TCG_ASSERT(m_rowsCount > 0 && m_colsCount > 0 && m_cells, return ); TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); @@ -798,7 +797,7 @@ class ResetStepUndo final : public TUndo { int m_r0, m_c0, m_r1, m_c1; int m_rowsCount, m_colsCount; - tcg::unique_ptr<TXshCell[]> m_cells; + std::unique_ptr<TXshCell[]> m_cells; QMap<int, int> m_insertedCells; //!< Count of inserted cells, by column public: @@ -821,7 +820,7 @@ ResetStepUndo::ResetStepUndo(int r0, int c0, int r1, int c1) , m_colsCount(m_c1 - m_c0 + 1) , m_cells(new TXshCell[m_rowsCount * m_colsCount]) { assert(m_rowsCount > 0 && m_colsCount > 0); - assert(m_cells.get()); + assert(m_cells); TApp *app = TApp::instance(); @@ -897,7 +896,7 @@ class IncreaseStepUndo final : public TUndo { int m_r0, m_c0, m_r1, m_c1; int m_rowsCount, m_colsCount; - tcg::unique_ptr<TXshCell[]> m_cells; + std::unique_ptr<TXshCell[]> m_cells; QMap<int, int> m_insertedCells; public: @@ -923,7 +922,7 @@ IncreaseStepUndo::IncreaseStepUndo(int r0, int c0, int r1, int c1) , m_colsCount(m_c1 - m_c0 + 1) , m_cells(new TXshCell[m_rowsCount * m_colsCount]) , m_newR1(m_r1) { - assert(m_cells.get()); + assert(m_cells); int k = 0; for (int c = c0; c <= c1; ++c) { @@ -1001,7 +1000,7 @@ class DecreaseStepUndo final : public TUndo { int m_r0, m_c0, m_r1, m_c1; int m_rowsCount, m_colsCount; - tcg::unique_ptr<TXshCell[]> m_cells; + std::unique_ptr<TXshCell[]> m_cells; QMap<int, int> m_removedCells; public: @@ -1027,7 +1026,7 @@ DecreaseStepUndo::DecreaseStepUndo(int r0, int c0, int r1, int c1) , m_colsCount(m_c1 - m_c0 + 1) , m_cells(new TXshCell[m_rowsCount * m_colsCount]) , m_newR1(m_r1) { - assert(m_cells.get()); + assert(m_cells); int k = 0; for (int c = c0; c <= c1; ++c) {