/*
 * SenchaObject.cpp
 *
 *  Created on: Dec 5, 2012
 *      Author: attero
 */

#include "SenchaObject.h"

SenchaObject::SenchaObject() {
	set_null_value();
}

SenchaObject::~SenchaObject() {
	// TODO Auto-generated destructor stub
}


std::string SenchaObject::repr()
{
	std::string representation = "";
	switch(type){
	case string_literal:
			representation = "type: string\n";
			representation += this->text;
			break;
	case integer_number:
			representation = "type: integer\n";
			representation += to_string(this->integer);
			break;
	case float_number:
			representation = "type: float\n";
			representation += to_string(this->number);
			break;
	case null:
			representation = "type: null\n";
			representation += "null";
			break;
	case symbol:
			representation = "type: symbol\n";
			representation += this->text;
			break;
	case invalid:
			representation = "type: invalid\n";
			representation += "some crap";
			break;
	}
	return representation;
}

SenchaObject SenchaObject::operator+(const SenchaObject& right)const
{
	SenchaObject result;
	if(type == right.type)
	{
		switch(type){
		case string_literal:
			result.set_new_string(this->text + right.text);
			break;
		case integer_number:
			result.set_value(this->integer + right.integer);
			break;
		case float_number:
			result.set_value(this->number + right.number);
			break;
		}
	}
	else
	{
		result.type = invalid;
	}

	return result;

}

SenchaObject SenchaObject::operator-(const SenchaObject& right)const
{
	SenchaObject result;
		if(type == right.type)
		{
			switch(type){
			case string_literal:
				result.type = invalid;
				break;
			case integer_number:
				result.set_value(this->integer - right.integer);
				break;
			case float_number:
				result.set_value(this->number - right.number);
				break;
			}
		}
		else
		{
			result.type = invalid;
		}

		return result;
}

SenchaObject SenchaObject::operator*(const SenchaObject& right)const
{
	SenchaObject result;
			if(type == right.type)
			{
				switch(type){
				case string_literal:
					result.type = invalid;
					break;
				case integer_number:
					result.set_value(this->integer * right.integer);
					break;
				case float_number:
					result.set_value(this->number * right.number);
					break;
				}
			}
			else
			{
				result.type = invalid;
			}

			return result;
}

SenchaObject SenchaObject::operator/(const SenchaObject& right)const
{
	SenchaObject result;
			if(type == right.type)
			{
				switch(type){
				case string_literal:
					result.type = invalid;
					break;
				case integer_number:
					result.set_value(this->integer / right.integer);
					break;
				case float_number:
					result.set_value(this->number / right.number);
					break;
				}
			}
			else
			{
				result.type = invalid;
			}

			return result;
}

//TODO change code above to something more generic
