Sfoglia il codice sorgente

cmGeneratedFileStream: Use ``std::string const&`` instead of ``const char*``

Sebastian Holtermann 7 anni fa
parent
commit
a688defcc6
2 ha cambiato i file con 19 aggiunte e 18 eliminazioni
  1. 13 12
      Source/cmGeneratedFileStream.cxx
  2. 6 6
      Source/cmGeneratedFileStream.h

+ 13 - 12
Source/cmGeneratedFileStream.cxx

@@ -24,8 +24,8 @@ cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding)
 #endif
 }
 
-cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet,
-                                             Encoding encoding)
+cmGeneratedFileStream::cmGeneratedFileStream(std::string const& name,
+                                             bool quiet, Encoding encoding)
   : cmGeneratedFileStreamBase(name)
   , Stream(TempName.c_str())
 {
@@ -54,7 +54,7 @@ cmGeneratedFileStream::~cmGeneratedFileStream()
   this->Okay = !this->fail();
 }
 
-cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name,
+cmGeneratedFileStream& cmGeneratedFileStream::Open(std::string const& name,
                                                    bool quiet, bool binaryFlag)
 {
   // Store the file name and construct the temporary file name.
@@ -114,7 +114,7 @@ cmGeneratedFileStreamBase::cmGeneratedFileStreamBase()
 {
 }
 
-cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name)
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(std::string const& name)
   : Name()
   , TempName()
   , CopyIfDifferent(false)
@@ -130,7 +130,7 @@ cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
   this->Close();
 }
 
-void cmGeneratedFileStreamBase::Open(const char* name)
+void cmGeneratedFileStreamBase::Open(std::string const& name)
 {
   // Save the original name of the file.
   this->Name = name;
@@ -188,10 +188,10 @@ bool cmGeneratedFileStreamBase::Close()
 }
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
-int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
-                                            const char* newname)
+int cmGeneratedFileStreamBase::CompressFile(std::string const& oldname,
+                                            std::string const& newname)
 {
-  gzFile gf = gzopen(newname, "w");
+  gzFile gf = gzopen(newname.c_str(), "w");
   if (!gf) {
     return 0;
   }
@@ -214,16 +214,17 @@ int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
   return 1;
 }
 #else
-int cmGeneratedFileStreamBase::CompressFile(const char*, const char*)
+int cmGeneratedFileStreamBase::CompressFile(std::string const&,
+                                            std::string const&)
 {
   return 0;
 }
 #endif
 
-int cmGeneratedFileStreamBase::RenameFile(const char* oldname,
-                                          const char* newname)
+int cmGeneratedFileStreamBase::RenameFile(std::string const& oldname,
+                                          std::string const& newname)
 {
-  return cmSystemTools::RenameFile(oldname, newname);
+  return cmSystemTools::RenameFile(oldname.c_str(), newname.c_str());
 }
 
 void cmGeneratedFileStream::SetName(const std::string& fname)

+ 6 - 6
Source/cmGeneratedFileStream.h

@@ -20,7 +20,7 @@ protected:
   cmGeneratedFileStreamBase();
 
   // This constructor prepares the temporary output file.
-  cmGeneratedFileStreamBase(const char* name);
+  cmGeneratedFileStreamBase(std::string const& name);
 
   // The destructor renames the temporary output file to the real name.
   ~cmGeneratedFileStreamBase();
@@ -29,14 +29,14 @@ protected:
   // called before the real stream is opened.  Close is always called
   // after the real stream is closed and Okay is set to whether the
   // real stream was still valid for writing when it was closed.
-  void Open(const char* name);
+  void Open(std::string const& name);
   bool Close();
 
   // Internal file replacement implementation.
-  int RenameFile(const char* oldname, const char* newname);
+  int RenameFile(std::string const& oldname, std::string const& newname);
 
   // Internal file compression implementation.
-  int CompressFile(const char* oldname, const char* newname);
+  int CompressFile(std::string const& oldname, std::string const& newname);
 
   // The name of the final destination file for the output.
   std::string Name;
@@ -87,7 +87,7 @@ public:
    * file cannot be opened an error message is produced unless the
    * second argument is set to true.
    */
-  cmGeneratedFileStream(const char* name, bool quiet = false,
+  cmGeneratedFileStream(std::string const& name, bool quiet = false,
                         Encoding encoding = codecvt::None);
 
   /**
@@ -103,7 +103,7 @@ public:
    * temporary file.  If the file cannot be opened an error message is
    * produced unless the second argument is set to true.
    */
-  cmGeneratedFileStream& Open(const char* name, bool quiet = false,
+  cmGeneratedFileStream& Open(std::string const& name, bool quiet = false,
                               bool binaryFlag = false);
 
   /**