int main(){ std::vector<int> v1 = {1,2,3,4,5,6,7,8,9}; std::list<int> l1, l2, l3; copy(v1.begin(), v1.end(), front_inserter(l1)); for(auto c : l1) std::cout << c << " "; std::cout << std::endl; copy(v1.begin(), v1.end(), back_inserter(l2)); for(auto c : l2) std::cout << c << " "; std::cout << std::endl; copy(v1.begin(), v1.end(), inserter(l3, l3.end())); for(auto c : l3) std::cout << c << " "; std::cout << std::endl; }
int main() { std::list<int> lst1; std::deque<int> deq1; std::vector<int> ivec1; std::vector<int> ivec {1,3,5,1,2,6,4,8,6,12}; auto vitb = back_inserter(ivec1); // back_inserter on vector for(auto &vel : ivec) *vitb = vel; std::cout << "After using back_inserter() on ivec1:\n"; for(auto &elem : ivec1) std::cout << elem << " "; std::cout << std::endl; auto qitb = front_inserter(deq1); // front_inserter on deque, elements of ivec are added in reverse order for(auto &vel : ivec) *qitb = vel; std::cout << "After using front_inserter() on deq1:\n"; for(auto &elem : deq1) std::cout << elem << " "; std::cout << std::endl; copy(ivec.cbegin(), ivec.cend(), inserter(lst1, lst1.begin()) ); //copy with inserter on list std::cout << "After calling copy() and using inserter() on lst1:\n"; for(auto &elem : lst1) std::cout << elem << " "; std::cout << std::endl; return 0; }
int main() { list<int> ilst, ilst2, ilst3; // empty lists // after this loop ilst contains: 1 2 3 4 for (list<int>::size_type i = 0; i != 4; ++i) ilst.push_front(i); // print list to see the ordering cout << "ilst" << endl; for (list<int>::iterator iter = ilst.begin(); iter != ilst.end(); ++iter) cout << *iter << " "; cout << endl; // after copy ilst2 contains: 4 3 2 1 copy(ilst.begin(), ilst.end(), front_inserter(ilst2)); // after copy, ilst3 contains: 1 2 3 4 copy(ilst.begin(), ilst.end(), inserter(ilst3, ilst3.begin())); // print ilst2 and ilst3 cout << "ilst2" << endl; for (list<int>::iterator iter = ilst2.begin(); iter != ilst2.end(); ++iter) cout << *iter << " "; cout << endl; cout << "ilst3" << endl; for (list<int>::iterator iter = ilst3.begin(); iter != ilst3.end(); ++iter) cout << *iter << " "; cout << endl; return 0; }
void ExplodingSprite::reset(const Vector2f &pos) { std::list<Chunk>::iterator ptr; if (chunks.empty()) { copy(freeList.begin(), freeList.end(), front_inserter(chunks)); freeList.clear(); ptr = chunks.begin(); while (ptr != chunks.end()) { ptr->reset(); ptr->setPosition(pos); ++ptr; } } }
IWORKPathPtr_t makeDoubleArrowPath(const IWORKSize &size, const double headWidth, const double stemThickness) { deque<Point> points = drawArrowHalf(2 * headWidth / size.m_width, 1 - 2 * stemThickness); { // mirror around the y axis deque<Point> mirroredPoints = points; transform(mirroredPoints, flip(true, false)); copy(mirroredPoints.begin(), mirroredPoints.end(), front_inserter(points)); } { // mirror around the x axis deque<Point> mirroredPoints = points; transform(mirroredPoints, flip(false, true)); copy(mirroredPoints.rbegin(), mirroredPoints.rend(), back_inserter(points)); } transform(points, scale(size.m_width, size.m_height) * scale(0.5, 0.5) * translate(1, 1)); const IWORKPathPtr_t path = makePolyLine(points); return path; }
void PhyEngine::buildEngineGraph(RadioGraph& graph) { //Create the components VertexIterator i, iend; for(b::tie(i,iend) = vertices(graph); i != iend; ++i) { //Load the component and add to vector ComponentDescription current = graph[*i]; b::shared_ptr<PhyComponent> comp = compManager_->loadComponent(current); comp->setEngine(this); //Provide an interface to the component components_.push_back(comp); } //Do a topological sort of the graph deque<unsigned> topoOrder; topological_sort(graph, front_inserter(topoOrder), b::vertex_index_map(b::identity_property_map())); //Set up some containers vector< ReadBufferBase* > currentInBufs; vector< WriteBufferBase* > currentOutBufs; map<string, int> inputTypes, outputTypes; //The external input buffers feed the source component of the graph for( vector< b::shared_ptr< DataBufferBase > >::iterator i = engInputBuffers_.begin(); i != engInputBuffers_.end(); ++i) { DataBufferBase* buf = (*i).get(); LinkDescription desc = buf->getLinkDescription(); inputTypes[desc.sinkPort] = buf->getTypeIdentifier(); currentInBufs.push_back(dynamic_cast<ReadBufferBase*>(buf)); } //Set buffers on the components for(deque<unsigned>::iterator i = topoOrder.begin(); i != topoOrder.end(); ++i) { //Get the internal input buffer details InEdgeIterator edgeIt, edgeItEnd; for(b::tie(edgeIt, edgeItEnd) = in_edges(*i, graph); edgeIt != edgeItEnd; ++edgeIt) { inputTypes[graph[*edgeIt].sinkPort] = graph[*edgeIt].theBuffer->getTypeIdentifier(); currentInBufs.push_back(dynamic_cast<ReadBufferBase*>(graph[*edgeIt].theBuffer.get())); } //TODO: Check that the input port names from the xml match existing input ports //TODO: Check that inputs exist for each of the registered input port names //Get output buffer types from component components_[*i]->calculateOutputTypes(inputTypes, outputTypes); // temporary shell for testing template components std::vector<int> inTypes, outTypes; for (std::map<std::string, int>::iterator j = inputTypes.begin(); j != inputTypes.end(); ++j) { inTypes.push_back(j->second); } for (std::map<std::string, int>::iterator j = outputTypes.begin(); j != outputTypes.end(); ++j) { outTypes.push_back(j->second); } PhyComponent* x = components_[*i]->setupIO(inTypes, outTypes); if (x != components_[*i].get()) { components_[*i].reset(x); } //Create internal output buffers and add to graph edges OutEdgeIterator outEdgeIt, outEdgeItEnd; for(b::tie(outEdgeIt, outEdgeItEnd) = out_edges(*i, graph); outEdgeIt != outEdgeItEnd; ++outEdgeIt) { //Check that the port name exists string srcPort = graph[*outEdgeIt].sourcePort; if(outputTypes.find(srcPort) == outputTypes.end()) { throw ResourceNotFoundException("Output port " + srcPort + \ " could not be found on PhyComponent " + components_[*i]->getName()); } //Create a PhyDataBuffer of the correct type int currentType = outputTypes[srcPort]; b::shared_ptr< DataBufferBase > buf = createPhyDataBuffer(currentType); graph[*outEdgeIt].theBuffer = buf; graph[*outEdgeIt].theBuffer->setLinkDescription(graph[*outEdgeIt]); internalBuffers_.push_back( buf ); currentOutBufs.push_back( dynamic_cast<WriteBufferBase*>( buf.get() ) ); //Remove from the outputTypes map outputTypes.erase( outputTypes.find( srcPort ) ); } //Anything left in the outputTypes map must be an external output buffer for( map<string, int>::iterator j = outputTypes.begin(); j != outputTypes.end(); ++j) { //Create a DataBuffer and add to exOutputBuffers b::shared_ptr< DataBufferBase > buf = createDataBuffer( j->second ); LinkDescription l; l.sourceEngine = engineName_; l.sourceComponent = components_[*i]->getName(); l.sourcePort = j->first; buf->setLinkDescription(l); engOutputBuffers_.push_back(buf); currentOutBufs.push_back( dynamic_cast<WriteBufferBase*>( buf.get() ) ); } //Set the buffers in the component components_[*i]->setBuffers(currentInBufs, currentOutBufs); //Initialize the component components_[*i]->initialize(); currentInBufs.clear(); currentOutBufs.clear(); } }
void EngineManager::loadRadio(RadioRepresentation rad) { //Set the current radio representation radioRep_ = rad; //Set the controller repositories in the ControllerManager controllerManager_.addRepository(reps_.contRepository); //Load the controllers vector<ControllerDescription> conts = rad.getControllers(); vector<ControllerDescription>::iterator contIt; for(contIt=conts.begin(); contIt!=conts.end(); ++contIt) { controllerManager_.loadController(contIt->type); } engineGraph_ = rad.getEngineGraph(); //Create the engines EngVertexIterator i, iend; for(b::tie(i,iend) = vertices(engineGraph_); i != iend; ++i) { //Get the engine description EngineDescription current = engineGraph_[*i]; //Add the engine to our vector engines_.push_back(createEngine(current)); } //Do a topological sort of the graph deque<unsigned> topoOrder; topological_sort(engineGraph_, front_inserter(topoOrder), b::vertex_index_map(b::identity_property_map())); //Go through graph in topological order and set buffers for(deque<unsigned>::iterator i = topoOrder.begin(); i != topoOrder.end(); ++i) { //Get input buffers vector< b::shared_ptr< DataBufferBase > > inputBuffers, outputBuffers; EngInEdgeIterator edgeIt, edgeItEnd; for(b::tie(edgeIt, edgeItEnd) = in_edges(*i, engineGraph_); edgeIt != edgeItEnd; ++edgeIt) { inputBuffers.push_back(engineGraph_[*edgeIt].theBuffer); } //Load the engine, passing in the input buffers outputBuffers = engines_[*i].loadEngine(engineGraph_[*i], inputBuffers); //Set the ouput buffers in the graph edges EngOutEdgeIterator outEdgeIt, outEdgeItEnd; for(b::tie(outEdgeIt, outEdgeItEnd) = out_edges(*i, engineGraph_); outEdgeIt != outEdgeItEnd; ++outEdgeIt) { for(vector< b::shared_ptr< DataBufferBase > >::iterator it = outputBuffers.begin(); it != outputBuffers.end(); ++it) { LinkDescription first = (*it)->getLinkDescription(); LinkDescription second = engineGraph_[*outEdgeIt]; if(sameLink(first, second)) { engineGraph_[*outEdgeIt].theBuffer = *it; engineGraph_[*outEdgeIt].theBuffer->setLinkDescription( second ); } } } } }