cmSourceGroup.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmSourceGroup.h"
  14. /**
  15. * The constructor initializes the group's regular expression.
  16. */
  17. cmSourceGroup::cmSourceGroup(const char* name, const char* regex):
  18. m_Name(name),
  19. m_GroupRegex(regex)
  20. {
  21. }
  22. /**
  23. * Copy constructor.
  24. */
  25. cmSourceGroup::cmSourceGroup(const cmSourceGroup& r):
  26. m_Name(r.m_Name),
  27. m_GroupRegex(r.m_GroupRegex),
  28. m_BuildRules(r.m_BuildRules)
  29. {
  30. }
  31. /**
  32. * Returns whether the given name matches the group's regular expression.
  33. */
  34. bool cmSourceGroup::Matches(const char* name)
  35. {
  36. return m_GroupRegex.find(name);
  37. }
  38. /**
  39. * Add a source to the group that the compiler will know how to build.
  40. */
  41. void cmSourceGroup::AddSource(const char* name)
  42. {
  43. BuildRules::iterator s = m_BuildRules.find(name);
  44. if(s == m_BuildRules.end())
  45. {
  46. // The source was not found. Add it with no commands.
  47. m_BuildRules[name];
  48. return;
  49. }
  50. }
  51. /**
  52. * Add a source and corresponding custom command to the group. If the
  53. * source already exists, the command will be added to its set of commands.
  54. * If the command also already exists, the given dependencies and outputs
  55. * are added to it.
  56. */
  57. void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
  58. {
  59. std::string commandAndArgs = cmd.GetCommandAndArguments();
  60. BuildRules::iterator s = m_BuildRules.find(cmd.GetSourceName());
  61. if(s == m_BuildRules.end())
  62. {
  63. // The source was not found. Add it with this command.
  64. CommandFiles& cmdFiles = m_BuildRules[cmd.GetSourceName()][commandAndArgs];
  65. cmdFiles.m_Command = cmd.GetCommand();
  66. cmdFiles.m_Arguments = cmd.GetArguments();
  67. cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
  68. cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
  69. return;
  70. }
  71. // The source already exists. See if the command exists.
  72. Commands& commands = s->second;
  73. Commands::iterator c = commands.find(commandAndArgs);
  74. if(c == commands.end())
  75. {
  76. // The command did not exist. Add it.
  77. commands[commandAndArgs].m_Command = cmd.GetCommand();
  78. commands[commandAndArgs].m_Arguments = cmd.GetArguments();
  79. commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
  80. cmd.GetDepends().end());
  81. commands[commandAndArgs].m_Outputs.insert(cmd.GetOutputs().begin(),
  82. cmd.GetOutputs().end());
  83. return;
  84. }
  85. // The command already exists for this source. Merge the sets.
  86. CommandFiles& commandFiles = c->second;
  87. commandFiles.m_Depends.insert(cmd.GetDepends().begin(),
  88. cmd.GetDepends().end());
  89. commandFiles.m_Outputs.insert(cmd.GetOutputs().begin(),
  90. cmd.GetOutputs().end());
  91. }
  92. void cmSourceGroup::Print() const
  93. {
  94. std::cout << "cmSourceGroup: " << m_Name.c_str() << "\n";
  95. for(BuildRules::const_iterator i = m_BuildRules.begin();
  96. i != m_BuildRules.end(); ++i)
  97. {
  98. std::cout << "BuildRule: " << i->first.c_str() << "\n";
  99. for(Commands::const_iterator j = i->second.begin();
  100. j != i->second.end(); ++j)
  101. {
  102. std::cout << "FullCommand: " << j->first.c_str() << "\n";
  103. std::cout << "Command: " << j->second.m_Command.c_str() << "\n";
  104. std::cout << "Arguments: " << j->second.m_Arguments.c_str() << "\n";
  105. std::cout << "Command Outputs " << j->second.m_Outputs.size() << "\n";
  106. std::cout << "Command Depends " << j->second.m_Depends.size() << "\n";
  107. }
  108. }
  109. }
  110. void cmSourceGroup::CommandFiles::Merge(const CommandFiles &r)
  111. {
  112. std::set<std::string>::const_iterator dep = r.m_Depends.begin();
  113. std::set<std::string>::const_iterator out = r.m_Outputs.begin();
  114. for (;dep != r.m_Depends.end(); ++dep)
  115. {
  116. this->m_Depends.insert(*dep);
  117. }
  118. for (;out != r.m_Outputs.end(); ++out)
  119. {
  120. this->m_Outputs.insert(*out);
  121. }
  122. }