Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

add move constructors

Shinya Kitaoka5f2af016ab4f
diff --git a/toonz/sources/common/tstream/tstream.cpp b/toonz/sources/common/tstream/tstream.cpp
index ac70b7f49..ae5a30b32 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> 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> 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 4f9b4128e..d4a2ee7b9 100644
--- a/toonz/sources/include/tstream.h
+++ b/toonz/sources/include/tstream.h
@@ -171,7 +171,10 @@ class DVAPI TOStream
std::shared_ptr<Imp> m_imp;
private:
- TOStream(std::shared_ptr<Imp> imp); //!< deprecated
+ explicit TOStream(std::shared_ptr<Imp> 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
};