/*
 * SenchaArray.cpp
 *
 *  Created on: Jan 10, 2013
 *      Author: att
 */

#include "SenchaArray.h"



SenchaArray::SenchaArray(std::string name, ContextManager * context_manager) {
	// TODO Auto-generated constructor stub
	max_index = 0;
	this->context_manager = context_manager;
	this->name = name;
	context_manager->get_top()->add(name, SenchaObject());
}

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


SenchaArray::SenchaArray(std::string name, ContextManager * context_manager, std::string text)
{
	max_index = 0;
	this->context_manager = context_manager;
	this->name = name;
	for(unsigned int i = 0; i < text.size(); i++)
	{
		SenchaObject temp;
		std::string letter_string = text.substr(i, 1) ;
		temp.text = letter_string;
		temp.type = SenchaObject::string_literal;
		context_manager->get_top()->add("_" + name+ "_" + to_string(i), temp);
	}
	max_index = text.size();
	//context->add(name, SenchaObject(text));
}

SenchaObject SenchaArray::get(IndexNumber index)
{
	SenchaObject result =  context_manager->get_top()->get("_" + name +"_"  +to_string(index));
	result.name = "_" + name + "_"  + to_string(index);
	return result;
 //return objects[index];
}

SenchaArray::IndexNumber SenchaArray::add(SenchaObject value)
{
	context_manager->get_top()->add("_" + name+ "_" + to_string(max_index), value);
	max_index++;

	return max_index;
}

void SenchaArray::set(IndexNumber index, SenchaObject value)
{
	//objects[index] = value;
	context_manager->get_top()->add("_" + name +"_" +to_string(index), value);
}
