cmXCodeObject.cxx 3.4 KB

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