Sfoglia il codice sorgente

Xcode: Add function to conditionally add Xcode Attributes

Gregor Jasny 9 anni fa
parent
commit
82ebbf683e
2 ha cambiato i file con 25 aggiunte e 0 eliminazioni
  1. 16 0
      Source/cmXCodeObject.cxx
  2. 9 0
      Source/cmXCodeObject.h

+ 16 - 0
Source/cmXCodeObject.cxx

@@ -83,6 +83,22 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
   }
 }
 
+bool cmXCodeObject::IsEmpty() const
+{
+  switch (this->TypeValue) {
+    case OBJECT_LIST:
+      return this->List.empty();
+    case STRING:
+      return this->String.empty();
+    case ATTRIBUTE_GROUP:
+      return this->ObjectAttributes.empty();
+    case OBJECT_REF:
+    case OBJECT:
+      return this->Object == 0;
+  }
+  return true; // unreachable, but quiets warnings
+}
+
 void cmXCodeObject::Indent(int level, std::ostream& out)
 {
   while (level) {

+ 9 - 0
Source/cmXCodeObject.h

@@ -62,6 +62,8 @@ public:
   Type GetType() const { return this->TypeValue; }
   PBXType GetIsA() const { return this->IsA; }
 
+  bool IsEmpty() const;
+
   void SetString(const std::string& s);
   const std::string& GetString() const { return this->String; }
 
@@ -70,6 +72,13 @@ public:
     this->ObjectAttributes[name] = value;
   }
 
+  void AddAttributeIfNotEmpty(const std::string& name, cmXCodeObject* value)
+  {
+    if (value && !value->IsEmpty()) {
+      AddAttribute(name, value);
+    }
+  }
+
   void SetObject(cmXCodeObject* value) { this->Object = value; }
   cmXCodeObject* GetObject() { return this->Object; }
   void AddObject(cmXCodeObject* value) { this->List.push_back(value); }