Ejemplo n.º 1
0
std::vector<std::shared_ptr<Endpoint>> ListeningEndpointsTable::getValue(
    const std::string &name) {
  auto it = m_values.find(name);
  if (it != m_values.end())
    return it->second;
  else
    throw TableException("Value not found.");
}
void Table::tableRetrieve(KeyType searchKey,
                          TableItemType& tableItem) const
   throw(TableException)
// Calls: position.
{
   // locate the position where searchKey exists/belongs
   int spot = position(searchKey);

   // is searchKey present in table?
   if ((spot > size) || (items[spot].getKey() != searchKey))
      // searchKey not in table
      throw TableException("TableException: Item not found on retrieve");
   else
      tableItem = items[spot];  // item present; retrieve it
}  // end tableRetrieve
void Table::tableDelete(KeyType searchKey)
   throw(TableException)
// Calls: position.
{
   // locate the position where searchKey exists/belongs
   int spot = position(searchKey);

   // is searchKey present in the table?
   if ((spot > size) || (items[spot].getKey() != searchKey))
      // searchKey not in table
      throw TableException("TableException: Item not found on delete");
   else
   {  // searchKey in table
      --size;  // delete the item

      // shift down to fill the gap
      for (int index = spot; index < size; ++index)
         items[index] = items[index+1];
   }  // end if
}  // end tableDelete
void Table::tableInsert(const TableItemType& newItem)
   throw(TableException)
// Note: Insertion is unsuccessful if the table is full,
// that is, if the table already contains MAX_TABLE items.
// Calls: position.
{
   if (size == MAX_TABLE)
      throw TableException("TableException: Table full");

   // there is room to insert;
   // locate the position where newItem belongs
   int spot = position(newItem.getKey());

   // shift up to make room for the new item
   for (int index = size-1; index >= spot; --index)
      items[index+1] = items[index];

   // make the insertion
   items[spot] = newItem;
   ++size;
}  // end tableInsert