Commits

Igor Baidiuk committed 81bcf21

Implemented assignment and copy constructor for Variant

Comments (0)

Files changed (1)

src/common/Variant.cpp

 	};
 
 	typedef RefArray<char>    RefString;
+	typedef RefArray<Variant> RefTuple;
 
 	extern StringMap<Type, TYPE_MAX_ENUM> types;
 
 			data.table.pairs[i] = table[i];
 	}
 
+	Variant::Variant(const Variant& other)
+		: type(UNKNOWN)
+	{
+		*this = other;
+	}
+
+	Variant& Variant::operator = (const Variant& other)
+	{
+		Variant::~Variant();
+		type = other.type;
+		switch (type)
+		{
+		case BOOLEAN:
+			data.boolean = other.data.boolean;
+			break;
+		case NUMBER:
+			data.number = other.data.number;
+			break;
+		case CHARACTER:
+			data.character = other.data.character;
+			break;
+		case STRING:
+			if (data.string = other.data.string)
+				((RefString*)data.string)->retain();
+			break;
+		case LUSERDATA:
+			data.light = other.data.light;
+			break;
+		case FUSERDATA:
+			data.full = other.data.full;
+			flags = other.flags;
+			if (data.full.type != INVALID_ID)
+				((love::Object*)data.full.data)->retain();
+			break;
+		case TUPLE:
+			break;
+		case TABLE:
+			break;
+		}
+	}
+
 	Variant::~Variant()
 	{
 		switch(type)
 				if (data.table.pairs)
 					delete[] data.table.pairs;
 				break;
-			default:
-				break;
 		}
 	}