Browse Source

Manage current local generator with automatic var

The cmLocalGenerator::Configure method sets its cmLocalGenerator
instance as the global generator's current local generator during
configuration.  This commit refactors management of the current local
generator to use an automatic variable.  This will allow early returns
from the method.
Brad King 16 years ago
parent
commit
a6890a1673
1 changed files with 22 additions and 5 deletions
  1. 22 5
      Source/cmLocalGenerator.cxx

+ 22 - 5
Source/cmLocalGenerator.cxx

@@ -68,11 +68,30 @@ cmLocalGenerator::~cmLocalGenerator()
   delete this->Makefile;
   delete this->Makefile;
 }
 }
 
 
+//----------------------------------------------------------------------------
+class cmLocalGeneratorCurrent
+{
+  cmGlobalGenerator* GG;
+  cmLocalGenerator* LG;
+public:
+  cmLocalGeneratorCurrent(cmLocalGenerator* lg)
+    {
+    this->GG = lg->GetGlobalGenerator();
+    this->LG = this->GG->GetCurrentLocalGenerator();
+    this->GG->SetCurrentLocalGenerator(lg);
+    }
+  ~cmLocalGeneratorCurrent()
+    {
+    this->GG->SetCurrentLocalGenerator(this->LG);
+    }
+};
+
+//----------------------------------------------------------------------------
 void cmLocalGenerator::Configure()
 void cmLocalGenerator::Configure()
 {
 {
-  cmLocalGenerator* previousLg = 
-                        this->GetGlobalGenerator()->GetCurrentLocalGenerator();
-  this->GetGlobalGenerator()->SetCurrentLocalGenerator(this);
+  // Manage the global generator's current local generator.
+  cmLocalGeneratorCurrent clg(this);
+  static_cast<void>(clg);
 
 
   // make sure the CMakeFiles dir is there
   // make sure the CMakeFiles dir is there
   std::string filesDir = this->Makefile->GetStartOutputDirectory();
   std::string filesDir = this->Makefile->GetStartOutputDirectory();
@@ -141,8 +160,6 @@ void cmLocalGenerator::Configure()
   }
   }
 
 
   this->Configured = true;
   this->Configured = true;
-
-  this->GetGlobalGenerator()->SetCurrentLocalGenerator(previousLg);
 }
 }
 
 
 void cmLocalGenerator::SetupPathConversions()
 void cmLocalGenerator::SetupPathConversions()