Make VariableData uncopyable but moveable

This commit is contained in:
Thomas Goyne 2012-12-09 08:06:10 -08:00
parent 482d31299b
commit 851f7f40e6
4 changed files with 17 additions and 13 deletions

View File

@ -56,18 +56,13 @@ AssOverrideParameter::AssOverrideParameter()
{ {
} }
AssOverrideParameter::AssOverrideParameter(const AssOverrideParameter &param) AssOverrideParameter::AssOverrideParameter(AssOverrideParameter&& o)
: VariableData(param) : VariableData(std::move(o))
, classification(param.classification) , classification(o.classification)
, omitted(param.omitted) , omitted(o.omitted)
{ {
} }
void AssOverrideParameter::operator=(const AssOverrideParameter &param) {
DeleteValue();
new(this) AssOverrideParameter(param);
}
// From ass_dialogue.h // From ass_dialogue.h
AssDialogueBlockOverride::~AssDialogueBlockOverride() { AssDialogueBlockOverride::~AssDialogueBlockOverride() {
delete_clear(Tags); delete_clear(Tags);
@ -117,7 +112,7 @@ void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callb
} }
} }
AssOverrideParamProto::AssOverrideParamProto(VariableDataType type,int opt,AssParameterClass classi) AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi)
: optional(opt) : optional(opt)
, type(type) , type(type)
, classification(classi) , classification(classi)

View File

@ -68,6 +68,8 @@ enum AssParameterOptional {
/// A single parameter to an override tag /// A single parameter to an override tag
class AssOverrideParameter : public VariableData { class AssOverrideParameter : public VariableData {
public: public:
AssOverrideParameter(AssOverrideParameter&&);
/// Type of parameter /// Type of parameter
AssParameterClass classification; AssParameterClass classification;
@ -75,8 +77,6 @@ public:
bool omitted; bool omitted;
AssOverrideParameter(); AssOverrideParameter();
AssOverrideParameter(const AssOverrideParameter&);
void operator=(const AssOverrideParameter &param);
}; };
/// Prototype of a single override parameter /// Prototype of a single override parameter

View File

@ -47,6 +47,12 @@ VariableData::VariableData() {
value = nullptr; value = nullptr;
} }
VariableData::VariableData(VariableData&& o)
: type(o.type)
, value(o.value)
{
}
VariableData::~VariableData() { VariableData::~VariableData() {
DeleteValue(); DeleteValue();
} }

View File

@ -34,6 +34,8 @@
#pragma once #pragma once
#include <boost/noncopyable.hpp>
namespace agi { struct Color; } namespace agi { struct Color; }
class wxString; class wxString;
@ -49,7 +51,7 @@ enum VariableDataType {
class AssDialogueBlockOverride; class AssDialogueBlockOverride;
class VariableData { class VariableData : private boost::noncopyable {
private: private:
union { union {
void *value; void *value;
@ -68,6 +70,7 @@ protected:
public: public:
VariableData(); VariableData();
VariableData(VariableData&& o);
virtual ~VariableData(); virtual ~VariableData();
VariableDataType GetType() const { return type; } VariableDataType GetType() const { return type; }