From 5f2af016ab4f18453637652073feac055614c21a Mon Sep 17 00:00:00 2001 From: Shinya Kitaoka Date: Apr 19 2016 07:54:53 +0000 Subject: add move constructors --- diff --git a/toonz/sources/common/tstream/tstream.cpp b/toonz/sources/common/tstream/tstream.cpp index ac70b7f..ae5a30b 100644 --- a/toonz/sources/common/tstream/tstream.cpp +++ b/toonz/sources/common/tstream/tstream.cpp @@ -262,7 +262,7 @@ TOStream::TOStream(std::shared_ptr imp) { assert(!m_imp->m_tagStack.empty()); ostream &os = *m_imp->m_os; - if (m_imp->m_justStarted == false) + if (!m_imp->m_justStarted) cr(); os << "<" << m_imp->m_tagStack.back() << ">"; m_imp->m_tab++; @@ -270,10 +270,26 @@ TOStream::TOStream(std::shared_ptr imp) m_imp->m_justStarted = true; } +TOStream::TOStream(TOStream&& that) + : m_imp(std::move(that.m_imp)) +{ +} + +TOStream& TOStream::operator = (TOStream && that) +{ + if (this != &that) { + this->m_imp = std::move(that.m_imp); + } + return *this; +} + //--------------------------------------------------------------- TOStream::~TOStream() { + if (!m_imp) { + return; + } try { if (!m_imp->m_tagStack.empty()) { string tagName = m_imp->m_tagStack.back(); @@ -501,7 +517,7 @@ TOStream TOStream::child(string tagName) { assert(tagName != ""); m_imp->m_tagStack.push_back(tagName); - return m_imp; + return TOStream(m_imp); } //--------------------------------------------------------------- diff --git a/toonz/sources/include/tstream.h b/toonz/sources/include/tstream.h index 4f9b412..d4a2ee7 100644 --- a/toonz/sources/include/tstream.h +++ b/toonz/sources/include/tstream.h @@ -171,7 +171,10 @@ class DVAPI TOStream std::shared_ptr m_imp; private: - TOStream(std::shared_ptr imp); //!< deprecated + explicit TOStream(std::shared_ptr imp); //!< deprecated + + TOStream(TOStream &&); + TOStream& operator=(TOStream &&); public: /*! @@ -238,7 +241,7 @@ public: private: // Not copyable - TOStream(const TOStream &) = default; //!< Not implemented + TOStream(const TOStream &) = delete; //!< Not implemented TOStream &operator=(const TOStream &) = delete; //!< Not implemented };