MT#62181 AmArg: add missing copy/assignment ctor

We still have raw pointers in the variant and so we need to deal with
copying the contained objects ourselves.

Change-Id: I0e5f1b56430ffeda9d34ede30ec87cfd45a61662
master
Richard Fuchs 2 months ago
parent 5fd2cfac8e
commit c7c12a1494

@ -46,6 +46,21 @@ const char* AmArg::t2str(int type) {
}
}
AmArg::AmArg(const AmArg& v)
: type(v.type) {
switch (type) {
case Array:
value = new ValueArray(*std::get<ValueArray*>(v.value));
break;
case Struct:
value = new ValueStruct(*std::get<ValueStruct*>(v.value));
break;
default:
value = v.value;
break;
}
}
AmArg::AmArg(std::map<std::string, std::string>& v)
: type(Undef) {
assertStruct();
@ -233,6 +248,23 @@ AmArg& AmArg::get(size_t idx) const {
return (*std::get<ValueArray*>(value))[idx];
}
AmArg& AmArg::operator=(const AmArg& v) {
invalidate();
type = v.type;
switch (type) {
case Array:
value = new ValueArray(*std::get<ValueArray*>(v.value));
break;
case Struct:
value = new ValueStruct(*std::get<ValueStruct*>(v.value));
break;
default:
value = v.value;
break;
}
return *this;
}
AmArg& AmArg::operator[](size_t idx) {
assertArray(idx+1);
return (*std::get<ValueArray*>(value))[idx];

@ -128,7 +128,7 @@ class AmArg
: type(Undef)
{ }
AmArg(const AmArg& v) = default;
AmArg(const AmArg& v);
AmArg(const int& v)
: type(Int),
@ -197,7 +197,7 @@ class AmArg
short getType() const { return type; }
AmArg& operator=(const AmArg& rhs) = default;
AmArg& operator=(const AmArg& rhs);
#define isArgUndef(a) (AmArg::Undef == a.getType())
#define isArgArray(a) (AmArg::Array == a.getType())

Loading…
Cancel
Save