cmCableCommand.cxx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 must make sure the output directory exists so that the CABLE
  54. // configuration file can be opened by the cmCableData.
  55. std::string pathName = m_Makefile->GetStartOutputDirectory();
  56. if(!cmSystemTools::MakeDirectory(pathName.c_str()))
  57. {
  58. cmSystemTools::Error("Unable to make directory ", pathName.c_str());
  59. }
  60. // We didn't find another cmCableCommand with a valid cmCableData.
  61. // We must allocate the new cmCableData ourselves, and with this
  62. // command as its owner.
  63. pathName += "/cable_config.xml";
  64. m_CableData = new cmCableData(this, pathName);
  65. }