Sfoglia il codice sorgente

cmMakefile: Introduce GeneratorAction as the class.

NAKAMURA Takumi 4 anni fa
parent
commit
90e1206f25
2 ha cambiato i file con 32 aggiunte e 5 eliminazioni
  1. 8 2
      Source/cmMakefile.cxx
  2. 24 3
      Source/cmMakefile.h

+ 8 - 2
Source/cmMakefile.cxx

@@ -891,12 +891,18 @@ struct file_not_persistent
 };
 }
 
-void cmMakefile::AddGeneratorAction(GeneratorAction action)
+void cmMakefile::AddGeneratorAction(GeneratorAction&& action)
 {
   assert(!this->GeneratorActionsInvoked);
   this->GeneratorActions.emplace_back(std::move(action), this->Backtrace);
 }
 
+void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg,
+                                             const cmListFileBacktrace& lfbt)
+{
+  Action(lg, lfbt);
+}
+
 void cmMakefile::DoGenerate(cmLocalGenerator& lg)
 {
   // do all the variable expansions here
@@ -904,7 +910,7 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg)
 
   // give all the commands a chance to do something
   // after the file has been parsed before generation
-  for (const BT<GeneratorAction>& action : this->GeneratorActions) {
+  for (auto& action : this->GeneratorActions) {
     action.Value(lg, action.Backtrace);
   }
   this->GeneratorActionsInvoked = true;

+ 24 - 3
Source/cmMakefile.h

@@ -140,13 +140,34 @@ public:
   bool EnforceUniqueName(std::string const& name, std::string& msg,
                          bool isCustom = false) const;
 
-  using GeneratorAction =
-    std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>;
+  class GeneratorAction
+  {
+    using ActionT =
+      std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>;
+
+  public:
+    GeneratorAction(ActionT&& action)
+      : Action(std::move(action))
+    {
+    }
+
+    void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt);
+
+  private:
+    ActionT Action;
+  };
 
   /**
    * Register an action that is executed during Generate
    */
-  void AddGeneratorAction(GeneratorAction action);
+  void AddGeneratorAction(GeneratorAction&& action);
+
+  /// Helper to insert the constructor GeneratorAction(args...)
+  template <class... Args>
+  void AddGeneratorAction(Args&&... args)
+  {
+    AddGeneratorAction(GeneratorAction(std::move(args)...));
+  }
 
   /**
    * Perform generate actions, Library dependency analysis etc before output of