summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRye Mutt <rye@alchemyviewer.org>2024-07-04 00:49:45 -0400
committerRye Mutt <rye@alchemyviewer.org>2024-07-05 02:56:25 -0400
commit7df1edbde100d1c07bd4d2edcfa76ea7a870de42 (patch)
treed4af44d15c787ffbe6c1f1c62f03b55b9d938ee0
parent59312bf209c5fcdb27c283caaa2ed36502ec7a33 (diff)
Introduce move assignment operators for various LLSD types
-rw-r--r--indra/llcommon/llsd.cpp100
-rw-r--r--indra/llcommon/llsd.h15
2 files changed, 104 insertions, 11 deletions
diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index a9cd8c597e..0576182c98 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -123,11 +123,17 @@ public:
virtual void assign(Impl*& var, LLSD::Boolean);
virtual void assign(Impl*& var, LLSD::Integer);
virtual void assign(Impl*& var, LLSD::Real);
+ virtual void assign(Impl*& var, const char*);
virtual void assign(Impl*& var, const LLSD::String&);
virtual void assign(Impl*& var, const LLSD::UUID&);
virtual void assign(Impl*& var, const LLSD::Date&);
virtual void assign(Impl*& var, const LLSD::URI&);
virtual void assign(Impl*& var, const LLSD::Binary&);
+ virtual void assign(Impl*& var, LLSD::String&&);
+ virtual void assign(Impl*& var, LLSD::UUID&&);
+ virtual void assign(Impl*& var, LLSD::Date&&);
+ virtual void assign(Impl*& var, LLSD::URI&&);
+ virtual void assign(Impl*& var, LLSD::Binary&&);
///< If the receiver is the right type and unshared, these are simple
// data assignments, othewise the default implementation handless
// constructing the proper Impl subclass
@@ -185,7 +191,7 @@ namespace LLSDUnnamedNamespace
namespace
#endif
{
- template<LLSD::Type T, class Data, class DataRef = Data>
+ template<LLSD::Type T, class Data, class DataRef = Data, class DataMove = Data>
class ImplBase : public LLSD::Impl
///< This class handles most of the work for a subclass of Impl
// for a given simple data type. Subclasses of this provide the
@@ -198,6 +204,7 @@ namespace
public:
ImplBase(DataRef value) : mValue(value) { }
+ ImplBase(DataMove value) : mValue(std::move(value)) { }
virtual LLSD::Type type() const { return T; }
@@ -212,11 +219,21 @@ namespace
mValue = value;
}
}
+ virtual void assign(LLSD::Impl*& var, DataMove value) {
+ if (shared())
+ {
+ Impl::assign(var, std::move(value));
+ }
+ else
+ {
+ mValue = std::move(value);
+ }
+ }
};
class ImplBoolean
- : public ImplBase<LLSD::TypeBoolean, LLSD::Boolean>
+ : public ImplBase<LLSD::TypeBoolean, LLSD::Boolean, LLSD::Boolean, LLSD::Boolean&&>
{
public:
ImplBoolean(LLSD::Boolean v) : Base(v) { }
@@ -239,7 +256,7 @@ namespace
class ImplInteger
- : public ImplBase<LLSD::TypeInteger, LLSD::Integer>
+ : public ImplBase<LLSD::TypeInteger, LLSD::Integer, LLSD::Integer, LLSD::Integer&&>
{
public:
ImplInteger(LLSD::Integer v) : Base(v) { }
@@ -257,7 +274,7 @@ namespace
class ImplReal
- : public ImplBase<LLSD::TypeReal, LLSD::Real>
+ : public ImplBase<LLSD::TypeReal, LLSD::Real, LLSD::Real, LLSD::Real&&>
{
public:
ImplReal(LLSD::Real v) : Base(v) { }
@@ -281,10 +298,11 @@ namespace
class ImplString
- : public ImplBase<LLSD::TypeString, LLSD::String, const LLSD::String&>
+ : public ImplBase<LLSD::TypeString, LLSD::String, const LLSD::String&, LLSD::String&&>
{
public:
ImplString(const LLSD::String& v) : Base(v) { }
+ ImplString(LLSD::String&& v) : Base(std::move(v)) {}
virtual LLSD::Boolean asBoolean() const { return !mValue.empty(); }
virtual LLSD::Integer asInteger() const;
@@ -297,6 +315,19 @@ namespace
virtual const LLSD::String& asStringRef() const { return mValue; }
virtual LLSD::String asXMLRPCValue() const { return "<string>" + LLStringFn::xml_encode(mValue) + "</string>"; }
+
+ using LLSD::Impl::assign; // Unhiding base class virtuals...
+ virtual void assign(LLSD::Impl*& var, const char* value)
+ {
+ if (shared())
+ {
+ Impl::assign(var, value);
+ }
+ else
+ {
+ mValue = value;
+ }
+ }
};
LLSD::Integer ImplString::asInteger() const
@@ -327,10 +358,11 @@ namespace
class ImplUUID
- : public ImplBase<LLSD::TypeUUID, LLSD::UUID, const LLSD::UUID&>
+ : public ImplBase<LLSD::TypeUUID, LLSD::UUID, const LLSD::UUID&, LLSD::UUID&&>
{
public:
ImplUUID(const LLSD::UUID& v) : Base(v) { }
+ ImplUUID(LLSD::UUID&& v) : Base(std::move(v)) { }
virtual LLSD::String asString() const{ return mValue.asString(); }
virtual LLSD::UUID asUUID() const { return mValue; }
@@ -340,13 +372,17 @@ namespace
class ImplDate
- : public ImplBase<LLSD::TypeDate, LLSD::Date, const LLSD::Date&>
+ : public ImplBase<LLSD::TypeDate, LLSD::Date, const LLSD::Date&, LLSD::Date&&>
{
public:
ImplDate(const LLSD::Date& v)
- : ImplBase<LLSD::TypeDate, LLSD::Date, const LLSD::Date&>(v)
+ : ImplBase(v)
{ }
+ ImplDate(LLSD::Date&& v)
+ : ImplBase(std::move(v))
+ { }
+
virtual LLSD::Integer asInteger() const
{
return (LLSD::Integer)(mValue.secondsSinceEpoch());
@@ -363,10 +399,11 @@ namespace
class ImplURI
- : public ImplBase<LLSD::TypeURI, LLSD::URI, const LLSD::URI&>
+ : public ImplBase<LLSD::TypeURI, LLSD::URI, const LLSD::URI&, LLSD::URI&&>
{
public:
ImplURI(const LLSD::URI& v) : Base(v) { }
+ ImplURI(LLSD::URI&& v) : Base(std::move(v)) { }
virtual LLSD::String asString() const{ return mValue.asString(); }
virtual LLSD::URI asURI() const { return mValue; }
@@ -376,10 +413,11 @@ namespace
class ImplBinary
- : public ImplBase<LLSD::TypeBinary, LLSD::Binary, const LLSD::Binary&>
+ : public ImplBase<LLSD::TypeBinary, LLSD::Binary, const LLSD::Binary&, LLSD::Binary&&>
{
public:
ImplBinary(const LLSD::Binary& v) : Base(v) { }
+ ImplBinary(LLSD::Binary&& v) : Base(std::move(v)) { }
virtual const LLSD::Binary& asBinary() const{ return mValue; }
@@ -789,6 +827,11 @@ void LLSD::Impl::assign(Impl*& var, LLSD::Real v)
reset(var, new ImplReal(v));
}
+void LLSD::Impl::assign(Impl*& var, const char* v)
+{
+ reset(var, new ImplString(v));
+}
+
void LLSD::Impl::assign(Impl*& var, const LLSD::String& v)
{
reset(var, new ImplString(v));
@@ -814,6 +857,31 @@ void LLSD::Impl::assign(Impl*& var, const LLSD::Binary& v)
reset(var, new ImplBinary(v));
}
+void LLSD::Impl::assign(Impl*& var, LLSD::String&& v)
+{
+ reset(var, new ImplString(std::move(v)));
+}
+
+void LLSD::Impl::assign(Impl*& var, LLSD::UUID&& v)
+{
+ reset(var, new ImplUUID(std::move(v)));
+}
+
+void LLSD::Impl::assign(Impl*& var, LLSD::Date&& v)
+{
+ reset(var, new ImplDate(std::move(v)));
+}
+
+void LLSD::Impl::assign(Impl*& var, LLSD::URI&& v)
+{
+ reset(var, new ImplURI(std::move(v)));
+}
+
+void LLSD::Impl::assign(Impl*& var, LLSD::Binary&& v)
+{
+ reset(var, new ImplBinary(std::move(v)));
+}
+
const LLSD& LLSD::Impl::undef()
{
@@ -900,6 +968,11 @@ LLSD::LLSD(const String& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
LLSD::LLSD(const Date& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
LLSD::LLSD(const URI& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
LLSD::LLSD(const Binary& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
+LLSD::LLSD(UUID&& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(std::move(v)); }
+LLSD::LLSD(String&& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(std::move(v)); }
+LLSD::LLSD(Date&& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(std::move(v)); }
+LLSD::LLSD(URI&& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(std::move(v)); }
+LLSD::LLSD(Binary&& v) : impl(0) { ALLOC_LLSD_OBJECT; assign(std::move(v)); }
// Scalar Assignment
void LLSD::assign(Boolean v) { safe(impl).assign(impl, v); }
@@ -910,6 +983,11 @@ void LLSD::assign(const UUID& v) { safe(impl).assign(impl, v); }
void LLSD::assign(const Date& v) { safe(impl).assign(impl, v); }
void LLSD::assign(const URI& v) { safe(impl).assign(impl, v); }
void LLSD::assign(const Binary& v) { safe(impl).assign(impl, v); }
+void LLSD::assign(String&& v) { safe(impl).assign(impl, std::move(v)); }
+void LLSD::assign(UUID&& v) { safe(impl).assign(impl, std::move(v)); }
+void LLSD::assign(Date&& v) { safe(impl).assign(impl, std::move(v)); }
+void LLSD::assign(URI&& v) { safe(impl).assign(impl, std::move(v)); }
+void LLSD::assign(Binary&& v) { safe(impl).assign(impl, std::move(v)); }
// Scalar Accessors
LLSD::Boolean LLSD::asBoolean() const { return safe(impl).asBoolean(); }
@@ -1076,7 +1154,7 @@ bool LLSD::fromXMLRPCValue(TreeNode* node)
LLSD::LLSD(const char* v) : impl(0) { ALLOC_LLSD_OBJECT; assign(v); }
void LLSD::assign(const char* v)
{
- if(v) assign(std::string(v));
+ if(v) safe(impl).assign(impl, v);
else assign(std::string());
}
diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h
index 675cbb0edb..77f1606554 100644
--- a/indra/llcommon/llsd.h
+++ b/indra/llcommon/llsd.h
@@ -188,6 +188,11 @@ public:
LLSD(const Date&);
LLSD(const URI&);
LLSD(const Binary&);
+ LLSD(String&&);
+ LLSD(UUID&&);
+ LLSD(Date&&);
+ LLSD(URI&&);
+ LLSD(Binary&&);
//@}
/** @name Convenience Constructors */
@@ -215,6 +220,11 @@ public:
void assign(const Date&);
void assign(const URI&);
void assign(const Binary&);
+ void assign(String&&);
+ void assign(UUID&&);
+ void assign(Date&&);
+ void assign(URI&&);
+ void assign(Binary&&);
LLSD& operator=(Boolean v) { assign(v); return *this; }
LLSD& operator=(Integer v) { assign(v); return *this; }
@@ -224,6 +234,11 @@ public:
LLSD& operator=(const Date& v) { assign(v); return *this; }
LLSD& operator=(const URI& v) { assign(v); return *this; }
LLSD& operator=(const Binary& v) { assign(v); return *this; }
+ LLSD& operator=(String&& v) { assign(std::move(v)); return *this; }
+ LLSD& operator=(UUID&& v) { assign(std::move(v)); return *this; }
+ LLSD& operator=(Date&& v) { assign(std::move(v)); return *this; }
+ LLSD& operator=(URI&& v) { assign(std::move(v)); return *this; }
+ LLSD& operator=(Binary&& v) { assign(std::move(v)); return *this; }
//@}
/**