本文整理汇总了C++中Host::getNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::getNumber方法的具体用法?C++ Host::getNumber怎么用?C++ Host::getNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::getNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connectTo
/* --------------------------------------------------------------------------- */
void Router::connectTo(Host &h) {
if ((this->routeMap).count(h.getNumber()) > 0) {
if (h.getConnection() != NULL) {
cout << "Sorry, but you must disconnect from your current router and "
<< "reconnect." << endl;
return;
} else {
cout << "Sorry, but you are currently using a name already in the network,"
<< " this must be reassigned." << endl;
return;
}
}
// Update neighborHosts table.
(this->neighborHosts).insert(pair<int, Host*>(h.getNumber(), &h));
// Add entry to the routeMap.
vector<int> route (1);
*(route.begin()) = h.getNumber();
(this->routeMap).insert(pair<int, vector<int> >(h.getNumber(), route));
// Have the Host update its connection.
h.connectTo(this);
// Update the Router's neighbors of the new connection.
route.insert(route.begin(), this->getNumber());
for (multimap<int, Router *>::iterator ri = (this->neighborRouters).begin();
ri != (this->neighborRouters).end();
ri++)
{
this->updateNeighbor(ri->second, route);
}
}
示例2: updateNeighborDisconnectHost
/* --------------------------------------------------------------------------- */
void Router::updateNeighborDisconnectHost(Router *r, Host &h) {
// If the Host does not appear in its routeMap, end function call.
if ((r->routeMap).count(h.getNumber()) == 0) {
return;
}
(r->routeMap).erase(h.getNumber());
for (multimap<int, Router *>::iterator ri = (r->neighborRouters).begin();
ri != (r->neighborRouters).end();
ri++)
{
r->updateNeighborDisconnectHost(ri->second, h);
}
}
示例3: disconnect
/* --------------------------------------------------------------------------- */
void Router::disconnect(Host &h) {
// Check if the Host is actually connected to the Router, if not throw error.
if ((this->neighborHosts).count(h.getNumber()) == 0) {
cout << "Sorry, but Host " << h.getNumber() << " is not connected to Router "
<< this->getNumber() << ", so cannot disconnect from it." << endl;
return;
}
// Remove the connection from neighborHosts, routeMap, and the Host.
(this->neighborHosts).erase(h.getNumber());
(this->routeMap).erase(h.getNumber());
h.disconnectFrom(this);
// Update the Router's neighbors of the deletion of the connection.
for (multimap<int, Router *>::iterator ri = (this->neighborRouters).begin();
ri != (this->neighborRouters).end();
ri++)
{
this->updateNeighborDisconnectHost(ri->second, h);
}
}