void weakptr_study() { { std::shared_ptr<int> kid2(new int(5)); } WDummy dd; std::shared_ptr<WDummy> spr2 = dd.process(); std::shared_ptr<int> kid(new int(10)); std::weak_ptr<int> ptr1 = kid; //std::cout << ptr1.use_count() << std::endl; std::weak_ptr<int> ptr2; { std::shared_ptr<int> kid2(new int(10)); ptr2 = kid2; } if (ptr1.expired()) { std::cout << "ptr1 dead" << std::endl; } if (ptr2.expired()) { std::cout << "ptr2 dead" << std::endl; } // convert std::shared_ptr<int> sptr2(ptr2); //std::shared_ptr<int> sptr4 = ptr2; auto sptr1 = ptr2.lock(); std::shared_ptr<int> sptr3 = ptr2.lock(); }
void traverse ( const xercesc::DOMNode *dom, XmlTree::Node *node ) { // Check input. if ( 0x0 == dom || 0x0 == node ) Usul::Exceptions::Thrower<std::runtime_error> ( "Error 3066136826: null node found while traversing" ); // Element nodes are the groups. This should always be true because of // the way we decide to recursively call this function, and the way we // initially call it with the document's root element. if ( xercesc::DOMNode::ELEMENT_NODE != dom->getNodeType() ) Usul::Exceptions::Thrower<std::runtime_error> ( "Error 4028759980: expected element node while traversing" ); // Should also be true. if ( true == node->name().empty() ) Usul::Exceptions::Thrower<std::runtime_error> ( "Error 3856531268: found node with empty name while traversing" ); // Set the attributes. Helper::setAttributes ( dom->getAttributes(), node ); // Loop through the children. const xercesc::DOMNodeList *kids ( dom->getChildNodes() ); const XMLSize_t num ( ( kids ) ? kids->getLength() : 0 ); for ( XMLSize_t i = 0; i < num; ++i ) { // Get the child. xercesc::DOMNode *kid ( kids->item ( i ) ); // Is the child a text node? if ( kid && xercesc::DOMNode::TEXT_NODE == kid->getNodeType() ) { // Xerces builds a "text node" for the value of the text, but the // tag-name is always "#text". The parent "element node" will contain // the tag's name. Ignore text elements that are empty. const std::string v ( XmlTree::Functions::value ( kid ) ); if ( false == v.empty() ) node->value ( v ); } // Is the child an element? else if ( kid && xercesc::DOMNode::ELEMENT_NODE == kid->getNodeType() ) { // Does it have a name? const std::string n ( XmlTree::Functions::name ( kid ) ); if ( false == n.empty() ) { // Call this function recursively with a new node. XmlTree::Node::ValidRefPtr child ( new XmlTree::Node ( n ) ); Helper::traverse ( kid, child.get() ); node->children().push_back ( child ); } } } }
::ceres::ResidualBlockId Estimator::addObservation(uint64_t landmarkId, uint64_t poseId, size_t camIdx, size_t keypointIdx) { OKVIS_ASSERT_TRUE_DBG(Exception, isLandmarkAdded(landmarkId), "landmark not added"); // avoid double observations okvis::KeypointIdentifier kid(poseId, camIdx, keypointIdx); if (landmarksMap_.at(landmarkId).observations.find(kid) != landmarksMap_.at(landmarkId).observations.end()) { return NULL; } // get the keypoint measurement okvis::MultiFramePtr multiFramePtr = multiFramePtrMap_.at(poseId); Eigen::Vector2d measurement; multiFramePtr->getKeypoint(camIdx, keypointIdx, measurement); Eigen::Matrix2d information = Eigen::Matrix2d::Identity(); double size = 1.0; multiFramePtr->getKeypointSize(camIdx, keypointIdx, size); information *= 64.0 / (size * size); // create error term std::shared_ptr < ceres::ReprojectionError < GEOMETRY_TYPE >> reprojectionError( new ceres::ReprojectionError<GEOMETRY_TYPE>( multiFramePtr->template geometryAs<GEOMETRY_TYPE>(camIdx), camIdx, measurement, information)); ::ceres::ResidualBlockId retVal = mapPtr_->addResidualBlock( reprojectionError, cauchyLossFunctionPtr_ ? cauchyLossFunctionPtr_.get() : NULL, mapPtr_->parameterBlockPtr(poseId), mapPtr_->parameterBlockPtr(landmarkId), mapPtr_->parameterBlockPtr( statesMap_.at(poseId).sensors.at(SensorStates::Camera).at(camIdx).at( CameraSensorStates::T_SCi).id)); // remember landmarksMap_.at(landmarkId).observations.insert( std::pair<okvis::KeypointIdentifier, uint64_t>( kid, reinterpret_cast<uint64_t>(retVal))); return retVal; }
Individual Individual::CreateOffspring(const std::string& name) noexcept { Individual kid( m_dna.CreateOffspring(), m_pedigree->CreateOffspring(name) ); if (name.empty()) { int index = kid.GetIndex(); std::string name; while (index != 0) { name += std::string(1,'A' + (index % 26)); index /= 26; } kid.SetName(name); } return kid; }
void GlobalGrid::getUpdateState( IndexSet* &update, double tol, TypeRefinement criteria )const{ if ( update != 0 ){ delete update; }; update = new IndexSet( num_dimensions ); // do a full refinement for now for( int i=0; i<tensorList->getNumIndexes(); i++ ){ const int *parent = tensorList->getIndexList(i); //int kid[num_dimensions]; std::vector<int> kid(num_dimensions); //tcopy( num_dimensions, parent, kid ); tcopy( num_dimensions, parent, &kid[0] ); for( int j=0; j<num_dimensions; j++ ){ kid[j]++; if ( tensorList->getSlot(&kid[0]) == -1 ){ update->add( &kid[0] ); } kid[j]--; } } };
void WaveGenerator::popKid(CommandQueue& commands, int minIntel, float speed) { Command cmd; cmd.category = Category::EntityLayer; cmd.action = [&,speed](SceneNode& node, sf::Time dt) { std::unique_ptr<BasicKidNode> kid(new BasicKidNode(mTextures, speed)); if(randomInt(2) == 0) { int y = randomInt(8); kid->setPosition(toIsoCoord(0, y)); kid->setGridPosition(sf::Vector2i(0, y)); } else { int x = randomInt(7)+1; kid->setPosition(toIsoCoord(x, 0)); kid->setGridPosition(sf::Vector2i(x, 0)); } node.attachChild(std::move(kid)); }; commands.push(cmd); mNbKidPoped++; }
int main (int argc, char *argv[]) { int i; struct sockaddr_in devil, isa; struct hostent *hp; if (argc == 1) { fprintf (stderr, "No socket number\n"); return 1; } sscanf (argv[1], "%d", &socketnumber); if (!socketnumber || socketnumber > 0xffff) { fprintf (stderr, "Invalid socket number: %d\n", socketnumber); return 1; } gethostname (localhost, MAXHOSTNAMELENGTH); hp = gethostbyname (localhost); if (!hp) { fprintf (stderr, "Cannot get local host info\n"); return 1; } /* Open a socket */ sockethandle = socket (hp->h_addrtype, SOCK_STREAM, 0); if (sockethandle == -1) { perror ("socket"); return 1; } devil.sin_family = hp->h_addrtype; devil.sin_port = htons (socketnumber); devil.sin_addr.s_addr = 0; for (i = 0; i < sizeof (devil.sin_zero); i++) devil.sin_zero[i] = '\000'; memcpy (&devil.sin_addr, hp->h_addr_list[0], hp->h_length); if (bind (sockethandle, &devil, sizeof (devil)) < 0) { perror ("bind"); return 1; } /* May only accept one debugger at once */ if (listen (sockethandle, 0)) { perror ("listen"); return 1; } fprintf (stderr, "Waiting for connection from debugger..."); debugsock = accept (sockethandle, &isa, &i); if (debugsock == -1) { perror ("accept"); return 1; } fprintf (stderr, " done.\nConnection Established.\n"); nfds = getdtablesize (); if (pipe (mumkid)) { perror ("pipe"); return 1; } if (pipe (kidmum)) { perror ("pipe"); return 1; } if (pipe (DebuggerARMul)) { perror ("pipe"); return 1; } #ifdef DEBUG fprintf (stderr, "Created pipes ok\n"); #endif child = fork (); #ifdef DEBUG fprintf (stderr, "fork() ok\n"); #endif if (child == 0) kid (); if (child != -1) parent (); perror ("fork"); return 1; }
void addChild (T & data) { Node kid(data); children.push_back(kid); }