cmXCodeObject.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmXCodeObject_h
  11. #define cmXCodeObject_h
  12. #include "cmStandardIncludes.h"
  13. class cmGeneratorTarget;
  14. class cmXCodeObject
  15. {
  16. public:
  17. enum Type
  18. {
  19. OBJECT_LIST,
  20. STRING,
  21. ATTRIBUTE_GROUP,
  22. OBJECT_REF,
  23. OBJECT
  24. };
  25. enum PBXType
  26. {
  27. PBXGroup,
  28. PBXBuildStyle,
  29. PBXProject,
  30. PBXHeadersBuildPhase,
  31. PBXSourcesBuildPhase,
  32. PBXFrameworksBuildPhase,
  33. PBXNativeTarget,
  34. PBXFileReference,
  35. PBXBuildFile,
  36. PBXContainerItemProxy,
  37. PBXTargetDependency,
  38. PBXShellScriptBuildPhase,
  39. PBXResourcesBuildPhase,
  40. PBXApplicationReference,
  41. PBXExecutableFileReference,
  42. PBXLibraryReference,
  43. PBXToolTarget,
  44. PBXLibraryTarget,
  45. PBXAggregateTarget,
  46. XCBuildConfiguration,
  47. XCConfigurationList,
  48. PBXCopyFilesBuildPhase,
  49. None
  50. };
  51. class StringVec : public std::vector<std::string>
  52. {
  53. };
  54. static const char* PBXTypeNames[];
  55. virtual ~cmXCodeObject();
  56. cmXCodeObject(PBXType ptype, Type type);
  57. Type GetType() const { return this->TypeValue; }
  58. PBXType GetIsA() const { return this->IsA; }
  59. bool IsEmpty() const;
  60. void SetString(const std::string& s);
  61. const std::string& GetString() const { return this->String; }
  62. void AddAttribute(const std::string& name, cmXCodeObject* value)
  63. {
  64. this->ObjectAttributes[name] = value;
  65. }
  66. void AddAttributeIfNotEmpty(const std::string& name, cmXCodeObject* value)
  67. {
  68. if (value && !value->IsEmpty()) {
  69. AddAttribute(name, value);
  70. }
  71. }
  72. void SetObject(cmXCodeObject* value) { this->Object = value; }
  73. cmXCodeObject* GetObject() { return this->Object; }
  74. void AddObject(cmXCodeObject* value) { this->List.push_back(value); }
  75. bool HasObject(cmXCodeObject* o) const
  76. {
  77. return !(std::find(this->List.begin(), this->List.end(), o) ==
  78. this->List.end());
  79. }
  80. void AddUniqueObject(cmXCodeObject* value)
  81. {
  82. if (std::find(this->List.begin(), this->List.end(), value) ==
  83. this->List.end()) {
  84. this->List.push_back(value);
  85. }
  86. }
  87. static void Indent(int level, std::ostream& out);
  88. void Print(std::ostream& out);
  89. void PrintAttribute(std::ostream& out, const int level,
  90. const std::string separator, const int factor,
  91. const std::string& name, const cmXCodeObject* object,
  92. const cmXCodeObject* parent);
  93. virtual void PrintComment(std::ostream&) {}
  94. static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
  95. const std::string& GetId() const { return this->Id; }
  96. void SetId(const std::string& id) { this->Id = id; }
  97. cmGeneratorTarget* GetTarget() const { return this->Target; }
  98. void SetTarget(cmGeneratorTarget* t) { this->Target = t; }
  99. const std::string& GetComment() const { return this->Comment; }
  100. bool HasComment() const { return (!this->Comment.empty()); }
  101. cmXCodeObject* GetObject(const char* name) const
  102. {
  103. std::map<std::string, cmXCodeObject*>::const_iterator i =
  104. this->ObjectAttributes.find(name);
  105. if (i != this->ObjectAttributes.end()) {
  106. return i->second;
  107. }
  108. return 0;
  109. }
  110. // search the attribute list for an object of the specified type
  111. cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
  112. {
  113. for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin();
  114. i != this->List.end(); ++i) {
  115. cmXCodeObject* o = *i;
  116. if (o->IsA == t) {
  117. return o;
  118. }
  119. }
  120. return 0;
  121. }
  122. void CopyAttributes(cmXCodeObject*);
  123. void AddDependLibrary(const std::string& configName, const std::string& l)
  124. {
  125. this->DependLibraries[configName].push_back(l);
  126. }
  127. std::map<std::string, StringVec> const& GetDependLibraries() const
  128. {
  129. return this->DependLibraries;
  130. }
  131. void AddDependTarget(const std::string& configName, const std::string& tName)
  132. {
  133. this->DependTargets[configName].push_back(tName);
  134. }
  135. std::map<std::string, StringVec> const& GetDependTargets() const
  136. {
  137. return this->DependTargets;
  138. }
  139. std::vector<cmXCodeObject*> const& GetObjectList() const
  140. {
  141. return this->List;
  142. }
  143. void SetComment(const std::string& c) { this->Comment = c; }
  144. static void PrintString(std::ostream& os, std::string String);
  145. protected:
  146. void PrintString(std::ostream& os) const;
  147. cmGeneratorTarget* Target;
  148. Type TypeValue;
  149. std::string Id;
  150. PBXType IsA;
  151. int Version;
  152. std::string Comment;
  153. std::string String;
  154. cmXCodeObject* Object;
  155. std::vector<cmXCodeObject*> List;
  156. std::map<std::string, StringVec> DependLibraries;
  157. std::map<std::string, StringVec> DependTargets;
  158. std::map<std::string, cmXCodeObject*> ObjectAttributes;
  159. };
  160. #endif