int main() { auto adam=Person::makePerson("Adam"); adam->print(std::cout); auto eve=Person::makePerson("Eve"); eve->print(std::cout); addson("Cain",adam, eve); addson("Abel",adam, eve); addson("Seth",adam, eve); adam->print(std::cout); eve->print(std::cout); // how to have Cain kill Abel? { auto abel=eve->findChild("Abel"); eve->killChild(abel); adam->killChild(abel); abel->print(std::cout); } eve->print(std::cout); // how can we kill Adam and Eve? { adam->killMe(); adam->print(std::cout); adam.reset(); } eve->print(std::cout); auto cain=eve->findChild("Cain"); if (cain) cain->print(std::cout); eve->killMe(); // avoid memory leak eve->print(std::cout); eve.reset(); }
/** string FXMLElement::getValueFromPath(string path); * * Added by cmicali * Purpose: get the value of the node referenced by the dot-path notation * example: * * <config> * <general> * <size>50</size> * <general> * </config> * * FXMLElement *n = fxml.ParseFile("abovefile.xml"); * // n is now a pointer to root node "config" * std::string s = n->getValueFromPath("general.size"); * // String s now is "50" */ std::string FXMLElement::getValueFromPath(std::string path) { int f = path.find(".",0); int o = 0; std::list<std::string> l; path = path + "."; while (f != std::string::npos) { std::string s = path.substr(o,f-o); if (s != "") l.push_back(s); o = f+1; f = path.find(".", o);; } std::list<std::string>::const_iterator iter; iter=l.begin(); if (iter != l.end()) { std::string s = (*iter); FXMLElement *n = findChild(this, s); iter++; if (!n) return ""; for (; iter != l.end(); iter++) { s = (*iter); n = findChild(n, s); if (!n) return ""; } return n->Value(); } return ""; }
void searchInString(char *str){ int i; char c; node *state = root; for (i = 0; str[i]; i++){ c = str[i]; while (state != root && findChild(state, c) == NULL) state = state->fall; state = findChild(state, c); if (state == NULL){ state = root; continue; } node *report = state; while (report != root){ if (report->isEnd){ tiled[i-report->length+1] = max(tiled[i-report->length+1], report->length); } report = report->fall; } } }
/** * Searches for the entry at the given the relative path to the given node. */ g_ramdisk_entry* g_ramdisk::findRelative(g_ramdisk_entry* node, const char* path) { char buf[G_RAMDISK_MAXIMUM_PATH_LENGTH]; uint32_t pathLen = g_string::length(path); g_memory::copy(buf, path, pathLen); buf[pathLen] = 0; g_ramdisk_entry* currentNode = node; while (g_string::length(buf) > 0) { int slashIndex = g_string::indexOf(buf, '/'); if (slashIndex >= 0) { // Set current node to next layer if (slashIndex > 0) { char childpath[G_RAMDISK_MAXIMUM_PATH_LENGTH]; g_memory::copy(childpath, buf, slashIndex); childpath[slashIndex] = 0; currentNode = findChild(currentNode, childpath); } // Cut off layer uint32_t len = g_string::length(buf) - (slashIndex + 1); g_memory::copy(buf, &buf[slashIndex + 1], len); buf[len] = 0; } else { // Reached the last node, find the child currentNode = findChild(currentNode, buf); break; } } return currentNode; }
void constructAhoCorasick(void){ int i; root->fall = root; push(root); while(queueIsNotEmpty) { node *curr = pop(); for (i = 0; i < CHILDNUM; i++){ node *child = curr->children[i]; while (child != NULL){ push(child); child = child->next; } } if (curr == root) continue; node *fall = curr->parent->fall; while (fall != root && findChild(fall, curr->c) == NULL) fall = fall->fall; curr->fall = findChild(fall, curr->c); if (curr->fall == NULL || curr->fall == curr) curr->fall = root; } }
boolean testCase(Trie trie, char *str, DeleteCase caseNum) { Node current = trie->dummy; boolean result = false; int i; switch(caseNum) { case case1: for(i = 0; i < strlen(str) - 1; i++) { current = findChild(current, str[i]); if(current->children > 1) return false; } result = !(current->children > 1); break; case case2: for(i = 0; i < strlen(str); i++) { current = findChild(current, str[i]); } result = (current->children >= 1); break; case case3: result = !testCase(trie, str, case2); break; } return result; }
List<Object *> Object::findChildren(const char *pattern) const { List<Object *> ret; auto pos = findChild(pattern, p.children.begin()); while(pos != p.children.end()) { ret.append(*pos); pos = findChild(pattern, ++pos); } return ret; }
void KMWRlpr::initPrinter(KMPrinter *p) { m_host->setText(p->option("host")); m_queue->setText(p->option("queue")); QListViewItem *item = findChild(m_view->firstChild(),m_host->text()); if (item) { item = findChild(item->firstChild(),m_queue->text()); if (item) { item->parent()->setOpen(true); m_view->setCurrentItem(item); m_view->ensureItemVisible(item); } } }
QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name) { const QObjectList &children = parent->children(); int i; for (i = 0; i < children.size(); ++i) { QObject* obj = children.at(i); if (!obj) return NULL; // Skip if the name doesn't match. if (!name.isNull() && obj->objectName() != name) continue; if ((typeName && obj->inherits(typeName)) || (meta && meta->cast(obj))) return obj; } for (i = 0; i < children.size(); ++i) { QObject* obj = findChild(children.at(i), typeName, meta, name); if (obj != NULL) return obj; } return NULL; }
void SceneGame::postUpdate(const float dt) { if (findChild("GC")->getComponent<GameController>()->isGameOver()) { jop::Engine::createScene<SceneStart>(); } }
QObject* LuaQObject::findChild(std::string name) { if(_object) { return findChild(_object, name); } return 0; }
Int CVTCDecoder::decUpdateStateAC(Int c) { Int err; Int x, y; Int nc; Int xc[3], yc[3]; err=0; /* loop through DC */ noteDetail("Updating state of AC bands...."); for (x = 0; x < mzte_codec.m_iDCWidth; ++x) for (y = 0; y < mzte_codec.m_iDCHeight; ++y) { if ((nc = findChild(x, y, xc, yc,c)) != 3) { noteError("DC band coefficient has %d children instead of 3.", nc); exit(-1); } updateCoeffAndDescState(xc[0], yc[0], c); updateCoeffAndDescState(xc[1], yc[1], c); updateCoeffAndDescState(xc[2], yc[2], c); } noteDetail("Completed updating state of AC bands."); return err; }
Node * HostFolder::addFolder(const std::string &name) { auto hostPath = mPath.join(name); auto winPath = platform::toWinApiString(hostPath.path()); auto child = findChild(name); if (child) { if (child->type() == NodeType::FolderNode) { return child; } return nullptr; } if (!checkPermission(Permissions::Write)) { return nullptr; } if (_wmkdir(winPath.c_str())) { return nullptr; } return registerFolder(hostPath, name); }
void Trie::addWord(string& word) { std::transform(word.begin(), word.end(), word.begin(), ::tolower); auto current = m_root; if ( word.length() == 0 ) { current->setWordMarker(); // an empty word return; } for ( size_t i = 0; i < word.length(); i++ ) { auto child = current->findChild(word[i]); if (child) { current = child; } else { auto tmp = new Node(); tmp->setContent(word[i]); current->appendChild(tmp); current = tmp; } if ( i == word.length() - 1 ) current->setWordMarker(); } }
Int CVTCDecoder::decIQuantizeAC(Int c) { Int err; Int x, y; Int nc; Int xc[3], yc[3]; err=0; /* loop through DC */ noteDetail("Inverse quantizing AC bands...."); for (x = 0; x < mzte_codec.m_iDCWidth; ++x) for (y = 0; y < mzte_codec.m_iDCHeight; ++y) { if ((nc = findChild(x, y, xc, yc,c)) != 3) { noteError("DC band coefficient has %d children instead of 3.", nc); exit(-1); } iQuantizeCoeffs(xc[0], yc[0],c); iQuantizeCoeffs(xc[1], yc[1],c); iQuantizeCoeffs(xc[2], yc[2],c); } noteDetail("Completed inverse quantizing of AC bands."); return err; }
static inline std::auto_ptr<Node> createNodeFromConfig(xmlNode *config, std::map<long,Node*> &nodeNumberMap) { long jtagID = readNumberAttribute(config, "jtagId"); Node::Type nodeType; if (!Node::getTypeFromJtagID(jtagID, nodeType)) { std::cerr << "Unknown jtagId 0x" << std::hex << jtagID << std::dec << '\n'; std::exit(1); } long numXLinks = 0; if (xmlNode *switchNode = findChild(config, "Switch")) { if (findAttribute(switchNode, "sLinks")) { numXLinks = readNumberAttribute(switchNode, "sLinks"); } } std::auto_ptr<Node> node(new Node(nodeType, numXLinks)); long nodeID = readNumberAttribute(config, "number"); nodeNumberMap.insert(std::make_pair(nodeID, node.get())); for (xmlNode *child = config->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE || strcmp("Processor", (char*)child->name) != 0) continue; node->addCore(createCoreFromConfig(child)); } return node; }
bool HostFolder::remove(const std::string &name) { auto hostPath = mPath.join(name); auto winPath = platform::toWinApiString(hostPath.path()); auto child = findChild(name); if (!child) { // File / Directory does not exist, nothing to do return true; } if (!checkPermission(Permissions::Write)) { return false; } auto removed = false; if (child->type() == NodeType::FileNode) { removed = !!DeleteFileW(winPath.c_str()); } else if (child->type() == NodeType::FolderNode) { removed = !!RemoveDirectoryW(winPath.c_str()); } if (removed) { mVirtual.deleteChild(child); } return removed; }
MPLogId LogMsgChildReceiverThread::addChildToManager(MPLogId pid, INode * childNode, bool isListener, bool connected) { CriticalBlock critBlock(tableOfChildrenCrit); aindex_t pos = findChild(childNode); if(pos != NotFound) { if(isListener) table.item(pos).queryLink()->sendFilterOwn(listener->getCompoundFilter()); else table.item(pos).queryLink()->sendFilterOwn(queryLogMsgManager()->getCompoundFilter()); return false; } MPLogId cid = ++nextId; ILogMsgLinkToChild * link = new CLogMsgLinkToChild(cid, pid, childNode, isListener, connected); if(!connected) link->connect(); if(isListener) { link->sendFilterOwn(listener->getCompoundFilter()); listener->addChildOwn(link); } else { link->sendFilterOwn(queryLogMsgManager()->getCompoundFilter()); queryLogMsgManager()->addChildOwn(link); } table.append(*new IdLinkToChildPair(cid, childNode, link, isListener)); return cid; }
void form::removeChild(control *c){ //doesn't dispose. int location = findChild(c); if(location==-1) return; for(int i = location; i <= children.size()-1; i++) children[i] = children[i+1]; children.pop_back(); }
/* 在文件系统中加载文件,文件大小写入size所指变量,返回bool值表示是否成功 */ bool loadFile(const char *path, uint32_t partitionFirstSector, uint32_t *size) { printString(" "); firstSector = partitionFirstSector; loadSector(firstSector + 2, superBlockBuffer); blockSize = (uint32_t) (1024 << superBlock->logBlockSize); sectorsPerBlock = blockSize / SECTOR_SIZE_512; if (superBlock->magic != EXT2_MAGIC_NUM) { printLine("incorrect ext2 magic number"); return false; } if (superBlock->revLevel < EXT2_DYNAMIC_REV) { printLine("reversion of this ext2 filesystem is too old"); return false; } if (blockSize > 0x10000) { printLine("block size is too large"); return false; } uint32_t targetInode = EXT2_INODE_ROOT; for (const char *nameEnd = path; *nameEnd != '\0';) { for (path = nameEnd; *path == '/'; ++path); for (nameEnd = path; *nameEnd != '/' && *nameEnd != '\0'; ++nameEnd); if (nameEnd == path) { break; } targetInode = findChild(targetInode, path, nameEnd - path); if (targetInode == EXT2_INODE_NULL) { printLine("can't find such file"); return false; } }; Ext2Inode inode = loadInode(targetInode); if ((inode.mode & EXT2_MODE_FT_MASK) != EXT2_MODE_FT_REG_FILE) { printLine("not a regular file"); return false; } else { printString("file found, size: "); printInt(inode.size); printString(" bytes ("); printStorageSize(inode.size); printLine(")"); } uint32_t blkCnt = inode.size / blockSize + (inode.size % blockSize != 0); for (uint32_t blockOffset = 0; blockOffset < blkCnt; ++blockOffset) { uint32_t block = getBlockIndex(&inode, blockOffset); if (!readFileSectorsToBuffer(lbaOfBlock(block), sectorsPerBlock)) { return false; } } *size = inode.size; return true; }
bool LogMsgChildReceiverThread::removeChildFromManager(MPLogId cid, bool disconnected) { CriticalBlock critBlock(tableOfChildrenCrit); aindex_t pos = findChild(cid); if(pos == NotFound) return false; doRemoveChildFromManager(pos, disconnected); return true; }
WordNode* WordNode::insertChild(string& nextCharacter){ if (!findChild(nextCharacter)) { m_map.insert(pair<string,WordNode>(nextCharacter, WordNode(nextCharacter))); return &(m_map.find(nextCharacter)->second); } return NULL; }
TrieNode* TrieNode::insertChild(std::string& nextCharacter) { if (!findChild(nextCharacter)) { __map.insert(std::pair<std::string, TrieNode>(nextCharacter, TrieNode(nextCharacter, __dataSize))); return &(__map.find(nextCharacter)->second); } return NULL; }
bool XmlNode::getSubNodeValue( const String &tag,float &value ) const { XmlNodeRef node = findChild( tag ); if (node) { node->getValue( value ); return true; } return false; }
void XmlNode::setSubNodeValue( const String &tag,float value ) { XmlNodeRef node = findChild( tag ); if (!node) { node = new XmlNode( tag ); addChild( node ); } node->setValue( value ); }
bool LogMsgChildReceiverThread::removeChildFromManager(INode const * node, bool disconnected) { StringBuffer buff; CriticalBlock critBlock(tableOfChildrenCrit); aindex_t pos = findChild(node); if(pos == NotFound) return false; doRemoveChildFromManager(pos, disconnected); return true; }
// Removing a child and its children void BoneVertex::removeChild(const char *zeName) { BoneVertex *tmp = findChild(zeName); if (tmp == NULL) return; if (tmp == this) return; childList.removeElement(tmp); childListCompiled = 0; delete tmp; }
void SceneNode::removeChild(StringHash nameHash, bool purge) { SceneNode* child = findChild(nameHash); if (!child) return; childrenNode_.erase(nameHash); if (purge) delete child; }
ConfigNode *ConfigNode::addChild(const std::string &name, bool replaceExisting) { if (replaceExisting) { ConfigNode *node = findChild(name, false); if (node) { return node; } } return new ConfigNode(this, name); }
/* * Trie deletion has 3 cases * * Case 1: The word is a separate branch in the tree and it doesn't have * any other children. Simply delete the starting node. * Case 2: The word contains suffices. Only remove the "word" marker * Case 3: The reverse of Case 2. The word is a suffix. Delete only the * suffix * * This only replaces the deleted node with NULL and then calling the * sortChild() function and then realloc() * * realloc() only fails if size == 0 or if the block cannot be reallocated */ void deleteWord(Trie trie, char *str) { Node current = trie->dummy, temp = NULL; int i, tmp; if(!searchWord(trie, str)) return; /* Test for case 1*/ if(testCase(trie, str, case1)) { /* Simply remove the node */ i = findChildID(current, str[0]); nodeDelete(current->child[i]); resizeChildren(current); } else if(testCase(trie, str, case2)) { /* Test for case 2 */ /* No real deletion occurs here, the nodes would * still be there, but it makes the word unsearchable */ for(i = 0; i < strlen(str); i++) { current = findChild(current, str[i]); } current->endMarker = false; } else if(testCase(trie, str, case3)) { /* Test for case 3 */ /* Traverse the word and keep track on which node * had children > 1, then find the next matching node * and delete it */ temp = trie->dummy; for(i = 0; i < strlen(str); i++) { temp = findChild(temp, str[i]); if(temp->children > 1) { current = temp; tmp = i+1; } } i = findChildID(current, str[tmp]); nodeDelete(current->child[i]); resizeChildren(current); } }