cmXCodeObject.cxx 3.6 KB

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