@@ -107,14 +107,19 @@ namespace ojph {
107107 // //////////////////////////////////////////////////////////////////////////
108108 mem_outfile::mem_outfile ()
109109 {
110- reset (*this );
110+ is_open = clear_mem = false ;
111+ buf_size = used_size = 0 ;
112+ buf = cur_ptr = nullptr ;
111113 }
112114
113115 // //////////////////////////////////////////////////////////////////////////
114- void mem_outfile::reset (mem_outfile& f) noexcept {
115- f.is_open = f.clear_mem = false ;
116- f.buf_size = f.used_size = 0 ;
117- f.buf = f.cur_ptr = nullptr ;
116+ void mem_outfile::swap (mem_outfile& other) noexcept {
117+ std::swap (this ->is_open ,other.is_open );
118+ std::swap (this ->clear_mem ,other.clear_mem );
119+ std::swap (this ->buf_size ,other.buf_size );
120+ std::swap (this ->used_size ,other.used_size );
121+ std::swap (this ->buf ,other.buf );
122+ std::swap (this ->cur_ptr ,other.cur_ptr );
118123 }
119124
120125 // //////////////////////////////////////////////////////////////////////////
@@ -128,24 +133,18 @@ namespace ojph {
128133 }
129134
130135 // //////////////////////////////////////////////////////////////////////////
131- mem_outfile::mem_outfile (mem_outfile&& rhs) noexcept
136+ mem_outfile::mem_outfile (mem_outfile&& rhs) noexcept : mem_outfile()
132137 {
133- reset (*this );
134- std::swap (*this , rhs);
138+ this ->swap (rhs);
135139 }
136140
137141 // //////////////////////////////////////////////////////////////////////////
138142 mem_outfile& mem_outfile::operator =(mem_outfile&& rhs) noexcept
139143 {
140- if (this == &rhs)
141- return *this ;
142-
143- if (this ->buf )
144- ojph_aligned_free (this ->buf );
145-
146- reset (*this );
147- std::swap (*this , rhs);
148-
144+ if (this != &rhs) {
145+ mem_outfile tmp (std::move (rhs));
146+ this ->swap (tmp);
147+ }
149148 return *this ;
150149 }
151150
@@ -318,6 +317,22 @@ namespace ojph {
318317 //
319318 // //////////////////////////////////////////////////////////////////////////
320319
320+ // //////////////////////////////////////////////////////////////////////////
321+ mem_infile::mem_infile (mem_infile&& rhs) noexcept : mem_infile()
322+ {
323+ this ->swap (rhs);
324+ }
325+
326+ // //////////////////////////////////////////////////////////////////////////
327+ mem_infile& mem_infile::operator =(mem_infile&& rhs) noexcept
328+ {
329+ if (this != &rhs) {
330+ mem_infile tmp (std::move (rhs));
331+ this ->swap (tmp);
332+ }
333+ return *this ;
334+ }
335+
321336 // //////////////////////////////////////////////////////////////////////////
322337 void mem_infile::open (const ui8* data, size_t size)
323338 {
@@ -376,5 +391,12 @@ namespace ojph {
376391 return result;
377392 }
378393
394+ // //////////////////////////////////////////////////////////////////////////
395+ void mem_infile::swap (mem_infile& other) noexcept
396+ {
397+ std::swap (this ->data ,other.data );
398+ std::swap (this ->cur_ptr ,other.cur_ptr );
399+ std::swap (this ->size ,other.size );
400+ }
379401
380402}
0 commit comments