Пример #1
0
CTECList<Type>::~CTECList()
{

	 // Start at head
	 // Loop over nodes
	 // update position
	 // Delete Final
	 //Assign default

	ArrayNode<Type>* current = head;

	while (current->getNext() != nullptr)
	{
		ArrayNode<Type>* temp = current;

		current = current->getNext();
		head = current;
		delete temp;
	}

	delete head;
	head = nullptr;
	end = nullptr;
	size = 0;
}
Пример #2
0
CTECArray<Type>::CTECArray(int size)
{
    this->size = size;
    head = nullptr;

    if(size <= 0)
    {
        cerr << "Impossible!" << endl;
        return;
    }

    for(int index = 0; index < size; index++)
    {
        if(head != nullptr)
        {   //we have more than one arraynode.
            ArrayNode<Type> nextNode;
            nextNode.setNext(head);
            head = &nextNode;
        }
        else
        {
            //this is the first node in the array.
            ArrayNode &temp;
            head = &temp;
        }
    }
}
Пример #3
0
int CTECArray<Type>::nextIndexOf(int startingIndex, Type searchValue)
{
	assert(this->size > 0);
	assert(startingIndex >= 0 && startingIndex < this->size);

	int indexNotFound = -1;

	ArrayNode<Type>* current = head;
	for(int index = 0; index < startingIndex; index++)
	{
		current = current->getNext();
	}

	for(int index = startingIndex; index < this->size; index++)
	{
		if(current->getValue == searchValue)
		{
			return index;
		}
		else
		{
			current = current->getNext();
		}
	}
	return indexNotFound;
}
Пример #4
0
Type CTECList<Type>::removeEnd()
{

	assert(size > 0);

	ArrayNode<Type>* previous;
	ArrayNode<Type>* toDelete;
	ArrayNode<Type>* current = head;
	Type thing;

	if (current->getNext() == nullptr)
	{
		toDelete = current;
		thing = toDelete->getValue();
		delete toDelete;
		end = nullptr;
	}
	else
	{
		while(current->getNext() != nullptr)
		{
			previous = current;
			current = current->getNext();
		}
		toDelete = current;
		thing = toDelete->getValue();
		delete toDelete;
		previous->setNext() = nullptr;
		end = previous;
	}

	this->calculateSize();
	return thing;
}
Пример #5
0
/**
 * Save the loaded files (build settings tree).
 *
 * @return A settings tree
 */
ArrayNode* Preferences::storeLoadedFiles() {
	ArrayNode* loadedFilesNode = new ArrayNode();
	
	for( deque<FileSession*>::iterator it = loadedFiles.begin(); it != loadedFiles.end(); it++ ) {
		if( *it != NULL ) {
			loadedFilesNode->addChild( storeFile( (*it)->filename, (*it)->session ) );
		}
	}
		
	return loadedFilesNode;
}
Пример #6
0
 FnCallNode::FnCallNode(std::vector<Node*> v)
 {
   // v[0] : function name
   // v[1] : function args
   this->name_ = v[0]->str();
   if (1 < v.size()) {
     ArrayNode* args = (ArrayNode*)v[1];
     for (size_t i = 0; i < args->size(); ++i) {
       this->args_.push_back((ExpNode*)(args->nth(i)));
     }
   }
 }
Пример #7
0
Type CTECList<Type>::getAtIndex(int index)
{
	assert(index > size || index < 0);
	ArrayNode<Type>* current = head;

	for (int i = 0; i < index - 1; i++)
	{
		current = current->getNext();
	}

	return current->getValue();
}
Пример #8
0
/**
 * Transform a XML node to a ArrayNode.
 *
 * @param xmlElement	XML element.
 *
 * @return				A ArrayNode.
 */
ArrayNode* XmlSettingsTree::xmlToArrayNode( TiXmlElement* xmlElement ) {
	ArrayNode* retNode = new ArrayNode();
	
	TiXmlHandle		handler( xmlElement );
	TiXmlElement* 	child = handler.FirstChild().Element();
			
	//< @todo what if child is null?
	for( child; child; child = child->NextSiblingElement() ) {
		SettingsNode* tmp = xmlToSettingsTree( child );
		retNode->addChild( tmp );
	}
	
	return retNode;
}
Пример #9
0
void
XmlRenderer::renderNode(const ArrayNode& node)
{
  StringBuffer attrs;

  if (fShowNodeType && node.type().isDef()) {
    attrs << " ty='" << xmlEncode(node.type().typeId()) << "'";
    fReferencedTypes.insert(std::make_pair(node.type().typeId(),
                                           node.type()));
  }

  displayOpenTagAttrs("array", StrHelper(attrs.toString()));
  displayNodeList(nullptr, node.children());
  displayCloseTag("array");
}
Пример #10
0
/**
 * Load settings for all files
 *
 * @param node 		Node representing a settings tree.
 */
Void Preferences::loadLoadedFiles( ArrayNode& node ) {
	for( Int i = 0; i < node.countChildren(); i++ ) {
		if( node[i].getType() == SETTINGS_TREE_DICTIONARY ) {
			loadFile( (DictionaryNode&) node[i] );
		}
	}
}
Пример #11
0
void CTECArray<Type>::set(int position,const Type& value)
{
	assert(position < size && position >= 0);
	ArrayNode<Type> *current = head;
	for (int spot = 0; spot <= position; spot++)
	{
		if (spot != position)
		{
			current = current->getNext();
		}
		else
		{
			current->setValue(value);
		}
	}

}
Пример #12
0
void CTECList<Type>::addToFront(const Type& value)
{
	ArrayNode<Type>* newNode = new ArrayNode<Type>(value);

	if (head == nullptr)
	{
		newNode->setNext(nullptr);
		head = newNode;
		end = newNode;
	}
	else
	{
		newNode->setNext(head);
		head = newNode;
	}
	calculateSize();
}
Пример #13
0
/**
 * Transform a ArrayNode to a XML node.
 *
 * @param node		A settings tree node representing an array node.
 * @param parent	The parent node of the XML document.
 */
Void XmlSettingsTree::settingsTreeToXml( ArrayNode& node, TiXmlNode& parent ) {
	TiXmlElement* element = new TiXmlElement( XMLSETTINGSTREE_ARRAY_ELEMENT );
	
	for( Int i = 0; i < node.countChildren(); i++ ) {
		settingsTreeToXml( node[i], *element);
	}

	parent.LinkEndChild( element );
}
Пример #14
0
int CTECArray<Type>::indexOf(Type searchValue)
{
	assert(this->size > 0);

	int indexNotFound = -1;

	ArrayNode<Type>* current = head;

	for(int index = 0; index < this->size; index++)
	{
		if(current->getValue() == searchValue)
		{
			return index;
		}
		else
		{
			current = current->getNext();
		}
	}
	return indexNotFound;
}
Пример #15
0
void CTECList<Type>::addAtIndex(int index, const Type& value)
{
	ArrayNode<Type>* newNode = new ArrayNode<Type>(value);
	ArrayNode<Type>* current = head;
	ArrayNode<Type>* previous = current;

	assert(index <= size && index >= 0);

	if (index == 0)
	{
		addFront(value);
	}
	else if(index == size)
	{
		addEnd(value);
	}
	else
	{
		for(int i = 0; i < index; i++)
		{
			previous = current;
			current = current->getNext();
		}
		previous->setNext(newNode);
		newNode->setNext(current);
	}

	calculateSize();
}
Пример #16
0
void CTECList<Type>::calculateSize()
{
	assert(size >= 0);

	ArrayNode<Type>* counterPointer = head;
	int count = 0;

	if (counterPointer == nullptr)
	{
		this->size = 0;
		return;
	}
	else
	{
		count++;
		while(counterPointer->getNext() != nullptr)
		{
			counterPointer = counterPointer->getNext();
			count++;
		}

		this->size = count;
	}
}
Пример #17
0
void CTECList<Type>::addToEnd(const Type& value)
{
	ArrayNode<Type>* newNode = new ArrayNode<Type>(value);
	ArrayNode<Type>* current = head;

	if (current->getNext() == nullptr)
	{
		current->setNext(newNode);
		newNode->setNext(nullptr);
		end = newNode;
	}
	else
	{
		while(current->getNext() != nullptr)
		{
			current = current->getNext();
		}
		current->setNext(newNode);
		newNode->setNext(nullptr);
		end = newNode;
	}
	calculateSize();
}
Пример #18
0
Type CTECList<Type>::removeAtIndex(int index)
{
	ArrayNode<Type>* previous;
	ArrayNode<Type>* toDelete;
	ArrayNode<Type>* newNext;
	ArrayNode<Type>* current = head;
	Type thing;

	assert(this->size > 0);
	assert(index > 0 || index <= size);

	if (index == 0)
	{
		thing = removeFront();
	}
	else if (index == size - 1)
	{
		thing = removeEnd();
	}
	else
	{

		for (int i = 0; i < index; i++)
		{
			if (i == index - 1)
			{
				previous = current;
			}
			else if (i == index)
			{
				toDelete = current;
				thing = toDelete->getValue();
				newNext = current->getNext();
				delete toDelete;
				previous->setNext(newNext);
			}
			current = current->next();
		}
	}

	this->calculateSize();
	return thing;
}
Пример #19
0
ArrayNode* handleArray(FuncArgsNode* expr_list)
{
    ArrayNode* node = new ArrayNode(expr_list);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #20
0
void PrintASTVisitor::visit(ArrayNode& node)
{
    std::cout << indent() << "ArrayNode: array size = " << node.type().arraySize() << "\n";
    ++indent_;
}
Пример #21
0
TreeNode *GenericParser::value_sequence()
{
    if (m_token->type() == START_DICT) {
        match(START_DICT);
        MapNode *map = new MapNode;

        while (m_scanner->good() && m_token && m_token->type() != END_DICT) {
            string name = m_token->value();
            match(NAME);
            TreeNode *value = value_sequence();
            NameNode *n = dynamic_cast<NameNode *>(value);
            if (n && n->name()[0] != '/') {
                value = value_sequence();
            }
            map->push(name, value);
        }
        match(END_DICT);
        return map;
    } else if (m_token->type() == TRUE) {
        match(TRUE);
        return new BooleanNode(true);
    } else if (m_token->type() == FALSE) {
        match(FALSE);
        return new BooleanNode(false);
    } else if (m_token->type() == NAME) {
        string name = m_token->value();
        match(NAME);
        return new NameNode(name);
    } else if (m_token->type() == STRING) {
        string value = m_token->value();
        match(STRING);
        return new StringNode(value);
    } else if (m_token->type() == NUM) {
        double value = m_token->to_number();
        int pos = m_scanner->pos();
        match(NUM);

        if (m_token->type() == NUM) {
            double generation = m_token->to_number();
            match(NUM);
            if (m_token->type() == NAME && m_token->value() == "R") {
                match(NAME);
                return new RefNode(value, generation);
            } else {
                m_scanner->to_pos(pos);
            }
        } else {
            m_scanner->to_pos(pos);
        }
        next_token();
        return new NumberNode(value);
    } else if (m_token->type() == START_ARRAY) {
        ArrayNode *array = new ArrayNode;
        match(START_ARRAY);
        while (m_scanner->good() && m_token->type() != END_ARRAY) {
            array->push(value_sequence());
        }
        match(END_ARRAY);
        return array;
    }
    return NULL;
}