cmCableCommand.cxx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmCableCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmCableCommand
  14. /**
  15. * Constructor initializes to empty m_CableData.
  16. */
  17. cmCableCommand::cmCableCommand(): m_CableData(0)
  18. {
  19. }
  20. /**
  21. * Destructor frees the cmCableData only if this command is its owner.
  22. */
  23. cmCableCommand::~cmCableCommand()
  24. {
  25. if(m_CableData && m_CableData->OwnerIs(this))
  26. {
  27. delete m_CableData;
  28. }
  29. }
  30. /**
  31. * Ensure that this cmCableCommand has a valid m_CableData pointer.
  32. */
  33. void cmCableCommand::SetupCableData()
  34. {
  35. // Only do something if the pointer is invalid.
  36. if(m_CableData)
  37. { return; }
  38. // Look through the vector of commands from the makefile.
  39. const std::vector<cmCommand*>& usedCommands =
  40. m_Makefile->GetUsedCommands();
  41. for(std::vector<cmCommand*>::const_iterator commandIter =
  42. usedCommands.begin(); commandIter != usedCommands.end(); ++commandIter)
  43. {
  44. // If this command is a cmCableCommand, see if it has a cmCableData
  45. // instance.
  46. cmCableCommand* command = cmCableCommand::SafeDownCast(*commandIter);
  47. if(command)
  48. { m_CableData = command->m_CableData; }
  49. // If we found an instance of cmCableData, then we are done.
  50. if(m_CableData)
  51. { return; }
  52. }
  53. // We didn't find another cmCableCommand with a valid cmCableData.
  54. // We must allocate the new cmCableData ourselves, and with this
  55. // command as its owner.
  56. m_CableData = new cmCableData(this);
  57. }