Bläddra i källkod

cmState: Add an accessor for Parent snapshot and a validity check.

Stephen Kelly 10 år sedan
förälder
incheckning
48a9e91b02
2 ändrade filer med 24 tillägg och 0 borttagningar
  1. 21 0
      Source/cmState.cxx
  2. 3 0
      Source/cmState.h

+ 21 - 0
Source/cmState.cxx

@@ -522,3 +522,24 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
     cmSystemTools::CollapseFullPath(
     cmSystemTools::CollapseFullPath(
         this->State->OutputLocations[this->Position]);
         this->State->OutputLocations[this->Position]);
 }
 }
+
+bool cmState::Snapshot::IsValid() const
+{
+  return this->State ? true : false;
+}
+
+cmState::Snapshot cmState::Snapshot::GetParent() const
+{
+  Snapshot snapshot;
+  if (!this->State)
+    {
+    return snapshot;
+    }
+  PositionType parentPos = this->State->ParentPositions[this->Position];
+  if (parentPos > 0)
+    {
+    snapshot = Snapshot(this->State, parentPos);
+    }
+
+  return snapshot;
+}

+ 3 - 0
Source/cmState.h

@@ -36,6 +36,9 @@ public:
     const char* GetCurrentBinaryDirectory() const;
     const char* GetCurrentBinaryDirectory() const;
     void SetCurrentBinaryDirectory(std::string const& dir);
     void SetCurrentBinaryDirectory(std::string const& dir);
 
 
+    bool IsValid() const;
+    Snapshot GetParent() const;
+
   private:
   private:
     friend class cmState;
     friend class cmState;
     cmState* State;
     cmState* State;