cmCableClassSet.cxx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "cmCableClassSet.h"
  33. /**
  34. * Add to the set of required sources to define the class.
  35. */
  36. void cmCableClass::AddSources(const Sources& sources)
  37. {
  38. for(Sources::const_iterator s = sources.begin(); s != sources.end(); ++s)
  39. {
  40. m_Sources.insert(*s);
  41. }
  42. }
  43. /**
  44. * Add to the set of required sources to define the class.
  45. */
  46. void cmCableClass::AddSource(const char* source)
  47. {
  48. m_Sources.insert(source);
  49. }
  50. /**
  51. * Add a class to the set.
  52. */
  53. void cmCableClassSet::AddClass(const char* name,
  54. const cmCableClass& cableClass)
  55. {
  56. m_CableClassMap.insert(CableClassMap::value_type(name, cableClass));
  57. }
  58. /**
  59. * Add a source to every class in the set. This should only be done after
  60. * all classes have been inserted.
  61. */
  62. void cmCableClassSet::AddSource(const char* name)
  63. {
  64. for(CableClassMap::iterator c = m_CableClassMap.begin();
  65. c != m_CableClassMap.end(); ++c)
  66. {
  67. c->second.AddSource(name);
  68. }
  69. }
  70. /**
  71. * Get the size of the internal CableClassMap used to store the set.
  72. */
  73. unsigned int cmCableClassSet::Size() const
  74. {
  75. return m_CableClassMap.size();
  76. }
  77. /**
  78. * Get a begin iterator to the internal CableClassMap used to store the
  79. * set.
  80. */
  81. cmCableClassSet::CableClassMap::const_iterator cmCableClassSet::Begin() const
  82. {
  83. return m_CableClassMap.begin();
  84. }
  85. /**
  86. * Get an end iterator to the internal CableClassMap used to store the
  87. * set.
  88. */
  89. cmCableClassSet::CableClassMap::const_iterator cmCableClassSet::End() const
  90. {
  91. return m_CableClassMap.end();
  92. }
  93. /**
  94. * Parse the given string to extract the class information specified.
  95. *
  96. * The format of the string is
  97. * [tag:]class_name[;source1;source2;...]
  98. *
  99. */
  100. void cmCableClassSet::ParseAndAddElement(const char* element,
  101. cmMakefile* makefile)
  102. {
  103. // A regular expression to match the tagged element specification.
  104. cmRegularExpression tagGiven("^([A-Za-z_0-9]*)[ \t]*:[ \t]*([^:].*|::.*)$");
  105. // A regular expression to match the element when more source files are given.
  106. cmRegularExpression sourcesRemain("^([^;]*);(.*)$");
  107. std::string tag;
  108. std::string elementWithoutTag;
  109. std::string className;
  110. std::string sourceString;
  111. if(tagGiven.find(element))
  112. {
  113. // A tag was given. Use it.
  114. tag = tagGiven.match(1);
  115. elementWithoutTag = tagGiven.match(2);
  116. }
  117. else
  118. {
  119. // No tag was given. Try to generate one.
  120. //if(!this->GenerateTag(element, tag))
  121. // { return false; }
  122. elementWithoutTag = element;
  123. }
  124. if(sourcesRemain.find(elementWithoutTag.c_str()))
  125. {
  126. className = sourcesRemain.match(1);
  127. sourceString = sourcesRemain.match(2);
  128. }
  129. else
  130. {
  131. className = elementWithoutTag;
  132. }
  133. cmCableClass::Sources sources;
  134. while(sourcesRemain.find(sourceString.c_str()))
  135. {
  136. sources.insert(sourcesRemain.match(1));
  137. sourceString = sourcesRemain.match(2);
  138. }
  139. if(sourceString != "")
  140. {
  141. sources.insert(sourceString);
  142. }
  143. // A regular expression to match a class name that is just a set.
  144. cmRegularExpression setDereference("^\\$(.*)$");
  145. if(setDereference.find(className))
  146. {
  147. std::string setName = setDereference.match(1);
  148. cmData* d = makefile->LookupData(setName.c_str());
  149. // This should be a dynamic_cast, but we don't want to require RTTI.
  150. cmCableClassSet* classSet = static_cast<cmCableClassSet*>(d);
  151. if(classSet)
  152. {
  153. this->AddCableClassSet(*classSet, sources);
  154. }
  155. else
  156. {
  157. cmSystemTools::Error("Unknown CABLE class set ", setName.c_str());
  158. }
  159. }
  160. else
  161. {
  162. cmCableClass cableClass;
  163. cableClass.AddSources(sources);
  164. this->AddClass(className.c_str(), cableClass);
  165. }
  166. }
  167. /**
  168. * Add all elements from the given cmCableClassSet to this set, with the given
  169. * sources added to each element.
  170. */
  171. void cmCableClassSet::AddCableClassSet(const cmCableClassSet& set,
  172. const cmCableClass::Sources& sources)
  173. {
  174. for(CableClassMap::const_iterator c = set.Begin(); c != set.End(); ++c)
  175. {
  176. cmCableClass cableClass = c->second;
  177. cableClass.AddSources(sources);
  178. this->AddClass(c->first.c_str(), cableClass);
  179. }
  180. }