From 9f0d8ce7722d4ed619f5f364933bc77e62c45cd9 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Thu, 8 May 2003 14:46:23 -0400
Subject: [PATCH] ENH: Reduced header dependencies and cleaned up inclusion of
 standard headers.

---
 CMakeLists.txt           | 14 ++++++++
 Configure.hxx.in         |  6 ++++
 Directory.cxx            | 73 +++++++++++++++++++++++++++++-----------
 Directory.hxx.in         | 34 +++++++++----------
 RegularExpression.hxx.in |  4 +--
 StandardIncludes.hxx.in  |  6 ----
 kwsys_std.h.in           | 15 +++++++++
 7 files changed, 105 insertions(+), 47 deletions(-)
 create mode 100644 kwsys_std.h.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6edaf3f..6b3cbf6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,20 @@ IF(KWSYS_INCLUDE_INSTALL_DIR)
                 FILES ${KWSYS_INCLUDES})
 ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
 
+#-----------------------------------------------------------------------------
+# Create STL header wrappers to block warnings in the STL headers.
+FOREACH(header algorithm deque iterator list map numeric queue set stack string
+               utility vector)
+  SET(KWSYS_STL_HEADER "${header}")
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_std.h.in
+                 ${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/std/${header}
+                 @ONLY IMMEDIATE)
+  IF(KWSYS_INCLUDE_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
+      FILES ${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/std/${header})
+  ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
+ENDFOREACH(header)
+
 IF(KWSYS_DEFAULTS)
   INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/..)
   ADD_EXECUTABLE(test1 test1.cxx)
diff --git a/Configure.hxx.in b/Configure.hxx.in
index baa9c74..68c8024 100644
--- a/Configure.hxx.in
+++ b/Configure.hxx.in
@@ -7,4 +7,10 @@
 #cmakedefine KWSYS_NO_ANSI_STRING_STREAM
 #cmakedefine KWSYS_NO_ANSI_FOR_SCOPE
 
+#if defined(KWSYS_NO_STD_NAMESPACE)
+# define kwsys_std
+#else
+# define kwsys_std std
+#endif
+
 #endif
diff --git a/Directory.cxx b/Directory.cxx
index 9003d9b..c9ad026 100644
--- a/Directory.cxx
+++ b/Directory.cxx
@@ -16,6 +16,53 @@
 =========================================================================*/
 #include <Directory.hxx>
 
+#include <std/string>
+#include <std/vector>
+
+namespace KWSYS_NAMESPACE
+{
+
+//----------------------------------------------------------------------------
+class DirectoryInternals
+{
+public:
+  // Array of Files
+  kwsys_std::vector<kwsys_std::string> Files;
+  
+  // Path to Open'ed directory
+  kwsys_std::string Path;
+};
+
+//----------------------------------------------------------------------------
+Directory::Directory()
+{
+  this->Internal = new DirectoryInternals;
+}
+
+//----------------------------------------------------------------------------
+Directory::~Directory()
+{
+  delete this->Internal;
+}
+
+//----------------------------------------------------------------------------
+unsigned long Directory::GetNumberOfFiles()
+{
+  return this->Internal->Files.size();
+}
+
+//----------------------------------------------------------------------------
+const char* Directory::GetFile(unsigned long dindex)
+{
+  if ( dindex >= this->Internal->Files.size() )
+    {
+    return 0;
+    }
+  return this->Internal->Files[dindex].c_str();
+}
+
+} // namespace KWSYS_NAMESPACE
+
 // First microsoft compilers
 
 #ifdef _MSC_VER
@@ -60,10 +107,10 @@ bool Directory::Load(const char* name)
   // Loop through names
   do 
     {
-    m_Files.push_back(data.name);
+    this->Internal->Files.push_back(data.name);
     } 
   while ( _findnext(srchHandle, &data) != -1 );
-  m_Path = name;
+  this->Internal->Path = name;
   return _findclose(srchHandle) != -1;
 }
 
@@ -75,7 +122,7 @@ bool Directory::Load(const char* name)
 
 #include <sys/types.h>
 #include <dirent.h>
-  
+
 namespace KWSYS_NAMESPACE
 {
 
@@ -90,27 +137,13 @@ bool Directory::Load(const char* name)
 
   for (dirent* d = readdir(dir); d; d = readdir(dir) )
     {
-    m_Files.push_back(d->d_name);
+    this->Internal->Files.push_back(d->d_name);
     }
-  m_Path = name;
+  this->Internal->Path = name;
   closedir(dir);
   return 1;
 }
-  
+
 } // namespace KWSYS_NAMESPACE
 
 #endif
-
-namespace KWSYS_NAMESPACE
-{
-
-const char* Directory::GetFile(size_t dindex)
-{
-  if ( dindex >= m_Files.size() )
-    {
-    return 0;
-    }
-  return m_Files[dindex].c_str();
-}
-
-} // namespace KWSYS_NAMESPACE
diff --git a/Directory.hxx.in b/Directory.hxx.in
index 8b43d9f..0a843b8 100644
--- a/Directory.hxx.in
+++ b/Directory.hxx.in
@@ -17,18 +17,13 @@
 #ifndef @KWSYS_NAMESPACE@_Directory_hxx
 #define @KWSYS_NAMESPACE@_Directory_hxx
 
-#ifdef _MSC_VER
-#pragma warning ( disable : 4786 )
-#endif
-
-#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
-
-#include <string>
-#include <vector>
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
 
 namespace @KWSYS_NAMESPACE@
 {
 
+class DirectoryInternals;
+
 /** \class Directory
  * \brief Portable directory/filename traversal.
  * 
@@ -37,33 +32,34 @@ namespace @KWSYS_NAMESPACE@
  *
  * Directory currently works with Windows and Unix operating systems.
  */
-
 class Directory 
 {
 public:
+  Directory();
+  ~Directory();
+  
   /**
    * Load the specified directory and load the names of the files
    * in that directory. 0 is returned if the directory can not be 
    * opened, 1 if it is opened.   
    */
-  bool Load(const char* dir);
-
+  bool Load(const char*);
+  
   /**
    * Return the number of files in the current directory.
    */
-  size_t GetNumberOfFiles() { return m_Files.size();}
-
+  unsigned long GetNumberOfFiles();
+  
   /**
    * Return the file at the given index, the indexing is 0 based
    */
-  const char* GetFile(size_t );
-
+  const char* GetFile(unsigned long);
+  
 private:
-  kwsys_std::vector<kwsys_std::string> m_Files; // Array of Files
-  kwsys_std::string m_Path;               // Path to Open'ed directory
-
+  // Private implementation details.
+  DirectoryInternals* Internal;
 }; // End Class: Directory
-  
+
 } // namespace @KWSYS_NAMESPACE@
 
 #endif
diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in
index 93c4066..dcd965e 100644
--- a/RegularExpression.hxx.in
+++ b/RegularExpression.hxx.in
@@ -35,9 +35,9 @@
 #ifndef @KWSYS_NAMESPACE@_RegularExpression_hxx
 #define @KWSYS_NAMESPACE@_RegularExpression_hxx
 
-#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
 
-#include <string>
+#include <@KWSYS_NAMESPACE@/std/string>
 
 namespace @KWSYS_NAMESPACE@
 {
diff --git a/StandardIncludes.hxx.in b/StandardIncludes.hxx.in
index fefa2c2..5084160 100644
--- a/StandardIncludes.hxx.in
+++ b/StandardIncludes.hxx.in
@@ -35,10 +35,4 @@
 #  include <strstream.h>
 #endif
 
-#if defined(KWSYS_NO_STD_NAMESPACE)
-# define kwsys_std
-#else
-# define kwsys_std std
-#endif
-
 #endif
diff --git a/kwsys_std.h.in b/kwsys_std.h.in
new file mode 100644
index 0000000..efb504a
--- /dev/null
+++ b/kwsys_std.h.in
@@ -0,0 +1,15 @@
+#ifndef @KWSYS_NAMESPACE@_std_@KWSYS_STL_HEADER@
+#define @KWSYS_NAMESPACE@_std_@KWSYS_STL_HEADER@
+
+#ifdef _MSC_VER
+#pragma warning (push, 1)
+#pragma warning (disable: 4702)
+#endif
+
+#include <@KWSYS_STL_HEADER@>
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#endif
-- 
GitLab