Don't like ads? PRO users don't see any ads ;-)
Guest

tutniet

By: a guest on May 7th, 2012  |  syntax: C++  |  size: 0.91 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. float Beam::getTotalMass(bool withLocked)
  2. {
  3.         if (!withLocked) return totalmass; // already computed in calc_masses2
  4.  
  5.         bool found = true;
  6.         float mass = 0.0f;
  7.         std::map< Beam*, bool> lookup_table;
  8.         std::pair<std::map< Beam*, bool>::iterator, bool> ret;
  9.  
  10.         lookup_table.insert(std::pair< Beam*, bool>(this, false));
  11.  
  12.         while (found)
  13.         {
  14.                 found = false;
  15.  
  16.                 for (std::map< Beam*, bool>::iterator it_beam=lookup_table.begin(); it_beam != lookup_table.end(); ++it_beam)
  17.                 {
  18.                         if (!it_beam->second)
  19.                         {
  20.                                 for (std::vector<hook_t>::iterator it_hook=it_beam->first->hooks.begin(); it_hook != it_beam->first->hooks.end(); ++it_hook)
  21.                                 {
  22.                                         if (it_hook->lockTruck)
  23.                                         {
  24.                                                 ret = lookup_table.insert(std::pair< Beam*, bool>(it_hook->lockTruck, false));
  25.                                                 found = found || ret.second;
  26.                                         }
  27.                                 }
  28.                                 mass += it_beam->first->totalmass;
  29.                                 it_beam->second = true;
  30.                         }
  31.                 }
  32.         }
  33.  
  34.         return mass;
  35. }