From 4308eb3d165dfc473182021c12ec877e388f60a2 Mon Sep 17 00:00:00 2001 From: Artur Ryt Date: Fri, 30 Nov 2018 20:08:44 +0100 Subject: cmDocumentationSection: Remove unused parameter in constructor --- Source/cmDocumentation.cxx | 24 +++++++++--------------- Source/cmDocumentationSection.h | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 2dfba04..a85a134 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -176,7 +176,7 @@ void cmDocumentation::addCommonStandardDocSections() { cmDocumentationSection* sec; - sec = new cmDocumentationSection("Options", "OPTIONS"); + sec = new cmDocumentationSection("Options"); sec->Append(cmDocumentationStandardOptions); this->AllSections["Options"] = sec; } @@ -185,7 +185,7 @@ void cmDocumentation::addCMakeStandardDocSections() { cmDocumentationSection* sec; - sec = new cmDocumentationSection("Generators", "GENERATORS"); + sec = new cmDocumentationSection("Generators"); sec->Append(cmDocumentationGeneratorsHeader); this->AllSections["Generators"] = sec; } @@ -201,7 +201,7 @@ void cmDocumentation::addCPackStandardDocSections() { cmDocumentationSection* sec; - sec = new cmDocumentationSection("Generators", "GENERATORS"); + sec = new cmDocumentationSection("Generators"); sec->Append(cmDocumentationGeneratorsHeader); this->AllSections["Generators"] = sec; } @@ -375,16 +375,14 @@ void cmDocumentation::SetSection(const char* name, void cmDocumentation::SetSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + cmDocumentationSection* sec = new cmDocumentationSection(name); sec->Append(docs); this->SetSection(name, sec); } void cmDocumentation::SetSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + cmDocumentationSection* sec = new cmDocumentationSection(name); sec->Append(docs); this->SetSection(name, sec); } @@ -401,8 +399,7 @@ void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) { cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + sec = new cmDocumentationSection(name); this->SetSection(name, sec); } else { sec = this->AllSections[name]; @@ -415,8 +412,7 @@ void cmDocumentation::PrependSection(const char* name, { cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + sec = new cmDocumentationSection(name); this->SetSection(name, sec); } else { sec = this->AllSections[name]; @@ -428,8 +424,7 @@ void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) { cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + sec = new cmDocumentationSection(name); this->SetSection(name, sec); } else { sec = this->AllSections[name]; @@ -442,8 +437,7 @@ void cmDocumentation::AppendSection(const char* name, { cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); + sec = new cmDocumentationSection(name); this->SetSection(name, sec); } else { sec = this->AllSections[name]; diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index d9e8187..7031b52 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -19,7 +19,7 @@ class cmDocumentationSection { public: /** Create a cmSection, with a special name for man-output mode. */ - cmDocumentationSection(const char* name, const char*) + explicit cmDocumentationSection(const char* name) : Name(name) { } -- cgit v0.12 From 57862079d8956d30711559eadbf0da31b39917f1 Mon Sep 17 00:00:00 2001 From: Artur Ryt Date: Fri, 30 Nov 2018 20:08:50 +0100 Subject: cmDocumentation: Get rid of raw pointers in AllSections map Also simplify a lot of logic around adding sections into it. Prefer move sematics over references. --- Source/cmDocumentation.cxx | 113 ++++++++++++++------------------------------- Source/cmDocumentation.h | 11 ++--- 2 files changed, 40 insertions(+), 84 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index a85a134..fafb079 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDocumentation.h" -#include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" #include "cmRST.h" @@ -55,11 +54,6 @@ cmDocumentation::cmDocumentation() this->ShowGenerators = true; } -cmDocumentation::~cmDocumentation() -{ - cmDeleteAll(this->AllSections); -} - bool cmDocumentation::PrintVersion(std::ostream& os) { /* clang-format off */ @@ -174,20 +168,16 @@ void cmDocumentation::WarnFormFromFilename( void cmDocumentation::addCommonStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Options"); - sec->Append(cmDocumentationStandardOptions); - this->AllSections["Options"] = sec; + cmDocumentationSection sec{ "Options" }; + sec.Append(cmDocumentationStandardOptions); + this->AllSections.emplace("Options", std::move(sec)); } void cmDocumentation::addCMakeStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Generators"); - sec->Append(cmDocumentationGeneratorsHeader); - this->AllSections["Generators"] = sec; + cmDocumentationSection sec{ "Generators" }; + sec.Append(cmDocumentationGeneratorsHeader); + this->AllSections.emplace("Generators", std::move(sec)); } void cmDocumentation::addCTestStandardDocSections() @@ -199,11 +189,7 @@ void cmDocumentation::addCTestStandardDocSections() void cmDocumentation::addCPackStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Generators"); - sec->Append(cmDocumentationGeneratorsHeader); - this->AllSections["Generators"] = sec; + addCMakeStandardDocSections(); } bool cmDocumentation::CheckOptions(int argc, const char* const* argv, @@ -364,85 +350,59 @@ void cmDocumentation::SetName(const std::string& name) } void cmDocumentation::SetSection(const char* name, - cmDocumentationSection* section) + cmDocumentationSection section) { - if (this->AllSections.find(name) != this->AllSections.end()) { - delete this->AllSections[name]; - } - this->AllSections[name] = section; + this->SectionAtName(name) = std::move(section); } void cmDocumentation::SetSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = new cmDocumentationSection(name); - sec->Append(docs); - this->SetSection(name, sec); + cmDocumentationSection sec{ name }; + sec.Append(docs); + this->SetSection(name, std::move(sec)); } void cmDocumentation::SetSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = new cmDocumentationSection(name); - sec->Append(docs); - this->SetSection(name, sec); + cmDocumentationSection sec{ name }; + sec.Append(docs); + this->SetSection(name, std::move(sec)); } void cmDocumentation::SetSections( - std::map& sections) + std::map sections) { - for (auto const& s : sections) { - this->SetSection(s.first.c_str(), s.second); + for (auto& s : sections) { + this->SetSection(s.first.c_str(), std::move(s.second)); } } +cmDocumentationSection& cmDocumentation::SectionAtName(const char* name) +{ + return this->AllSections.emplace(name, cmDocumentationSection{ name }) + .first->second; +} void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = new cmDocumentationSection(name); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Prepend(docs); + this->SectionAtName(name).Prepend(docs); } void cmDocumentation::PrependSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = new cmDocumentationSection(name); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Prepend(docs); + this->SectionAtName(name).Prepend(docs); } void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = new cmDocumentationSection(name); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Append(docs); + this->SectionAtName(name).Append(docs); } void cmDocumentation::AppendSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = new cmDocumentationSection(name); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Append(docs); + this->SectionAtName(name).Append(docs); } void cmDocumentation::AppendSection(const char* name, @@ -625,11 +585,10 @@ bool cmDocumentation::PrintHelpListPolicies(std::ostream& os) bool cmDocumentation::PrintHelpListGenerators(std::ostream& os) { - std::map::iterator si; - si = this->AllSections.find("Generators"); + const auto si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { this->Formatter.SetIndent(" "); - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } return true; } @@ -655,29 +614,27 @@ bool cmDocumentation::PrintHelpListVariables(std::ostream& os) bool cmDocumentation::PrintUsage(std::ostream& os) { - std::map::iterator si; - si = this->AllSections.find("Usage"); + const auto si = this->AllSections.find("Usage"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } return true; } bool cmDocumentation::PrintHelp(std::ostream& os) { - std::map::iterator si; - si = this->AllSections.find("Usage"); + auto si = this->AllSections.find("Usage"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } si = this->AllSections.find("Options"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } if (this->ShowGenerators) { si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } } return true; diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 153bad6..b2ff01a 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -6,13 +6,13 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmDocumentationFormatter.h" +#include "cmDocumentationSection.h" #include #include #include #include -class cmDocumentationSection; struct cmDocumentationEntry; /** Class to generate documentation. */ @@ -21,8 +21,6 @@ class cmDocumentation : public cmDocumentationEnums public: cmDocumentation(); - ~cmDocumentation(); - /** * Check command line arguments for documentation options. Returns * true if documentation options are found, and false otherwise. @@ -52,11 +50,11 @@ public: /** Set a section of the documentation. Typical sections include Name, Usage, Description, Options */ - void SetSection(const char* sectionName, cmDocumentationSection* section); + void SetSection(const char* sectionName, cmDocumentationSection section); void SetSection(const char* sectionName, std::vector& docs); void SetSection(const char* sectionName, const char* docs[][2]); - void SetSections(std::map& sections); + void SetSections(std::map sections); /** Add the documentation to the beginning/end of the section */ void PrependSection(const char* sectionName, const char* docs[][2]); @@ -110,7 +108,8 @@ private: bool ShowGenerators; std::string NameString; - std::map AllSections; + std::map AllSections; + cmDocumentationSection& SectionAtName(const char* name); std::string CurrentArgument; -- cgit v0.12