Children mainParse(I& be, I& en, Pos& pos) { Children ret; while(be != en) { eatWhitespaceComment(be, en, pos); if(test(be, en, "<{{")) { ret.push_back(std::move(parseC(be, en, pos))); } else if(test(be, en, '<')) { ret.push_back(std::move(parseNode(be, en, pos))); } else if(test(be, en, '>')) { eat(be, '>', pos); break; } else { I iter; TNodeType type; if(!test(be, en, "&{{") && *be == '&') { iter = eatUntil(be, en, "\n", pos); /*for(iter = be; !test(iter, en, '\n') && !test(iter, en, "//"); increment(iter, pos)) { } if(test(be, en, "//")) { eatWhitespaceComment(be, en, pos); }*/ type = TNodeType::SingleCppLine; } else { iter = eatUntil(be, en, "\n>", pos); for(iter = be; !test(iter, en, '\n') && !test(iter, en, "//") && !test(iter, en, '>'); increment(iter, pos)) { } if(test(be, en, "//")) { eatWhitespaceComment(be, en, pos); } type = TNodeType::Text; } auto posCopy = pos; //std::cout<<"||| "<<std::string(be, iter)<<std::endl; ret.push_back( std::make_unique<TNode>(std::string(be, iter), posCopy, type ) ); be = iter; char iterC = *iter; eat(be, iterC, pos); if(iterC == '>') { break; } } eatWhitespaceComment(be, en, pos); } return ret; }
void GeoRSSLayer::_read ( const std::string &filename, Usul::Interfaces::IUnknown *caller, Usul::Interfaces::IUnknown *progress ) { // Make sure the file exists before reading. if ( false == boost::filesystem::exists ( filename ) ) return; // Set the name. if ( true == this->name().empty() ) this->name ( this->url() ); // Scope the reading flag. Usul::Scope::Caller::RefPtr scope ( Usul::Scope::makeCaller ( boost::bind ( &GeoRSSLayer::reading, this, true ), boost::bind ( &GeoRSSLayer::reading, this, false ) ) ); // TODO: I think a SAX parser is more appropraite here, because we can stop the parsing if there isn't new data. XmlTree::Document::RefPtr doc ( new XmlTree::Document ); doc->load ( filename ); // Get the date the stream was modified. Children lastPubDateNode ( doc->find ( "lastBuildDate", true ) ); const std::string date ( false == lastPubDateNode.empty() ? lastPubDateNode.front()->value() : "" ); boost::posix_time::ptime utcTime ( Minerva::Core::Data::Date::createFromRSS ( date ) ); boost::posix_time::ptime lastDataUpdate ( Usul::Threads::Safe::get ( this->mutex(), _lastDataUpdate ) ); std::cout << "Last data update: " << lastDataUpdate << std::endl; std::cout << "Last feed update: " << utcTime << std::endl; // Check the date against the time time we updated. if ( false == this->dirtyData() && false == lastDataUpdate.is_not_a_date_time() && false == utcTime.is_not_a_date_time() ) { // Return now if the feed has not been updated. if ( lastDataUpdate >= utcTime ) { // Our data doesn't need to be updated. this->dirtyData ( false ); return; } } // Clear what we have. this->clear(); unsigned int i ( 0 ); // Get all the items. Children children ( doc->find ( "item", true ) ); BOOST_FOREACH ( XmlTree::Node::ValidRefPtr node, children ) { std::cout << "Adding item " << ++i << " of " << children.size() << std::endl; this->_parseItem( *node ); if ( this->size() >= this->maximumItems() ) break; }
void Panel::Clear() { // Clear children Children aspChildren = m_aspChildren; for ( Children::reverse_iterator it = aspChildren.rbegin(); it != aspChildren.rend(); ++it ) { GuiObjectPtr spChild = *it; spChild->Clear(); RemoveChild( spChild ); } GuiObject::Clear(); }
void BrowsingContext::Detach(bool aFromIPC) { MOZ_LOG(GetLog(), LogLevel::Debug, ("%s: Detaching 0x%08" PRIx64 " from 0x%08" PRIx64, XRE_IsParentProcess() ? "Parent" : "Child", Id(), mParent ? mParent->Id() : 0)); RefPtr<BrowsingContext> kungFuDeathGrip(this); BrowsingContextMap<RefPtr>::Ptr p; if (sCachedBrowsingContexts && (p = sCachedBrowsingContexts->lookup(Id()))) { MOZ_DIAGNOSTIC_ASSERT(!mParent || !mParent->mChildren.Contains(this)); MOZ_DIAGNOSTIC_ASSERT(!mGroup || !mGroup->Toplevels().Contains(this)); sCachedBrowsingContexts->remove(p); } else { Children* children = nullptr; if (mParent) { children = &mParent->mChildren; } else if (mGroup) { children = &mGroup->Toplevels(); } if (children) { // TODO(farre): This assert looks extremely fishy, I know, but // what we're actually saying is this: if we're detaching, but our // parent doesn't have any children, it is because we're being // detached by the cycle collector destroying docshells out of // order. MOZ_DIAGNOSTIC_ASSERT(children->IsEmpty() || children->Contains(this)); children->RemoveElement(this); } } if (mGroup) { mGroup->Unregister(this); } // As our nsDocShell is going away, this should implicitly mark us as closed. // We directly set our member, rather than using a transaction as we're going // to send a `Detach` message to other processes either way. mClosed = true; if (!aFromIPC && XRE_IsContentProcess()) { auto cc = ContentChild::GetSingleton(); MOZ_DIAGNOSTIC_ASSERT(cc); cc->SendDetachBrowsingContext(this, false /* aMoveToBFCache */); } }
void findAllUnresolvedSymbols(std::vector<ParseItem>* pItems) const { // Get the unresolved symbols at this node std::set<ParseItem> unresolved = getUnresolvedSymbols(); pItems->insert(pItems->end(), unresolved.begin(), unresolved.end()); // Apply this over all children on the node Children children = getChildren(); for (Children::iterator it = children.begin(); it != children.end(); ++it) { (**it).findAllUnresolvedSymbols(pItems); } }
void InstanceArray::bindToMasterView(const ViewSharedPtr& inMaster, bool inMapPortReferences) throw (Error) { typedef std::vector<InstanceSharedPtr> Children; Children children; getChildren(children); Children::iterator child = children.begin(); Children::iterator cEnd = children.end(); for(; child != cEnd; ++child) { try { (*child)->bindToMasterView(inMaster); } catch(Error& e) { e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__); throw; } } Instance::bindToMasterView(inMaster, false); }
void FontSizeComboBox::setActiveFontSize(int value) { if (value == 0) { unset_active(); return; } typedef Gtk::TreeModel::Children Children; Children children = font_size_tree_model_->children(); for (Children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; if (row[columns_.font_size] == value) { set_active (iter); break; } } }
void cHandler::GetChildren( Children& children ) const { cObject::GetChildren( children ); Resources::const_iterator iter = m_resources.begin(); Resources::const_iterator end = m_resources.end(); for ( ; iter != end; ++iter ) { cResource * r = iter->second; children.push_back( r ); } }
inline status wait_children(Children &cs) { BOOST_ASSERT(cs.size() >= 2); typename Children::iterator it = cs.begin(); while (it != cs.end()) { const status s = it->wait(); ++it; if (it == cs.end()) return s; else if (!s.exited() || s.exit_status() != EXIT_SUCCESS) { while (it != cs.end()) { it->wait(); ++it; } return s; } } BOOST_ASSERT(false); return cs.begin()->wait(); }
int main () { Component* composite1 = new Composite(); composite1->add( GET("LeafA") ); composite1->add( GET("LeafA") ); Component* composite2 = new Composite(); composite2->add( GET("LeafB") ); composite2->add( GET("LeafA") ); composite2->add( composite1 ); composite2->draw(10); Children* children = composite2->getChildren(); std::cout << std::endl; int i = 11; for(typename Children::iterator it = children->begin(); it != children->end(); ++it) { (*it)->draw(i); i += 11; } return 0; }
void Panel::RemoveAllChildren() { Children aspChildren = m_aspChildren; for ( Children::iterator it = aspChildren.begin(); it != aspChildren.end(); ++it ) { GuiObjectPtr spChild = *it; DeinitChild( spChild ); } m_aspChildren.clear(); if ( GetSizeModeX() == SIZE_MODE_CONTENT || GetSizeModeY() == SIZE_MODE_CONTENT ) { UpdateSize(); } // Dispatch events for ( Children::iterator it = aspChildren.begin(); it != aspChildren.end(); ++it ) { GuiObjectPtr spChild = *it; DispatchEvent( EVENT_PANEL_CHILD_REMOVED, GetSharedPtr< Panel >(), spChild ); DispatchEvent( EVENT_PANEL_CHILDREN_CHANGED, GetSharedPtr< Panel >(), spChild ); } }
void Entity::onObjectLoaded() { __super::onObjectLoaded(); if ( m_parent ) { onAttached( *m_parent ); } // copy the managed children to the runtime children array unsigned int count = m_managedChildren.size(); m_children.resize( count ); for( unsigned int i = 0; i < count; ++i ) { m_children[i] = m_managedChildren[i]; } // inform that the children have been attached Children children = m_children; for ( Children::iterator it = children.begin(); it != children.end(); ++it ) { onChildAttached( **it ); } }
size_t outdegree() const { return children.size(); }
void finaleWidgetBeingDeleted(FinaleWidget const &widget) { DENG2_ASSERT(children.contains(&const_cast<FinaleWidget &>(widget))); children.removeOne(&const_cast<FinaleWidget &>(widget)); }
~Impl() { qDeleteAll(children); DENG2_ASSERT(children.isEmpty()); }
int _tmain(int argc, _TCHAR* argv[]) { //知识点:注意区分指针类型(编译时确定)和对象类型(运行时确定). 总之,非虚方法是根据指针类型来调用,虚方法是根据对象类型来调用 //指针类型(CBase) 对象类型(CDerived()) //CBase *pBase = new CDerived(); CBase base; cout << "sizeof(base):" << sizeof(base) << endl; // 4 cout << sizeof(long long) << endl; //base.Test(); CDerived derived; cout << "sizeof(derived):" << sizeof(derived) << endl; derived.name(); derived.derived_print(); CBase* p = &derived; //隐式向上强制转换 //当一个derived class object被交出去当作一个base class object时, //它原本所以“成为一个derived class object”的所有特征,都会被切除(slicing)掉,只留下内部一个base class object。 //以by reference的方式传递参数,有另一个优点:可避免所谓的“切割(slicing)问题”。引用是除指针外另一个可以产生多态效果的手段。 Test1(derived);//Output from CBase! 出现切割 Test2(derived);//Output from CDerived! Test3(p); //Output from CDerived! cout << "打印指针自身内存地址:" << &p << endl; cout << "打印指针指向内存地址:" << (int *)p << endl; p->show(); //p->range();//编译错误.“range”: 不是“CBase”的成员 CDerived* derived2 = (CDerived *)&base; //显式向下强制转换 derived2->range();//调用派生类独有的方法,不安全操作(如果方法内有访问CDerived独有的成员变量,用到this指针就会出问题) CDerived* derived3 = dynamic_cast<CDerived*>(&base);//用dynamic_cast来转换类型可以检查转换是否安全成功,失败返回空指针 if (derived3) { cout<< "derived3 dynamic_cast successful !!" <<endl; derived3->range(); } else { cout<< "derived3 dynamic_cast failed !!" <<endl; } CDerived* derived4 = dynamic_cast<CDerived*>(p); if (derived4) { cout<< "derived4 dynamic_cast successful !!" <<endl; derived4->range(); } else { cout<< "derived4 dynamic_cast failed !!" <<endl; } derived2->Test();//Output from CBase (根据对象类型来判断) CBase *pBase = new CDerived(); /*虚析构: 如果一个类用作基类,我们通常需要virtual来修饰它的析构函数,这点很重要。 如果基类的析构函数不是虚析构,当我们用delete来释放基类指针(它其实指向的是派生类的对象实例)占用的内存的时候, 只有基类的析构函数被调用,而派生类的析构函数不会被调用,这就可能引起内存泄露。如果基类的析构函数是虚析构, 那么在delete基类指针时,继承树上的析构函数会被自低向上依次调用,即最底层派生类的析构函数会被首先调用, 然后一层一层向上直到该指针声明的类型。*/ delete pBase; Person *person = new Person(); person->showAge(); person->show1(); printf("%d\n", Person::date); Children *children = new Children(); printf("%d\n", Children::date); children->show1(); Person *person1 = children; //show2()没有使用virtual关键字,程序将根据引用或者指针类型选择方法。忠告:绝对不要重新定义继承而来的非虚拟函数 person1->show2(); //Person::show2() Children* children2 = (Children*)person;//显式向下强制转换 children2->show2(); //Children::show2() 发现转型之后还是可以调用Children的函数的,因为编译的时函数内存地址已经确定,如果函数里面需要用到this指针调用到成员变量就不安全 Person *person2 = new Children(); //person2->show4(); person2并不能调用show4(),只能调用Person类方法; person2->hide(); //children->hide(); //Person的hide()函数给隐藏了,不能调用 children->hide(1); //子类在外部调用父类方法!!!!好奇怪的语法 Children child; child.Person::show2(); Children *pChild = new Children(); pChild->Person::show2(); //测试覆盖 person1->testOverride(10); person2->testOverride(10); children->testOverride(10); system("Pause"); return 0; }
inline void add_child (int c) { child.push_back (c); }
void start() { std::ofstream pidfile(SC_PID); if (!pidfile.good()) { std::cerr << "cannot open PID file " << SC_PID << ": " << strerror(errno) << std::endl; exit(errno); } pidfile << getpid() << std::endl; pidfile.close(); std::ofstream log; log.open(SC_LOG, std::ofstream::app); log << "\n" << logPrefix() << "starting shoutcast daemon" << std::endl; log << logPrefix() << "reading shoutcast configuration files from " << SC_CONFIG << std::endl; log.close(); // Enumerate config files in shoutcast config dir. DIR *dir; struct dirent *ent; dir = opendir (SC_CONFIG); if (dir == NULL) { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "cannot read scd configuration direcoty " << SC_CONFIG << ": " << strerror(errno) << std::endl; log.close(); exit(errno); } for (; ent = readdir(dir); ent != NULL) { std::string cfgfile = ent->d_name; if (cfgfile == "." || cfgfile == "..") { continue; } std::string cfgpath = SC_CONFIG; cfgpath += "/"; cfgpath += cfgfile; Child c; c.pid = 0; c.config = cfgpath; size_t idx = cfgfile.find("."); c.log = SC_LOGDIR"sc_stream_"; c.log += cfgfile.substr(0, idx); c.log += ".log"; g_children.push_back(c); log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "found shoutcast configuration: " << cfgpath << std::endl; log.close(); } closedir(dir); // Start respawn loop. while (g_running) { // Respawn all children with zero pid. for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) { if (i->pid == 0) { i->pid = fork(); if (i->pid == 0) { // Open log file and redirect stdout, stderr. FILE *f = fopen(i->log.c_str(), "a"); int r1 = dup2(fileno(f), 1); int r2 = dup2(fileno(f), 2); fclose(f); // Start child process. std::cout << timeStr() << "[" << getpid() << "] started" << std::endl; if (execl(SC_EXEC, SC_EXEC, i->config.c_str(), (char*)0) < 0) { exit(1); } } else { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "spawned server for config " << i->config << ", server pid is [" << i->pid << "]" << std::endl; log.close(); } } } // Wait for any failed children. int status; pid_t pid = wait(&status); if (!g_running) break; // Mark a failed child to restart. for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) { if (i->pid == pid) { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "server with pid [" << pid << "] (" << i->config << ") failed with status " << status << std::endl; log.close(); i->pid = 0; break; } } } log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "terminated" << "\n" << std::endl; log.close(); }