cmXCodeObject.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "cmXCodeObject.h"
  2. const char* cmXCodeObject::PBXTypeNames[] = {
  3. "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
  4. "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
  5. "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy", "PBXTargetDependency",
  6. "PBXShellScriptBuildPhase", "PBXResourcesBuildPhase", "PBXApplicationReference",
  7. "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget", "PBXLibraryTarget",
  8. "None"
  9. };
  10. //----------------------------------------------------------------------------
  11. cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
  12. {
  13. m_IsA = ptype;
  14. cmOStringStream str;
  15. str << (void*)this;
  16. m_Id = str.str();
  17. m_Type = type;
  18. if(m_Type == OBJECT)
  19. {
  20. this->AddAttribute("isa", 0);
  21. }
  22. }
  23. //----------------------------------------------------------------------------
  24. void cmXCodeObject::Indent(int level, std::ostream& out)
  25. {
  26. while(level)
  27. {
  28. out << " ";
  29. level--;
  30. }
  31. }
  32. //----------------------------------------------------------------------------
  33. void cmXCodeObject::Print(std::ostream& out)
  34. {
  35. cmXCodeObject::Indent(2, out);
  36. out << m_Id << " = {\n";
  37. std::map<cmStdString, cmXCodeObject*>::iterator i;
  38. for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
  39. {
  40. cmXCodeObject* object = i->second;
  41. cmXCodeObject::Indent(3, out);
  42. if(i->first == "isa")
  43. {
  44. out << i->first << " = " << PBXTypeNames[m_IsA] << ";\n";
  45. }
  46. else if(object->m_Type == OBJECT_LIST)
  47. {
  48. out << i->first << " = {\n";
  49. for(unsigned int k = 0; k < i->second->m_List.size(); k++)
  50. {
  51. cmXCodeObject::Indent(4, out);
  52. out << i->second->m_List[k]->m_Id << ",\n";
  53. }
  54. cmXCodeObject::Indent(3, out);
  55. out << "};\n";
  56. }
  57. else if(object->m_Type == ATTRIBUTE_GROUP)
  58. {
  59. std::map<cmStdString, cmXCodeObject*>::iterator j;
  60. out << i->first << " = {\n";
  61. for(j = object->m_ObjectAttributes.begin(); j != object->m_ObjectAttributes.end(); ++j)
  62. {
  63. cmXCodeObject::Indent(4, out);
  64. out << j->first << " = " << j->second->m_String << ";\n";
  65. }
  66. cmXCodeObject::Indent(3, out);
  67. out << "}\n";
  68. }
  69. else if(object->m_Type == OBJECT_REF)
  70. {
  71. out << i->first << " = " << object->m_Object->m_Id << ";\n";
  72. }
  73. else if(object->m_Type == STRING)
  74. {
  75. out << i->first << " = " << object->m_String << ";\n";
  76. }
  77. }
  78. cmXCodeObject::Indent(2, out);
  79. out << "};\n";
  80. }
  81. //----------------------------------------------------------------------------
  82. void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
  83. std::ostream& out)
  84. {
  85. cmXCodeObject::Indent(1, out);
  86. out << "objects = {\n";
  87. for(unsigned int i = 0; i < objs.size(); ++i)
  88. {
  89. if(objs[i]->m_Type == OBJECT)
  90. {
  91. objs[i]->Print(out);
  92. }
  93. }
  94. cmXCodeObject::Indent(1, out);
  95. out << "};\n";
  96. }