cmSourceGroup.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "cmSourceGroup.h"
  12. /**
  13. * The constructor initializes the group's regular expression.
  14. */
  15. cmSourceGroup::cmSourceGroup(const char* name, const char* regex):
  16. m_Name(name),
  17. m_GroupRegex(regex)
  18. {
  19. }
  20. /**
  21. * Copy constructor.
  22. */
  23. cmSourceGroup::cmSourceGroup(const cmSourceGroup& r):
  24. m_Name(r.m_Name),
  25. m_GroupRegex(r.m_GroupRegex),
  26. m_Sources(r.m_Sources),
  27. m_CustomCommands(r.m_CustomCommands)
  28. {
  29. }
  30. /**
  31. * Returns whether the given name matches the group's regular expression.
  32. */
  33. bool cmSourceGroup::Matches(const char* name)
  34. {
  35. return m_GroupRegex.find(name);
  36. }
  37. /**
  38. * Add a source and corresponding custom command to the group. If the
  39. * source already exists, the command will be added to its set of commands.
  40. * If the command also already exists, the given dependencies and outputs
  41. * are added to it.
  42. */
  43. void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
  44. {
  45. CustomCommands::iterator s = m_CustomCommands.find(cmd.m_Source);
  46. if(s == m_CustomCommands.end())
  47. {
  48. // The source was not found. Add it with this command.
  49. m_CustomCommands[cmd.m_Source][cmd.m_Command].
  50. m_Depends.insert(cmd.m_Depends.begin(),cmd.m_Depends.end());
  51. m_CustomCommands[cmd.m_Source][cmd.m_Command].
  52. m_Outputs.insert(cmd.m_Outputs.begin(),cmd.m_Outputs.end());
  53. return;
  54. }
  55. // The source already exists. See if the command exists.
  56. Commands& commands = s->second;
  57. Commands::iterator c = commands.find(cmd.m_Command);
  58. if(c == commands.end())
  59. {
  60. // The command did not exist. Add it.
  61. commands[cmd.m_Command].m_Depends.insert(cmd.m_Depends.begin(), cmd.m_Depends.end());
  62. commands[cmd.m_Command].m_Outputs.insert(cmd.m_Outputs.begin(), cmd.m_Outputs.end());
  63. return;
  64. }
  65. // The command already exists for this source. Merge the sets.
  66. CommandFiles& commandFiles = c->second;
  67. commandFiles.m_Depends.insert(cmd.m_Depends.begin(), cmd.m_Depends.end());
  68. commandFiles.m_Outputs.insert(cmd.m_Outputs.begin(), cmd.m_Outputs.end());
  69. }