ENH: Renamed cmStringStream to cmOStringStream and added cmIStringStream. Removed cmInputStringStream.

This commit is contained in:
Brad King 2002-10-10 10:43:59 -04:00
parent 65cc289047
commit 281f7519e1
9 changed files with 128 additions and 117 deletions

View File

@ -35,7 +35,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args)
sscanf(args[1].c_str(), "%f", &reqVersion); sscanf(args[1].c_str(), "%f", &reqVersion);
if(reqVersion > version) if(reqVersion > version)
{ {
cmStringStream str; cmOStringStream str;
str << "WARNING: This project requires version: " << args[1].c_str() << " of cmake.\n" str << "WARNING: This project requires version: " << args[1].c_str() << " of cmake.\n"
<< "You are running version: " << version; << "You are running version: " << version;
cmSystemTools::Message(str.str().c_str()); cmSystemTools::Message(str.str().c_str());

View File

@ -221,7 +221,7 @@ void cmLocalBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout
command += "-e"; command += "-e";
command += target; command += target;
command += " "; command += " ";
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, name, t); this->OutputLinkLibraries(linklibs, name, t);
// then the linker options -L and libraries (any other order will fail!) // then the linker options -L and libraries (any other order will fail!)
command += linklibs.str(); command += linklibs.str();
@ -321,7 +321,7 @@ void cmLocalBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
{ {
command += " -tWC "; command += " -tWC ";
} }
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, 0, t); this->OutputLinkLibraries(linklibs, 0, t);
command += linklibs.str(); command += linklibs.str();
command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ")"; command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ")";

View File

@ -407,7 +407,7 @@ void cmLocalNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") "; command += " $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, name, t); this->OutputLinkLibraries(linklibs, name, t);
command += linklibs.str(); command += linklibs.str();
@ -528,7 +528,7 @@ void cmLocalNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout,
command += " /subsystem:windows "; command += " /subsystem:windows ";
} }
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, 0, t); this->OutputLinkLibraries(linklibs, 0, t);
command += linklibs.str(); command += linklibs.str();

View File

@ -652,7 +652,7 @@ void cmLocalUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
libName = cmSystemTools::ConvertToOutputPath(libName.c_str()); libName = cmSystemTools::ConvertToOutputPath(libName.c_str());
command2 += libName + " \\\n"; command2 += libName + " \\\n";
command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") "; command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, name, t); this->OutputLinkLibraries(linklibs, name, t);
command2 += linklibs.str(); command2 += linklibs.str();
std::string customCommands = this->CreateTargetRules(t, name); std::string customCommands = this->CreateTargetRules(t, name);
@ -694,7 +694,7 @@ void cmLocalUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
libName = cmSystemTools::ConvertToOutputPath(libName.c_str()); libName = cmSystemTools::ConvertToOutputPath(libName.c_str());
command2 += libName + " \\\n"; command2 += libName + " \\\n";
command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") "; command2 += "\t $(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, std::string(name).c_str(), t); this->OutputLinkLibraries(linklibs, std::string(name).c_str(), t);
command2 += linklibs.str(); command2 += linklibs.str();
std::string customCommands = this->CreateTargetRules(t, name); std::string customCommands = this->CreateTargetRules(t, name);
@ -771,7 +771,7 @@ void cmLocalUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
"$(CMAKE_C_COMPILER) $(CMAKE_C_SHLIB_LINK_FLAGS) $(CMAKE_C_FLAGS) "; "$(CMAKE_C_COMPILER) $(CMAKE_C_SHLIB_LINK_FLAGS) $(CMAKE_C_FLAGS) ";
} }
command += "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") "; command += "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
cmStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, 0, t); this->OutputLinkLibraries(linklibs, 0, t);
command += linklibs.str(); command += linklibs.str();
std::string outputFile = m_ExecutableOutputPath + name; std::string outputFile = m_ExecutableOutputPath + name;

View File

@ -162,65 +162,76 @@ struct cmStdString : public std::string
StdString(s, pos, n) {} StdString(s, pos, n) {}
}; };
// Define cmStringStream wrapper to hide differences between // Define cmOStringStream and cmIStringStream wrappers to hide
// std::stringstream and the old strstream. // differences between std::stringstream and the old strstream.
#if !defined(CMAKE_NO_ANSI_STRING_STREAM) #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
class cmStringStream: public std::ostringstream class cmOStringStream: public std::ostringstream
{ {
public: public:
cmStringStream() {} cmOStringStream() {}
private: private:
cmStringStream(const cmStringStream&); cmOStringStream(const cmOStringStream&);
void operator=(const cmStringStream&); void operator=(const cmOStringStream&);
}; };
class cmInputStringStream: public std::istringstream class cmIStringStream: public std::istringstream
{ {
public: public:
typedef std::istringstream Superclass; typedef std::istringstream Superclass;
cmInputStringStream() {} cmIStringStream() {}
cmInputStringStream(const char* c) : Superclass(c) {} cmIStringStream(const std::string& s): Superclass(s) {}
private: private:
cmInputStringStream(const cmInputStringStream&); cmIStringStream(const cmIStringStream&);
void operator=(const cmInputStringStream&); void operator=(const cmIStringStream&);
}; };
#else #else
class cmStrStreamCleanup class cmOStrStreamCleanup
{ {
public: public:
cmStrStreamCleanup(std::ostrstream& ostr): m_StrStream(ostr) {} cmOStrStreamCleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
~cmStrStreamCleanup() { m_StrStream.rdbuf()->freeze(0); } ~cmOStrStreamCleanup() { m_OStrStream.rdbuf()->freeze(0); }
static void IgnoreUnusedVariable(const cmStrStreamCleanup&) {} static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
protected: protected:
std::ostrstream& m_StrStream; std::ostrstream& m_OStrStream;
}; };
class cmStringStream: public std::ostrstream class cmOStringStream: public std::ostrstream
{ {
public: public:
typedef std::ostrstream Superclass; typedef std::ostrstream Superclass;
cmStringStream() {} cmOStringStream() {}
std::string str() std::string str()
{ {
cmStrStreamCleanup cleanup(*this); cmOStrStreamCleanup cleanup(*this);
cmStrStreamCleanup::IgnoreUnusedVariable(cleanup); cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
int pcount = this->pcount(); int pcount = this->pcount();
const char* ptr = this->Superclass::str(); const char* ptr = this->Superclass::str();
return std::string(ptr?ptr:"", pcount); return std::string(ptr?ptr:"", pcount);
} }
private: private:
cmStringStream(const cmStringStream&); cmOStringStream(const cmOStringStream&);
void operator=(const cmStringStream&); void operator=(const cmOStringStream&);
}; };
class cmInputStringStream: public std::istrstream
class cmIStringStream: private std::string, public std::istrstream
{ {
public: public:
typedef std::istrstream Superclass; typedef std::string StdString;
cmInputStringStream(const char* c) : Superclass(c) {} typedef std::istrstream IStrStream;
cmIStringStream(): StdString(), IStrStream(this->StdString::c_str()) {}
cmIStringStream(const std::string& s):
StdString(s), IStrStream(this->StdString::c_str()) {}
std::string str() const { return *this; }
void str(const std::string& s)
{
// Very dangerous. If this throws, the object is hosed. When the
// destructor is later called, the program is hosed too.
this->~cmIStringStream();
new (this) cmIStringStream(s);
}
private: private:
cmInputStringStream(const cmInputStringStream&); cmIStringStream(const cmIStringStream&);
void operator=(const cmInputStringStream&); void operator=(const cmIStringStream&);
}; };
#endif #endif
#endif #endif

View File

@ -1083,7 +1083,7 @@ bool cmSystemTools::FilesDiffer(const char* source,
if(statSource.st_size != static_cast<long>(finSource.gcount()) || if(statSource.st_size != static_cast<long>(finSource.gcount()) ||
statSource.st_size != static_cast<long>(finDestination.gcount())) statSource.st_size != static_cast<long>(finDestination.gcount()))
{ {
cmStringStream msg; cmOStringStream msg;
msg << "FilesDiffer failed to read files (allocated: " msg << "FilesDiffer failed to read files (allocated: "
<< statSource.st_size << ", read source: " << finSource.gcount() << statSource.st_size << ", read source: " << finSource.gcount()
<< ", read dest: " << finDestination.gcount(); << ", read dest: " << finDestination.gcount();
@ -1190,7 +1190,7 @@ void cmSystemTools::cmCopyFile(const char* source,
if (statSource.st_size != statDestination.st_size) if (statSource.st_size != statDestination.st_size)
{ {
cmStringStream msg; cmOStringStream msg;
msg << "CopyFile failed to copy files (sizes differ, source: " msg << "CopyFile failed to copy files (sizes differ, source: "
<< statSource.st_size << " , dest: " << statDestination.st_size; << statSource.st_size << " , dest: " << statDestination.st_size;
cmSystemTools::Error(msg.str().c_str()); cmSystemTools::Error(msg.str().c_str());
@ -1426,7 +1426,7 @@ bool RunCommandViaPopen(const char* command,
if (WIFSIGNALED(retVal)) if (WIFSIGNALED(retVal))
{ {
retVal = WTERMSIG(retVal); retVal = WTERMSIG(retVal);
cmStringStream error; cmOStringStream error;
error << "\nProcess terminated due to "; error << "\nProcess terminated due to ";
switch (retVal) switch (retVal)
{ {

View File

@ -326,7 +326,7 @@ cmVTKMakeInstantiatorCommand
std::string std::string
cmVTKMakeInstantiatorCommand::OldGenerateCreationFileName(unsigned int block) cmVTKMakeInstantiatorCommand::OldGenerateCreationFileName(unsigned int block)
{ {
cmStringStream nameStr; cmOStringStream nameStr;
nameStr << m_ClassName.c_str() << block << ".cxx"; nameStr << m_ClassName.c_str() << block << ".cxx";
std::string result = nameStr.str(); std::string result = nameStr.str();
return result; return result;

View File

@ -95,7 +95,7 @@ void cmake::AddCommand(cmCommand* wg)
void cmake::Usage(const char* program) void cmake::Usage(const char* program)
{ {
cmStringStream errorStream; cmOStringStream errorStream;
errorStream << "cmake version " << cmMakefile::GetMajorVersion() errorStream << "cmake version " << cmMakefile::GetMajorVersion()
<< "." << cmMakefile::GetMinorVersion() << "\n"; << "." << cmMakefile::GetMinorVersion() << "\n";
@ -332,7 +332,7 @@ int cmake::AddCMakePaths(const char *arg0)
if(!cmSystemTools::FileExists(cMakeSelf.c_str())) if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
{ {
failures.push_back(cMakeSelf); failures.push_back(cMakeSelf);
cmStringStream msg; cmOStringStream msg;
msg << "CMAKE can not find the command line program cmake.\n"; msg << "CMAKE can not find the command line program cmake.\n";
msg << " argv[0] = \"" << arg0 << "\"\n"; msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n"; msg << " Attempted paths:\n";
@ -444,7 +444,7 @@ int cmake::AddCMakePaths(const char *arg0)
void CMakeCommandUsage(const char* program) void CMakeCommandUsage(const char* program)
{ {
cmStringStream errorStream; cmOStringStream errorStream;
errorStream errorStream
<< "cmake version " << cmMakefile::GetMajorVersion() << "cmake version " << cmMakefile::GetMajorVersion()

View File

@ -475,7 +475,7 @@ int ctest::BuildDirectory()
// 1 - error // 1 - error
// > 1 - warning // > 1 - warning
std::vector<int> markedLines; std::vector<int> markedLines;
cmInputStringStream istr(coutput); cmIStringStream istr(coutput);
while(istr) while(istr)
{ {
char buffer[1024]; char buffer[1024];