conditionlist.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ** Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: conditionlist.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the training library "conditionlist" interface.
  10. **
  11. ** History:
  12. */
  13. #include "pch.h"
  14. #include "ConditionList.h"
  15. namespace Training
  16. {
  17. //------------------------------------------------------------------------------
  18. // class methods
  19. //------------------------------------------------------------------------------
  20. /* void */ ConditionList::~ConditionList (void)
  21. {
  22. // assume that no one else is managing the memory for these conditions, and delete
  23. // them myself.
  24. std::list<Condition*>::iterator iterator = m_conditionList.begin ();
  25. for (; iterator != m_conditionList.end (); iterator++)
  26. delete *iterator;
  27. }
  28. //------------------------------------------------------------------------------
  29. bool ConditionList::Start (void)
  30. {
  31. // This condition list is to be considered "true" by default.
  32. bool result = true;
  33. // Loop over the condition list. If any condition evaluates to false, then
  34. // the condition list evaluates to false. We need to traverse all of the
  35. // conditions, however, since they may have actions associated with them.
  36. std::list<Condition*>::iterator iterator = m_conditionList.begin ();
  37. for (; iterator != m_conditionList.end (); iterator++)
  38. if ((*iterator)->Start () == false)
  39. result = false;
  40. // return the result
  41. return result;
  42. }
  43. //------------------------------------------------------------------------------
  44. void ConditionList::Stop (void)
  45. {
  46. // Loop over the condition list, calling stop on all of them.
  47. std::list<Condition*>::iterator iterator = m_conditionList.begin ();
  48. for (; iterator != m_conditionList.end (); iterator++)
  49. (*iterator)->Stop ();
  50. }
  51. //------------------------------------------------------------------------------
  52. bool ConditionList::Evaluate (void)
  53. {
  54. // This condition list is to be considered "true" by default.
  55. bool result = true;
  56. // Loop over the condition list. If any condition evaluates to false, then
  57. // the condition list evaluates to false. We need to traverse all of the
  58. // conditions, however, since they may have actions associated with them.
  59. std::list<Condition*>::iterator iterator = m_conditionList.begin ();
  60. for (; iterator != m_conditionList.end (); iterator++)
  61. if ((*iterator)->Evaluate () == false)
  62. result = false;
  63. // return the result
  64. return result;
  65. }
  66. //------------------------------------------------------------------------------
  67. void ConditionList::AddCondition (Condition* pCondition)
  68. {
  69. // Store the conditions in the order they are added. This gives the
  70. // author some modicum of control over playback order.
  71. m_conditionList.push_back (pCondition);
  72. }
  73. //------------------------------------------------------------------------------
  74. }