Skip to content

Commit 5d6b4f4

Browse files
committed
dtool: add StreamReader/StreamWriter move ctor and assignment ops
1 parent 269d3db commit 5d6b4f4

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

dtool/src/prc/streamReader.I

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ StreamReader(const StreamReader &copy) :
4343
}
4444

4545
/**
46-
* The copy constructor does not copy ownership of the stream.
46+
* The move constructor steals ownership of the stream.
47+
*/
48+
INLINE StreamReader::
49+
StreamReader(StreamReader &&from) noexcept :
50+
_in(from._in),
51+
_owns_stream(from._owns_stream)
52+
{
53+
from._owns_stream = false;
54+
}
55+
56+
/**
57+
* The copy assignment operator does not copy ownership of the stream.
4758
*/
4859
INLINE void StreamReader::
4960
operator = (const StreamReader &copy) {
@@ -54,6 +65,19 @@ operator = (const StreamReader &copy) {
5465
_owns_stream = false;
5566
}
5667

68+
/**
69+
* The move assignment operator steals ownership of the stream.
70+
*/
71+
INLINE void StreamReader::
72+
operator = (StreamReader &&from) noexcept {
73+
if (_owns_stream) {
74+
delete _in;
75+
}
76+
_in = from._in;
77+
_owns_stream = from._owns_stream;
78+
from._owns_stream = false;
79+
}
80+
5781
/**
5882
*
5983
*/

dtool/src/prc/streamReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class EXPCL_DTOOL_PRC StreamReader {
3131
PUBLISHED:
3232
INLINE explicit StreamReader(std::istream *in, bool owns_stream);
3333
INLINE StreamReader(const StreamReader &copy);
34+
INLINE StreamReader(StreamReader &&from) noexcept;
3435
INLINE void operator = (const StreamReader &copy);
36+
INLINE void operator = (StreamReader &&from) noexcept;
3537
INLINE ~StreamReader();
3638

3739
INLINE std::istream *get_istream() const;

dtool/src/prc/streamWriter.I

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,21 @@ StreamWriter(const StreamWriter &copy) :
5151
}
5252

5353
/**
54-
* The copy constructor does not copy ownership of the stream.
54+
* The move constructor steals ownership of the stream.
55+
*/
56+
INLINE StreamWriter::
57+
StreamWriter(StreamWriter &&from) noexcept :
58+
#ifdef HAVE_PYTHON
59+
softspace(0),
60+
#endif
61+
_out(from._out),
62+
_owns_stream(from._owns_stream)
63+
{
64+
from._owns_stream = false;
65+
}
66+
67+
/**
68+
* The copy assignment operator does not copy ownership of the stream.
5569
*/
5670
INLINE void StreamWriter::
5771
operator = (const StreamWriter &copy) {
@@ -62,6 +76,19 @@ operator = (const StreamWriter &copy) {
6276
_owns_stream = false;
6377
}
6478

79+
/**
80+
* The move assignment operator steals ownership of the stream.
81+
*/
82+
INLINE void StreamWriter::
83+
operator = (StreamWriter &&from) noexcept {
84+
if (_owns_stream) {
85+
delete _out;
86+
}
87+
_out = from._out;
88+
_owns_stream = from._owns_stream;
89+
from._owns_stream = false;
90+
}
91+
6592
/**
6693
*
6794
*/

dtool/src/prc/streamWriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class EXPCL_DTOOL_PRC StreamWriter {
3232
PUBLISHED:
3333
INLINE explicit StreamWriter(std::ostream *out, bool owns_stream);
3434
INLINE StreamWriter(const StreamWriter &copy);
35+
INLINE StreamWriter(StreamWriter &&from) noexcept;
3536
INLINE void operator = (const StreamWriter &copy);
37+
INLINE void operator = (StreamWriter &&from) noexcept;
3638
INLINE ~StreamWriter();
3739

3840
INLINE std::ostream *get_ostream() const;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy