cmCableCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmCableCommand.h"
  33. #include "cmCacheManager.h"
  34. // cmCableCommand
  35. /**
  36. * Constructor initializes to empty m_CableData.
  37. */
  38. cmCableCommand::cmCableCommand(): m_CableData(0)
  39. {
  40. }
  41. /**
  42. * Destructor frees the cmCableData only if this command is its owner.
  43. */
  44. cmCableCommand::~cmCableCommand()
  45. {
  46. if(m_CableData && m_CableData->OwnerIs(this))
  47. {
  48. delete m_CableData;
  49. }
  50. }
  51. /**
  52. * Ensure that this cmCableCommand has a valid m_CableData pointer.
  53. */
  54. void cmCableCommand::SetupCableData()
  55. {
  56. // Only do something if the pointer is invalid.
  57. if(m_CableData)
  58. { return; }
  59. // Look through the vector of commands from the makefile.
  60. const std::vector<cmCommand*>& usedCommands =
  61. m_Makefile->GetUsedCommands();
  62. for(std::vector<cmCommand*>::const_iterator commandIter =
  63. usedCommands.begin(); commandIter != usedCommands.end(); ++commandIter)
  64. {
  65. // If this command is a cmCableCommand, see if it has a cmCableData
  66. // instance.
  67. cmCableCommand* command = cmCableCommand::SafeDownCast(*commandIter);
  68. if(command)
  69. { m_CableData = command->m_CableData; }
  70. // If we found an instance of cmCableData, then we are done.
  71. if(m_CableData)
  72. { return; }
  73. }
  74. // We must make sure the output directory exists so that the CABLE
  75. // configuration file can be opened by the cmCableData.
  76. std::string pathName = m_Makefile->GetStartOutputDirectory();
  77. if(!cmSystemTools::MakeDirectory(pathName.c_str()))
  78. {
  79. cmSystemTools::Error("Unable to make directory ", pathName.c_str());
  80. }
  81. // We didn't find another cmCableCommand with a valid cmCableData.
  82. // We must allocate the new cmCableData ourselves, and with this
  83. // command as its owner.
  84. pathName += "/cable_config.xml";
  85. m_CableData = new cmCableData(this, pathName);
  86. }