summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratedFileStream.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2005-04-05 12:25:21 (GMT)
committerBrad King <brad.king@kitware.com>2005-04-05 12:25:21 (GMT)
commit389f24f777b790b12759184c96c4690a771f941b (patch)
treee5c4106ba13859b4fd1047f0de051b2689de814c /Source/cmGeneratedFileStream.cxx
parent2681215256835253cf18d47d314b3202df8e9651 (diff)
downloadCMake-389f24f777b790b12759184c96c4690a771f941b.zip
CMake-389f24f777b790b12759184c96c4690a771f941b.tar.gz
CMake-389f24f777b790b12759184c96c4690a771f941b.tar.bz2
ENH: Added Close method and updated Open method to allow streams to be reused.
Diffstat (limited to 'Source/cmGeneratedFileStream.cxx')
-rw-r--r--Source/cmGeneratedFileStream.cxx52
1 files changed, 35 insertions, 17 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 2b2e940..8aa51f7 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -80,6 +80,22 @@ cmGeneratedFileStream::Open(const char* name, bool quiet)
}
//----------------------------------------------------------------------------
+cmGeneratedFileStream&
+cmGeneratedFileStream::Close()
+{
+ // Save whether the temporary output file is valid before closing.
+ m_Okay = (*this)?true:false;
+
+ // Close the temporary output file.
+ this->Stream::close();
+
+ // Remove the temporary file (possibly by renaming to the real file).
+ this->cmGeneratedFileStreamBase::Close();
+
+ return *this;
+}
+
+//----------------------------------------------------------------------------
void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different)
{
m_CopyIfDifferent = copy_if_different;
@@ -103,13 +119,29 @@ cmGeneratedFileStreamBase::cmGeneratedFileStreamBase():
//----------------------------------------------------------------------------
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
- m_Name(name),
- m_TempName(name),
+ m_Name(),
+ m_TempName(),
m_CopyIfDifferent(false),
m_Okay(false),
m_Compress(false)
{
+ this->Open(name);
+}
+
+//----------------------------------------------------------------------------
+cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
+{
+ this->Close();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratedFileStreamBase::Open(const char* name)
+{
+ // Save the original name of the file.
+ m_Name = name;
+
// Create the name of the temporary file.
+ m_TempName = name;
m_TempName += ".tmp";
// Make sure the temporary file that will be used is not present.
@@ -117,7 +149,7 @@ cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
}
//----------------------------------------------------------------------------
-cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
+void cmGeneratedFileStreamBase::Close()
{
std::string resname = m_Name;
if ( m_Compress )
@@ -155,20 +187,6 @@ cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
}
//----------------------------------------------------------------------------
-void cmGeneratedFileStreamBase::Open(const char* name)
-{
- // Save the original name of the file.
- m_Name = name;
-
- // Create the name of the temporary file.
- m_TempName = name;
- m_TempName += ".tmp";
-
- // Make sure the temporary file that will be used is not present.
- cmSystemTools::RemoveFile(m_TempName.c_str());
-}
-
-//----------------------------------------------------------------------------
#ifdef CMAKE_BUILD_WITH_CMAKE
int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
const char* newname)