cmXCodeObject.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. str << (void*)this;
  17. str << (void*)this;
  18. m_Id = str.str();
  19. m_Type = type;
  20. if(m_Type == OBJECT)
  21. {
  22. this->AddAttribute("isa", 0);
  23. }
  24. }
  25. //----------------------------------------------------------------------------
  26. void cmXCodeObject::Indent(int level, std::ostream& out)
  27. {
  28. while(level)
  29. {
  30. out << " ";
  31. level--;
  32. }
  33. }
  34. //----------------------------------------------------------------------------
  35. void cmXCodeObject::Print(std::ostream& out)
  36. {
  37. cmXCodeObject::Indent(2, out);
  38. out << m_Id << " = {\n";
  39. std::map<cmStdString, cmXCodeObject*>::iterator i;
  40. for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
  41. {
  42. cmXCodeObject* object = i->second;
  43. cmXCodeObject::Indent(3, out);
  44. if(i->first == "isa")
  45. {
  46. out << i->first << " = " << PBXTypeNames[m_IsA] << ";\n";
  47. }
  48. else if(object->m_Type == OBJECT_LIST)
  49. {
  50. out << i->first << " = (\n";
  51. for(unsigned int k = 0; k < i->second->m_List.size(); k++)
  52. {
  53. cmXCodeObject::Indent(4, out);
  54. out << i->second->m_List[k]->m_Id << ",\n";
  55. }
  56. cmXCodeObject::Indent(3, out);
  57. out << ");\n";
  58. }
  59. else if(object->m_Type == ATTRIBUTE_GROUP)
  60. {
  61. std::map<cmStdString, cmXCodeObject*>::iterator j;
  62. out << i->first << " = {\n";
  63. for(j = object->m_ObjectAttributes.begin(); j != object->m_ObjectAttributes.end(); ++j)
  64. {
  65. cmXCodeObject::Indent(4, out);
  66. if(object->m_String.size() )
  67. {
  68. out << j->first << " = " << j->second->m_String << ";\n";
  69. }
  70. else
  71. {
  72. out << j->first << " = " << "\"\";\n";
  73. }
  74. }
  75. cmXCodeObject::Indent(3, out);
  76. out << "};\n";
  77. }
  78. else if(object->m_Type == OBJECT_REF)
  79. {
  80. out << i->first << " = " << object->m_Object->m_Id << ";\n";
  81. }
  82. else if(object->m_Type == STRING)
  83. {
  84. if(object->m_String.size() )
  85. {
  86. out << i->first << " = " << object->m_String << ";\n";
  87. }
  88. else
  89. {
  90. out << i->first << " = " << "\"\";\n";
  91. }
  92. }
  93. else
  94. {
  95. out << "what is this?? " << i->first << "\n";
  96. }
  97. }
  98. cmXCodeObject::Indent(2, out);
  99. out << "};\n";
  100. }
  101. //----------------------------------------------------------------------------
  102. void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
  103. std::ostream& out)
  104. {
  105. cmXCodeObject::Indent(1, out);
  106. out << "objects = {\n";
  107. for(unsigned int i = 0; i < objs.size(); ++i)
  108. {
  109. if(objs[i]->m_Type == OBJECT)
  110. {
  111. objs[i]->Print(out);
  112. }
  113. }
  114. cmXCodeObject::Indent(1, out);
  115. out << "};\n";
  116. }