cmCableCommand.cxx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cmCabilCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmCabilCommand
  14. /**
  15. * Constructor initializes to empty m_CabilData.
  16. */
  17. cmCabilCommand::cmCabilCommand(): m_CabilData(0)
  18. {
  19. }
  20. /**
  21. * Destructor frees the cmCabilData only if this command is its owner.
  22. */
  23. cmCabilCommand::~cmCabilCommand()
  24. {
  25. if(m_CabilData && m_CabilData->OwnerIs(this))
  26. {
  27. delete m_CabilData;
  28. }
  29. }
  30. /**
  31. * Write a CABIL configuration file header.
  32. */
  33. void cmCabilCommand::WriteConfigurationHeader(std::ostream& os) const
  34. {
  35. os << "<?xml version=\"1.0\"?>" << std::endl
  36. << "<CabilConfiguration>" << std::endl;
  37. }
  38. /**
  39. * Write a CABIL configuration file footer.
  40. */
  41. void cmCabilCommand::WriteConfigurationFooter(std::ostream& os) const
  42. {
  43. os << "</CabilConfiguration>" << std::endl;
  44. }
  45. /**
  46. * Ensure that this cmCabilCommand has a valid m_CabilData pointer.
  47. */
  48. void cmCabilCommand::SetupCabilData()
  49. {
  50. // Only do something if the pointer is invalid.
  51. if(m_CabilData)
  52. { return; }
  53. // Look through the vector of commands from the makefile.
  54. const std::vector<cmCommand*>& usedCommands =
  55. m_Makefile->GetUsedCommands();
  56. for(std::vector<cmCommand*>::const_iterator commandIter =
  57. usedCommands.begin(); commandIter != usedCommands.end(); ++commandIter)
  58. {
  59. // If this command is a cmCabilCommand, see if it has a cmCabilData
  60. // instance.
  61. cmCabilCommand* command = cmCabilCommand::SafeDownCast(*commandIter);
  62. if(command)
  63. { m_CabilData = command->m_CabilData; }
  64. // If we found an instance of cmCabilData, then we are done.
  65. if(m_CabilData)
  66. { return; }
  67. }
  68. // We didn't find another cmCabilCommand with a valid cmCabilData.
  69. // We must allocate the new cmCabilData ourselves, and with this
  70. // command as its owner.
  71. m_CabilData = new cmCabilData(this);
  72. }