From 9d4f3a06864b3b5fe96073ddc256ef39ab24ddad Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Fri, 15 Jun 2007 10:10:24 -0400 Subject: STYLE: remove duplicate non-const accessors GetLocalGenerator(int) and GetLocaGenerators(cmLocalGenerators) from cmGlobalGenerator(). Now there is one const accessor which is even faster since it returns a reference (instead of copying a vector) -more const to ensure that this the returned local generators don't actually get modified -removed duplicated code in GetCTestCommand() and GetCPackCommand() -added some const accessors Alex --- Source/cmExportLibraryDependencies.cxx | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'Source/cmExportLibraryDependencies.cxx') diff --git a/Source/cmExportLibraryDependencies.cxx b/Source/cmExportLibraryDependencies.cxx index 51d9498ee7..6720c3e404 100644 --- a/Source/cmExportLibraryDependencies.cxx +++ b/Source/cmExportLibraryDependencies.cxx @@ -32,38 +32,40 @@ bool cmExportLibraryDependenciesCommand } // store the arguments for the final pass - // also expand any CMake variables - - this->Args = args; + this->Filename = args[0]; + this->Append = false; + if(args.size() > 1) + { + if(args[1] == "APPEND") + { + this->Append = true; + } + } return true; } void cmExportLibraryDependenciesCommand::FinalPass() { - // Create a full path filename for output - std::string fname = this->Args[0]; - bool append = false; - if(this->Args.size() > 1) - { - if(this->Args[1] == "APPEND") - { - append = true; - } - } + // export_library_dependencies() shouldn't modify anything + // ensure this by calling a const method + this->ConstFinalPass(); +} +void cmExportLibraryDependenciesCommand::ConstFinalPass() const +{ // Use copy-if-different if not appending. cmsys::auto_ptr foutPtr; - if(append) + if(this->Append) { cmsys::auto_ptr ap( - new std::ofstream(fname.c_str(), std::ios::app)); + new std::ofstream(this->Filename.c_str(), std::ios::app)); foutPtr = ap; } else { cmsys::auto_ptr ap( - new cmGeneratedFileStream(fname.c_str(), true)); + new cmGeneratedFileStream(this->Filename.c_str(), true)); ap->SetCopyIfDifferent(true); foutPtr = ap; } @@ -71,23 +73,22 @@ void cmExportLibraryDependenciesCommand::FinalPass() if (!fout) { - cmSystemTools::Error("Error Writing ", fname.c_str()); + cmSystemTools::Error("Error Writing ", this->Filename.c_str()); cmSystemTools::ReportLastSystemError(""); return; } - cmake* cm = this->Makefile->GetCMakeInstance(); - cmGlobalGenerator* global = cm->GetGlobalGenerator(); - std::vector locals; - global->GetLocalGenerators(locals); + const cmake* cm = this->Makefile->GetCMakeInstance(); + const cmGlobalGenerator* global = cm->GetGlobalGenerator(); + const std::vector& locals = global->GetLocalGenerators(); std::string libDepName; - for(std::vector::iterator i = locals.begin(); + for(std::vector::const_iterator i = locals.begin(); i != locals.end(); ++i) { - cmLocalGenerator* gen = *i; - cmTargets &tgts = gen->GetMakefile()->GetTargets(); + const cmLocalGenerator* gen = *i; + const cmTargets &tgts = gen->GetMakefile()->GetTargets(); std::vector depends; const char *defType; - for(cmTargets::iterator l = tgts.begin(); + for(cmTargets::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { libDepName = l->first; -- cgit v1.2.1