Widget::WidgetsList SearchContainerForClass( Container::PtrConst container, const std::string& class_name ) { Widget::WidgetsList result; if( !container ) { return result; } for( const auto& child : container->GetChildren() ) { if( child->GetClass() == class_name ) { result.push_back( child ); } auto child_container = std::dynamic_pointer_cast<Container>( child ); if( child_container ) { auto child_result = SearchContainerForClass( child_container, class_name ); // Splice the 2 vectors. if( !child_result.empty() ) { result.reserve( child_result.size() ); result.insert( result.end(), child_result.begin(), child_result.end() ); } } } return result; }
Widget::Ptr SearchContainerForId( Container::PtrConst container, const std::string& id ) { if( !container ) { return Widget::Ptr(); } for( const auto& child : container->GetChildren() ) { if( child->GetId() == id ) { return child; } auto child_container = std::dynamic_pointer_cast<Container>( child ); if( child_container ) { auto widget = SearchContainerForId( child_container, id ); if( widget ) { return widget; } } } return Widget::Ptr(); }