32
32
#include < stdio.h>
33
33
#include < string.h>
34
34
#include < stdarg.h>
35
+ #include < utility>
35
36
36
37
#include " firebird.h"
37
38
#include " fb_types.h"
@@ -203,6 +204,27 @@ namespace Firebird
203
204
memcpy (stringBuffer, s, l);
204
205
}
205
206
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
+
206
228
pointer modify ()
207
229
{
208
230
return stringBuffer;
@@ -223,6 +245,8 @@ namespace Firebird
223
245
224
246
void baseTrim (const TrimType whereTrim, const_pointer toTrim);
225
247
248
+ bool baseMove (AbstractString&& rhs);
249
+
226
250
size_type getMaxLength () const
227
251
{
228
252
return max_length;
@@ -676,6 +700,10 @@ namespace Firebird
676
700
AbstractString (Comparator::getMaxLength(), p, s, static_cast <size_type>(s ? strlen(s) : 0 )) {}
677
701
StringBase (MemoryPool& p, const char_type* s, size_type l) :
678
702
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)) {}
679
707
680
708
static size_type max_length ()
681
709
{
@@ -754,6 +782,25 @@ namespace Firebird
754
782
{
755
783
return add (&c, 1 );
756
784
}
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
+ }
757
804
758
805
StringBase<StringComparator> ToString () const
759
806
{
0 commit comments