STYLE: Fix typo in GetFilenameLastExtension docs
[cmake.git] / Source / cmXCodeObject.cxx
blob1fd73ecf8690a786c9fb2677cf29d8db05ab8615
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmXCodeObject.cxx,v $
5 Language: C++
6 Date: $Date: 2008-09-02 14:27:15 $
7 Version: $Revision: 1.26 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmXCodeObject.h"
18 #include "cmSystemTools.h"
20 //----------------------------------------------------------------------------
21 const char* cmXCodeObject::PBXTypeNames[] = {
22 "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
23 "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
24 "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
25 "PBXTargetDependency", "PBXShellScriptBuildPhase",
26 "PBXResourcesBuildPhase", "PBXApplicationReference",
27 "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
28 "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
29 "XCConfigurationList",
30 "PBXCopyFilesBuildPhase",
31 "None"
34 //----------------------------------------------------------------------------
35 cmXCodeObject::~cmXCodeObject()
37 this->Version = 15;
40 //----------------------------------------------------------------------------
41 cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
43 this->Version = 15;
44 this->PBXTargetDependencyValue = 0;
45 this->Target = 0;
46 this->Object =0;
48 this->IsA = ptype;
49 if(type == OBJECT)
51 cmOStringStream str;
52 str << (void*)this;
53 str << (void*)this;
54 str << (void*)this;
55 this->Id = str.str();
57 else
59 this->Id =
60 "Temporary cmake object, should not be refered to in xcode file";
62 cmSystemTools::ReplaceString(this->Id, "0x", "");
63 this->Id = cmSystemTools::UpperCase(this->Id);
64 if(this->Id.size() < 24)
66 int diff = 24 - this->Id.size();
67 for(int i =0; i < diff; ++i)
69 this->Id += "0";
72 if(this->Id.size() > 24)
74 this->Id = this->Id.substr(0,24);
76 this->TypeValue = type;
77 if(this->TypeValue == OBJECT)
79 this->AddAttribute("isa", 0);
83 //----------------------------------------------------------------------------
84 void cmXCodeObject::Indent(int level, std::ostream& out)
86 while(level)
88 out << " ";
89 level--;
93 //----------------------------------------------------------------------------
94 void cmXCodeObject::Print(std::ostream& out)
96 std::string separator = "\n";
97 int indentFactor = 1;
98 if(this->Version > 15
99 && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
101 separator = " ";
102 indentFactor = 0;
104 cmXCodeObject::Indent(2*indentFactor, out);
105 out << this->Id << " ";
106 if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
108 this->PrintComment(out);
110 out << " = {";
111 if(separator == "\n")
113 out << separator;
115 std::map<cmStdString, cmXCodeObject*>::iterator i;
116 cmXCodeObject::Indent(3*indentFactor, out);
117 out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
118 for(i = this->ObjectAttributes.begin();
119 i != this->ObjectAttributes.end(); ++i)
121 cmXCodeObject* object = i->second;
122 if(i->first != "isa")
124 cmXCodeObject::Indent(3*indentFactor, out);
126 else
128 continue;
130 if(object->TypeValue == OBJECT_LIST)
132 out << i->first << " = (" << separator;
133 for(unsigned int k = 0; k < i->second->List.size(); k++)
135 cmXCodeObject::Indent(4*indentFactor, out);
136 out << i->second->List[k]->Id << " ";
137 i->second->List[k]->PrintComment(out);
138 out << "," << separator;
140 cmXCodeObject::Indent(3*indentFactor, out);
141 out << ");" << separator;
143 else if(object->TypeValue == ATTRIBUTE_GROUP)
145 std::map<cmStdString, cmXCodeObject*>::iterator j;
146 out << i->first << " = {" << separator;
147 for(j = object->ObjectAttributes.begin(); j !=
148 object->ObjectAttributes.end(); ++j)
150 cmXCodeObject::Indent(4 *indentFactor, out);
152 if(j->second->TypeValue == STRING)
154 out << j->first << " = ";
155 j->second->PrintString(out);
156 out << ";";
158 else if(j->second->TypeValue == OBJECT_LIST)
160 out << j->first << " = (";
161 for(unsigned int k = 0; k < j->second->List.size(); k++)
163 if(j->second->List[k]->TypeValue == STRING)
165 j->second->List[k]->PrintString(out);
166 out << ", ";
168 else
170 out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
173 out << ");";
175 else
177 out << j->first << " = error_unexpected_TypeValue_" <<
178 j->second->TypeValue << ";";
181 out << separator;
183 cmXCodeObject::Indent(3 *indentFactor, out);
184 out << "};" << separator;
186 else if(object->TypeValue == OBJECT_REF)
188 out << i->first << " = " << object->Object->Id;
189 if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
191 out << " ";
192 object->Object->PrintComment(out);
194 out << ";" << separator;
196 else if(object->TypeValue == STRING)
198 out << i->first << " = ";
199 object->PrintString(out);
200 out << ";" << separator;
202 else
204 out << "what is this?? " << i->first << "\n";
207 cmXCodeObject::Indent(2*indentFactor, out);
208 out << "};\n";
211 //----------------------------------------------------------------------------
212 void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
213 std::ostream& out)
215 cmXCodeObject::Indent(1, out);
216 out << "objects = {\n";
217 for(unsigned int i = 0; i < objs.size(); ++i)
219 if(objs[i]->TypeValue == OBJECT)
221 objs[i]->Print(out);
224 cmXCodeObject::Indent(1, out);
225 out << "};\n";
228 //----------------------------------------------------------------------------
229 void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
231 this->ObjectAttributes = copy->ObjectAttributes;
232 this->List = copy->List;
233 this->String = copy->String;
234 this->Object = copy->Object;
237 //----------------------------------------------------------------------------
238 void cmXCodeObject::PrintString(std::ostream& os) const
240 // The string needs to be quoted if it contains any characters
241 // considered special by the Xcode project file parser.
242 bool needQuote =
243 (this->String.empty() ||
244 this->String.find_first_of(" <>.+-=@") != this->String.npos);
245 const char* quote = needQuote? "\"" : "";
247 // Print the string, quoted and escaped as necessary.
248 os << quote;
249 for(std::string::const_iterator i = this->String.begin();
250 i != this->String.end(); ++i)
252 if(*i == '"')
254 // Escape double-quotes.
255 os << '\\';
257 os << *i;
259 os << quote;
262 //----------------------------------------------------------------------------
263 void cmXCodeObject::SetString(const char* s)
265 this->String = s;