summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratedFileStream.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2005-01-26 19:25:16 (GMT)
committerBrad King <brad.king@kitware.com>2005-01-26 19:25:16 (GMT)
commitaaac6f2c3ac9e9f95f0fdad7d77b4de21568ed52 (patch)
treecbe224acc7180d02629d171ab2e8b9dadabea84f /Source/cmGeneratedFileStream.cxx
parentf6cd83d6f3dfad07cedf82e96eb371fa264abef2 (diff)
downloadCMake-aaac6f2c3ac9e9f95f0fdad7d77b4de21568ed52.zip
CMake-aaac6f2c3ac9e9f95f0fdad7d77b4de21568ed52.tar.gz
CMake-aaac6f2c3ac9e9f95f0fdad7d77b4de21568ed52.tar.bz2
ENH: Added default constructor and Open method.
Diffstat (limited to 'Source/cmGeneratedFileStream.cxx')
-rw-r--r--Source/cmGeneratedFileStream.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 254b6bf..53f3077 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -27,6 +27,12 @@
#endif
//----------------------------------------------------------------------------
+cmGeneratedFileStream::cmGeneratedFileStream():
+ cmGeneratedFileStreamBase(), Stream()
+{
+}
+
+//----------------------------------------------------------------------------
cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet):
cmGeneratedFileStreamBase(name),
Stream(m_TempName.c_str())
@@ -51,12 +57,40 @@ cmGeneratedFileStream::~cmGeneratedFileStream()
}
//----------------------------------------------------------------------------
+cmGeneratedFileStream&
+cmGeneratedFileStream::Open(const char* name, bool quiet)
+{
+ // Store the file name and construct the temporary file name.
+ this->cmGeneratedFileStreamBase::Open(name);
+
+ // Open the temporary output file.
+ this->Stream::open(m_TempName.c_str());
+
+ // Check if the file opened.
+ if(!*this && !quiet)
+ {
+ cmSystemTools::Error("Cannot open file for write: ", m_TempName.c_str());
+ cmSystemTools::ReportLastSystemError("");
+ }
+ return *this;
+}
+
+//----------------------------------------------------------------------------
void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different)
{
m_CopyIfDifferent = copy_if_different;
}
//----------------------------------------------------------------------------
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase():
+ m_Name(),
+ m_TempName(),
+ m_CopyIfDifferent(false),
+ m_Okay(false)
+{
+}
+
+//----------------------------------------------------------------------------
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
m_Name(name),
m_TempName(name),
@@ -92,6 +126,20 @@ 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());
+}
+
+//----------------------------------------------------------------------------
int cmGeneratedFileStreamBase::RenameFile(const char* oldname,
const char* newname)
{