Browse Source

cmDepends: Define DependencyMap instead of DependencyVector

In `cmDepends` use
`typedef std::map<std::string, std::vector<std::string>> DependencyMap`
instead of defining a
`class DependencyVector : public std::vector<std::string>`
and using it in `std::map<std::string, DependencyVector>`.

Since `std::map<std::string, std::vector<std::string>>` is used in various
other places, we now reuse all of it's auto generated methods.  This doesn't
happen when we use `DependencyVector` in a `std::map`, because it is a
different class than `std::vector<std::string>`.
Sebastian Holtermann 6 years ago
parent
commit
87341d8328

+ 5 - 5
Source/cmDepends.cxx

@@ -61,7 +61,7 @@ bool cmDepends::Finalize(std::ostream& /*unused*/, std::ostream& /*unused*/)
 
 bool cmDepends::Check(const std::string& makeFile,
                       const std::string& internalFile,
-                      std::map<std::string, DependencyVector>& validDeps)
+                      DependencyMap& validDeps)
 {
   // Check whether dependencies must be regenerated.
   bool okay = true;
@@ -101,9 +101,9 @@ bool cmDepends::WriteDependencies(const std::set<std::string>& /*unused*/,
   return false;
 }
 
-bool cmDepends::CheckDependencies(
-  std::istream& internalDepends, const std::string& internalDependsFileName,
-  std::map<std::string, DependencyVector>& validDeps)
+bool cmDepends::CheckDependencies(std::istream& internalDepends,
+                                  const std::string& internalDependsFileName,
+                                  DependencyMap& validDeps)
 {
   // Read internal depends file time
   cmFileTime internalDependsTime;
@@ -124,7 +124,7 @@ bool cmDepends::CheckDependencies(
   std::string dependee;
   cmFileTime dependerTime;
   cmFileTime dependeeTime;
-  DependencyVector* currentDependencies = nullptr;
+  std::vector<std::string>* currentDependencies = nullptr;
 
   while (std::getline(internalDepends, line)) {
     // Check if this an empty or a comment line

+ 7 - 8
Source/cmDepends.h

@@ -23,6 +23,9 @@ class cmLocalGenerator;
  */
 class cmDepends
 {
+public:
+  typedef std::map<std::string, std::vector<std::string>> DependencyMap;
+
 public:
   /** Instances need to know the build directory name and the relative
       path from the build directory to the target file.  */
@@ -55,17 +58,13 @@ public:
   /** Write dependencies for the target file.  */
   bool Write(std::ostream& makeDepends, std::ostream& internalDepends);
 
-  class DependencyVector : public std::vector<std::string>
-  {
-  };
-
   /** Check dependencies for the target file.  Returns true if
       dependencies are okay and false if they must be generated.  If
       they must be generated Clear has already been called to wipe out
       the old dependencies.
       Dependencies which are still valid will be stored in validDeps. */
   bool Check(const std::string& makeFile, const std::string& internalFile,
-             std::map<std::string, DependencyVector>& validDeps);
+             DependencyMap& validDeps);
 
   /** Clear dependencies for the target file so they will be regenerated.  */
   void Clear(const std::string& file);
@@ -84,9 +83,9 @@ protected:
   // Check dependencies for the target file in the given stream.
   // Return false if dependencies must be regenerated and true
   // otherwise.
-  virtual bool CheckDependencies(
-    std::istream& internalDepends, const std::string& internalDependsFileName,
-    std::map<std::string, DependencyVector>& validDeps);
+  virtual bool CheckDependencies(std::istream& internalDepends,
+                                 const std::string& internalDependsFileName,
+                                 DependencyMap& validDeps);
 
   // Finalize the dependency information for the target.
   virtual bool Finalize(std::ostream& makeDepends,

+ 3 - 5
Source/cmDependsC.cxx

@@ -21,9 +21,8 @@
 
 cmDependsC::cmDependsC() = default;
 
-cmDependsC::cmDependsC(
-  cmLocalGenerator* lg, const std::string& targetDir, const std::string& lang,
-  const std::map<std::string, DependencyVector>* validDeps)
+cmDependsC::cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
+                       const std::string& lang, const DependencyMap* validDeps)
   : cmDepends(lg, targetDir)
   , ValidDeps(validDeps)
 {
@@ -102,8 +101,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
     this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj);
 
   if (this->ValidDeps != nullptr) {
-    std::map<std::string, DependencyVector>::const_iterator tmpIt =
-      this->ValidDeps->find(obj_i);
+    auto const tmpIt = this->ValidDeps->find(obj_i);
     if (tmpIt != this->ValidDeps->end()) {
       dependencies.insert(tmpIt->second.begin(), tmpIt->second.end());
       haveDeps = true;

+ 2 - 3
Source/cmDependsC.h

@@ -27,8 +27,7 @@ public:
       relative path from the build directory to the target file.  */
   cmDependsC();
   cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
-             const std::string& lang,
-             const std::map<std::string, DependencyVector>* validDeps);
+             const std::string& lang, const DependencyMap* validDeps);
 
   /** Virtual destructor to cleanup subclasses properly.  */
   ~cmDependsC() override;
@@ -81,7 +80,7 @@ public:
   };
 
 protected:
-  const std::map<std::string, DependencyVector>* ValidDeps = nullptr;
+  const DependencyMap* ValidDeps = nullptr;
   std::set<std::string> Encountered;
   std::queue<UnscannedEntry> Unscanned;
 

+ 1 - 2
Source/cmDependsJava.cxx

@@ -24,8 +24,7 @@ bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
 
 bool cmDependsJava::CheckDependencies(
   std::istream& /*internalDepends*/,
-  const std::string& /*internalDependsFileName*/,
-  std::map<std::string, DependencyVector>& /*validDeps*/)
+  const std::string& /*internalDependsFileName*/, DependencyMap& /*validDeps*/)
 {
   return true;
 }

+ 3 - 4
Source/cmDependsJava.h

@@ -8,7 +8,6 @@
 #include "cmDepends.h"
 
 #include <iosfwd>
-#include <map>
 #include <set>
 #include <string>
 
@@ -33,9 +32,9 @@ protected:
   bool WriteDependencies(const std::set<std::string>& sources,
                          const std::string& file, std::ostream& makeDepends,
                          std::ostream& internalDepends) override;
-  bool CheckDependencies(
-    std::istream& internalDepends, const std::string& internalDependsFileName,
-    std::map<std::string, DependencyVector>& validDeps) override;
+  bool CheckDependencies(std::istream& internalDepends,
+                         const std::string& internalDependsFileName,
+                         DependencyMap& validDeps) override;
 };
 
 #endif

+ 2 - 3
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1312,7 +1312,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
   // The build.make file may have explicit dependencies for the object
   // files but these will not affect the scanning process so they need
   // not be considered.
-  std::map<std::string, cmDepends::DependencyVector> validDependencies;
+  cmDepends::DependencyMap validDependencies;
   bool needRescanDependencies = false;
   if (!needRescanDirInfo) {
     cmDependsC checker;
@@ -1352,8 +1352,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
 
 bool cmLocalUnixMakefileGenerator3::ScanDependencies(
   std::string const& targetDir, std::string const& dependFile,
-  std::string const& internalDependFile,
-  std::map<std::string, cmDepends::DependencyVector>& validDeps)
+  std::string const& internalDependFile, cmDepends::DependencyMap& validDeps)
 {
   // Read the directory information file.
   cmMakefile* mf = this->Makefile;

+ 5 - 6
Source/cmLocalUnixMakefileGenerator3.h

@@ -143,8 +143,7 @@ public:
 
   // File pairs for implicit dependency scanning.  The key of the map
   // is the depender and the value is the explicit dependee.
-  struct ImplicitDependFileMap
-    : public std::map<std::string, cmDepends::DependencyVector>
+  struct ImplicitDependFileMap : public cmDepends::DependencyMap
   {
   };
   struct ImplicitDependLanguageMap
@@ -230,10 +229,10 @@ protected:
                           const char* filename = nullptr);
 
   // Helper methods for dependency updates.
-  bool ScanDependencies(
-    std::string const& targetDir, std::string const& dependFile,
-    std::string const& internalDependFile,
-    std::map<std::string, cmDepends::DependencyVector>& validDeps);
+  bool ScanDependencies(std::string const& targetDir,
+                        std::string const& dependFile,
+                        std::string const& internalDependFile,
+                        cmDepends::DependencyMap& validDeps);
   void CheckMultipleOutputs(bool verbose);
 
 private: