packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmXCodeObject.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmXCodeObject_h
13 #define cmXCodeObject_h
14
15 #include "cmStandardIncludes.h"
16 class cmTarget;
17
18 class cmXCodeObject
19 {
20 public:
21   enum Type { OBJECT_LIST, STRING, ATTRIBUTE_GROUP, OBJECT_REF, OBJECT };
22   enum PBXType { PBXGroup, PBXBuildStyle, PBXProject, PBXHeadersBuildPhase,
23                  PBXSourcesBuildPhase, PBXFrameworksBuildPhase,
24                  PBXNativeTarget, PBXFileReference, PBXBuildFile,
25                  PBXContainerItemProxy, PBXTargetDependency,
26                  PBXShellScriptBuildPhase, PBXResourcesBuildPhase,
27                  PBXApplicationReference, PBXExecutableFileReference,
28                  PBXLibraryReference, PBXToolTarget, PBXLibraryTarget,
29                  PBXAggregateTarget,XCBuildConfiguration,XCConfigurationList,
30                  PBXCopyFilesBuildPhase,
31                  None
32   };
33   class StringVec: public std::vector<cmStdString> {};
34   static const char* PBXTypeNames[];
35   virtual ~cmXCodeObject();
36   cmXCodeObject(PBXType ptype, Type type);
37   Type GetType() { return this->TypeValue;}
38   PBXType GetIsA() { return this->IsA;}
39
40   void SetString(const char* s);
41   const char* GetString()
42     {
43       return this->String.c_str();
44     }
45
46   void AddAttribute(const char* name, cmXCodeObject* value)
47     {
48       this->ObjectAttributes[name] = value;
49     }
50
51   void SetObject(cmXCodeObject* value)
52     {
53       this->Object = value;
54     }
55   cmXCodeObject* GetObject()
56     {
57       return this->Object;
58     }
59   void AddObject(cmXCodeObject* value)
60     {
61       this->List.push_back(value);
62     }
63   bool HasObject(cmXCodeObject* o)
64   {
65     return !(std::find(this->List.begin(), this->List.end(), o)
66              == this->List.end());
67   }
68   void AddUniqueObject(cmXCodeObject* value)
69   {
70     if(std::find(this->List.begin(), this->List.end(), value)
71        == this->List.end())
72       {
73       this->List.push_back(value);
74       }
75   }
76   static void Indent(int level, std::ostream& out);
77   void Print(std::ostream& out);
78   virtual void PrintComment(std::ostream&) {};
79
80   static void PrintList(std::vector<cmXCodeObject*> const&,
81                         std::ostream& out);
82   const char* GetId()
83     {
84       return this->Id.c_str();
85     }
86   void SetId(const char* id)
87     {
88       this->Id = id;
89     }
90   cmTarget* GetTarget()
91     {
92       return this->Target;
93     }
94   void SetTarget(cmTarget* t)
95     {
96       this->Target = t;
97     }
98   const char* GetComment() {return this->Comment.c_str();}
99   bool HasComment() { return (this->Comment.size() !=  0);}
100   cmXCodeObject* GetObject(const char* name)
101     {
102       if(this->ObjectAttributes.count(name))
103         {
104         return this->ObjectAttributes[name];
105         }
106       return 0;
107     }
108   // serach the attribute list for an object of the specified type
109   cmXCodeObject* GetObject(cmXCodeObject::PBXType t)
110     {
111       for(std::vector<cmXCodeObject*>::iterator i = this->List.begin();
112           i != this->List.end(); ++i)
113         {
114         cmXCodeObject* o = *i;
115         if(o->IsA == t)
116           {
117           return o;
118           }
119         }
120       return 0;
121     }
122
123   void CopyAttributes(cmXCodeObject* );
124
125   void AddDependLibrary(const char* configName,
126                         const char* l)
127     {
128       if(!configName)
129         {
130         configName = "";
131         }
132       this->DependLibraries[configName].push_back(l);
133     }
134   std::map<cmStdString, StringVec> const& GetDependLibraries()
135     {
136       return this->DependLibraries;
137     }
138   void AddDependTarget(const char* configName,
139                        const char* tName)
140     {
141       if(!configName)
142         {
143         configName = "";
144         }
145       this->DependTargets[configName].push_back(tName);
146     }
147   std::map<cmStdString, StringVec> const& GetDependTargets()
148     {
149     return this->DependTargets;
150     }
151   std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;}
152   void SetComment(const char* c) { this->Comment = c;}
153   static void PrintString(std::ostream& os,cmStdString String);
154 protected:
155   void PrintString(std::ostream& os) const;
156
157   cmTarget* Target;
158   Type TypeValue;
159   cmStdString Id;
160   PBXType IsA;
161   int Version;
162   cmStdString Comment;
163   cmStdString String;
164   cmXCodeObject* Object;
165   std::vector<cmXCodeObject*> List;
166   std::map<cmStdString, StringVec> DependLibraries;
167   std::map<cmStdString, StringVec> DependTargets;
168   std::map<cmStdString, cmXCodeObject*> ObjectAttributes;
169 };
170 #endif