Für Vorlesungen, bitte die Webseite verwenden. https://flavigny.de/lecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1KB

  1. // Methoden fuer die geschachtelte Klasse
  2. Simulator::WireEvent::WireEvent () { w=0; t=0; s=unknown; }
  3. Simulator::WireEvent::WireEvent (Wire& W, int T, State S) {w=&W; t=T; s=S;}
  4. bool Simulator::WireEvent::operator< (WireEvent we)
  5. {
  6. if (t<we.t) return true;
  7. if (t==we.t && (reinterpret_cast<unsigned long int>(w)<reinterpret_cast<unsigned long int>(we.w))) return true;
  8. return false;
  9. }
  10. // Konstruktor
  11. Simulator::Simulator (){time = 0;}
  12. int Simulator::GetTime (){return time;}
  13. void Simulator::StoreWireEvent (Wire& w, int t, State s)
  14. {
  15. pq.push(WireEvent(w,t,s));
  16. }
  17. void Simulator::StoreCircuitEvent (Circuit& c)
  18. {
  19. q.push(&c);
  20. }
  21. void Simulator::Simulate (int end)
  22. {
  23. WireEvent we;
  24. while (time<=end)
  25. {
  26. // Alle Draehte fuer die aktuelle Zeit
  27. while (!pq.empty())
  28. {
  29. we = pq.top(); // kleinster Eintrag
  30. if (we.t>time) break; // alle Zustaende fuer Zeitschritt OK
  31. pq.pop(); // entferne Eintrag
  32. (we.w)->Action(we.s); // neuer Zustand
  33. }
  34. // Berechne Bausteine zur aktuellen Zeit neu
  35. while (!q.empty())
  36. {
  37. (q.front())->Action();
  38. q.pop();
  39. }
  40. // Zeitschritt fertig
  41. time = time+1;
  42. }
  43. }