diff --git a/dtool/src/prc/streamReader.I b/dtool/src/prc/streamReader.I index e15953aeba..36f8b93e92 100644 --- a/dtool/src/prc/streamReader.I +++ b/dtool/src/prc/streamReader.I @@ -43,7 +43,18 @@ StreamReader(const StreamReader ©) : } /** - * The copy constructor does not copy ownership of the stream. + * The move constructor steals ownership of the stream. + */ +INLINE StreamReader:: +StreamReader(StreamReader &&from) noexcept : + _in(from._in), + _owns_stream(from._owns_stream) +{ + from._owns_stream = false; +} + +/** + * The copy assignment operator does not copy ownership of the stream. */ INLINE void StreamReader:: operator = (const StreamReader ©) { @@ -54,6 +65,19 @@ operator = (const StreamReader ©) { _owns_stream = false; } +/** + * The move assignment operator steals ownership of the stream. + */ +INLINE void StreamReader:: +operator = (StreamReader &&from) noexcept { + if (_owns_stream) { + delete _in; + } + _in = from._in; + _owns_stream = from._owns_stream; + from._owns_stream = false; +} + /** * */ diff --git a/dtool/src/prc/streamReader.h b/dtool/src/prc/streamReader.h index a317f0a783..4d32e0616e 100644 --- a/dtool/src/prc/streamReader.h +++ b/dtool/src/prc/streamReader.h @@ -31,7 +31,9 @@ public: PUBLISHED: INLINE explicit StreamReader(std::istream *in, bool owns_stream); INLINE StreamReader(const StreamReader ©); + INLINE StreamReader(StreamReader &&from) noexcept; INLINE void operator = (const StreamReader ©); + INLINE void operator = (StreamReader &&from) noexcept; INLINE ~StreamReader(); INLINE std::istream *get_istream() const; diff --git a/dtool/src/prc/streamWriter.I b/dtool/src/prc/streamWriter.I index b2485d3fc7..1f12c1517e 100644 --- a/dtool/src/prc/streamWriter.I +++ b/dtool/src/prc/streamWriter.I @@ -51,7 +51,21 @@ StreamWriter(const StreamWriter ©) : } /** - * The copy constructor does not copy ownership of the stream. + * The move constructor steals ownership of the stream. + */ +INLINE StreamWriter:: +StreamWriter(StreamWriter &&from) noexcept : +#ifdef HAVE_PYTHON + softspace(0), +#endif + _out(from._out), + _owns_stream(from._owns_stream) +{ + from._owns_stream = false; +} + +/** + * The copy assignment operator does not copy ownership of the stream. */ INLINE void StreamWriter:: operator = (const StreamWriter ©) { @@ -62,6 +76,19 @@ operator = (const StreamWriter ©) { _owns_stream = false; } +/** + * The move assignment operator steals ownership of the stream. + */ +INLINE void StreamWriter:: +operator = (StreamWriter &&from) noexcept { + if (_owns_stream) { + delete _out; + } + _out = from._out; + _owns_stream = from._owns_stream; + from._owns_stream = false; +} + /** * */ diff --git a/dtool/src/prc/streamWriter.h b/dtool/src/prc/streamWriter.h index cc00ef9ce3..8072e8aa40 100644 --- a/dtool/src/prc/streamWriter.h +++ b/dtool/src/prc/streamWriter.h @@ -32,7 +32,9 @@ public: PUBLISHED: INLINE explicit StreamWriter(std::ostream *out, bool owns_stream); INLINE StreamWriter(const StreamWriter ©); + INLINE StreamWriter(StreamWriter &&from) noexcept; INLINE void operator = (const StreamWriter ©); + INLINE void operator = (StreamWriter &&from) noexcept; INLINE ~StreamWriter(); INLINE std::ostream *get_ostream() const;