3232#include < stdio.h>
3333#include < string.h>
3434#include < stdarg.h>
35+ #include < utility>
3536
3637#include " firebird.h"
3738#include " fb_types.h"
@@ -203,6 +204,27 @@ namespace Firebird
203204 memcpy (stringBuffer, s, l);
204205 }
205206
207+ AbstractString (const size_type limit, AbstractString&& rhs) :
208+ max_length(static_cast <internal_size_type>(limit))
209+ {
210+ // We can move only string with default pool
211+ if (!baseMove (std::forward<AbstractString>(rhs)))
212+ {
213+ initialize (rhs.length ());
214+ memcpy (stringBuffer, rhs.c_str (), stringLength);
215+ }
216+ }
217+
218+ AbstractString (const size_type limit, MemoryPool& p, AbstractString&& rhs)
219+ : AutoStorage(p), max_length(static_cast <internal_size_type>(limit))
220+ {
221+ if (!baseMove (std::forward<AbstractString>(rhs)))
222+ {
223+ initialize (rhs.length ());
224+ memcpy (stringBuffer, rhs.c_str (), stringLength);
225+ }
226+ }
227+
206228 pointer modify ()
207229 {
208230 return stringBuffer;
@@ -223,6 +245,8 @@ namespace Firebird
223245
224246 void baseTrim (const TrimType whereTrim, const_pointer toTrim);
225247
248+ bool baseMove (AbstractString&& rhs);
249+
226250 size_type getMaxLength () const
227251 {
228252 return max_length;
@@ -676,6 +700,10 @@ namespace Firebird
676700 AbstractString (Comparator::getMaxLength(), p, s, static_cast <size_type>(s ? strlen(s) : 0 )) {}
677701 StringBase (MemoryPool& p, const char_type* s, size_type l) :
678702 AbstractString (Comparator::getMaxLength(), p, s, l) {}
703+ StringBase (StringType&& rhs) :
704+ AbstractString (Comparator::getMaxLength(), std::forward<AbstractString>(rhs)) {}
705+ StringBase (MemoryPool& p, StringType&& rhs) :
706+ AbstractString (Comparator::getMaxLength(), p, std::forward<AbstractString>(rhs)) {}
679707
680708 static size_type max_length ()
681709 {
@@ -754,6 +782,25 @@ namespace Firebird
754782 {
755783 return add (&c, 1 );
756784 }
785+ StringType& operator =(StringType&& rhs)
786+ {
787+ // baseMove do not clear the buffer so do it in this method
788+ char_type* backup = nullptr ;
789+ if (stringBuffer != inlineBuffer)
790+ backup = stringBuffer;
791+
792+ if (baseMove (std::forward<AbstractString>(rhs)))
793+ {
794+ // The dynamic buffer has been replaced, so clear the old one
795+ delete[] backup;
796+ }
797+ else
798+ {
799+ // Cannot move, do the base assignment
800+ assign (rhs.c_str (), rhs.length ());
801+ }
802+ return *this ;
803+ }
757804
758805 StringBase<StringComparator> ToString () const
759806 {
0 commit comments