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; }
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; } } }
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; }
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; }
/** * 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; }
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))); } } }
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(); }
/** * 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; }
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"); }
/** * 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] ); } } }
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); } } }
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(); }
/** * 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 ); }
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; }
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(); }
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; } }
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(); }
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; }
ArrayNode* handleArray(FuncArgsNode* expr_list) { ArrayNode* node = new ArrayNode(expr_list); node->setLocation(FileLocation(yylineno)); return node; }
void PrintASTVisitor::visit(ArrayNode& node) { std::cout << indent() << "ArrayNode: array size = " << node.type().arraySize() << "\n"; ++indent_; }
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; }