Skip to content

Commit

Permalink
Add another rvalue constructor to the String class
Browse files Browse the repository at this point in the history
refs #12555
  • Loading branch information
gunnarbeutner committed Aug 31, 2016
1 parent 7e293b0 commit 54f0cb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/base/string.cpp
Expand Up @@ -29,6 +29,23 @@ REGISTER_BUILTIN_TYPE(String, String::GetPrototype());

const String::SizeType String::NPos = std::string::npos;

String::String(Value&& other)
{
*this = std::move(other);
}

String& String::operator=(Value&& other)
{
const String *p = other.GetPtr<String>();

if (p)
m_Data = std::move(p->m_Data);
else
m_Data = other;

return *this;
}

String& String::operator+=(const Value& rhs)
{
m_Data += static_cast<String>(rhs);
Expand Down
4 changes: 4 additions & 0 deletions lib/base/string.hpp
Expand Up @@ -85,6 +85,8 @@ class I2_BASE_API String
: m_Data(std::move(other.m_Data))
{ }

String(Value&& other);

inline ~String(void)
{ }

Expand All @@ -105,6 +107,8 @@ class I2_BASE_API String
return *this;
}

String& operator=(Value&& rhs);

inline String& operator=(const std::string& rhs)
{
m_Data = rhs;
Expand Down
6 changes: 6 additions & 0 deletions lib/base/value.hpp
Expand Up @@ -286,6 +286,12 @@ class I2_BASE_API Value
return boost::get<T>(m_Value);
}

template<typename T>
const T *GetPtr(void) const
{
return &boost::get<T>(m_Value);
}

private:
boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value;
};
Expand Down

0 comments on commit 54f0cb2

Please sign in to comment.