1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

cmCursesCacheEntryComposite: default destructor

This commit is contained in:
Tushar Maheshwari
2019-09-14 17:27:00 +05:30
committed by Brad King
parent 36875ff419
commit bc71b253cb
3 changed files with 42 additions and 37 deletions

View File

@@ -14,7 +14,10 @@
#include "cmStringAlgorithms.h" #include "cmStringAlgorithms.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include <cm/memory>
#include <cassert> #include <cassert>
#include <utility>
#include <vector> #include <vector>
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
@@ -23,9 +26,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
, LabelWidth(labelwidth) , LabelWidth(labelwidth)
, EntryWidth(entrywidth) , EntryWidth(entrywidth)
{ {
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key); this->Label =
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " "); cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
this->Entry =
cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
} }
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
@@ -35,47 +40,51 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
, LabelWidth(labelwidth) , LabelWidth(labelwidth)
, EntryWidth(entrywidth) , EntryWidth(entrywidth)
{ {
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key); this->Label =
cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
if (isNew) { if (isNew) {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*"); this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*");
} else { } else {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " "); this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
} }
this->Entry = nullptr;
const char* value = state->GetCacheEntryValue(key); const char* value = state->GetCacheEntryValue(key);
assert(value); assert(value);
switch (state->GetCacheEntryType(key)) { switch (state->GetCacheEntryType(key)) {
case cmStateEnums::BOOL: case cmStateEnums::BOOL: {
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1); auto bw = cm::make_unique<cmCursesBoolWidget>(this->EntryWidth, 1, 1, 1);
if (cmIsOn(value)) { bw->SetValueAsBool(cmIsOn(value));
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true); this->Entry = std::move(bw);
} else {
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
}
break; break;
case cmStateEnums::PATH: }
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1); case cmStateEnums::PATH: {
static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value); auto pw = cm::make_unique<cmCursesPathWidget>(this->EntryWidth, 1, 1, 1);
pw->SetString(value);
this->Entry = std::move(pw);
break; break;
case cmStateEnums::FILEPATH: }
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1); case cmStateEnums::FILEPATH: {
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value); auto fpw =
cm::make_unique<cmCursesFilePathWidget>(this->EntryWidth, 1, 1, 1);
fpw->SetString(value);
this->Entry = std::move(fpw);
break; break;
}
case cmStateEnums::STRING: { case cmStateEnums::STRING: {
const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS"); const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProp) { if (stringsProp) {
cmCursesOptionsWidget* ow = auto ow =
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1); cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1);
this->Entry = ow; for (std::string const& opt : cmExpandedList(stringsProp)) {
std::vector<std::string> options = cmExpandedList(stringsProp);
for (auto const& opt : options) {
ow->AddOption(opt); ow->AddOption(opt);
} }
ow->SetOption(value); ow->SetOption(value);
this->Entry = std::move(ow);
} else { } else {
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); auto sw =
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value); cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
sw->SetString(value);
this->Entry = std::move(sw);
} }
break; break;
} }
@@ -88,12 +97,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
} }
} }
cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() = default;
{
delete this->Label;
delete this->IsNewLabel;
delete this->Entry;
}
const char* cmCursesCacheEntryComposite::GetValue() const char* cmCursesCacheEntryComposite::GetValue()
{ {

View File

@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <memory>
#include <string> #include <string>
class cmCursesLabelWidget; class cmCursesLabelWidget;
@@ -29,9 +30,9 @@ public:
friend class cmCursesMainForm; friend class cmCursesMainForm;
protected: protected:
cmCursesLabelWidget* Label; std::unique_ptr<cmCursesLabelWidget> Label;
cmCursesLabelWidget* IsNewLabel; std::unique_ptr<cmCursesLabelWidget> IsNewLabel;
cmCursesWidget* Entry; std::unique_ptr<cmCursesWidget> Entry;
std::string Key; std::string Key;
int LabelWidth; int LabelWidth;
int EntryWidth; int EntryWidth;

View File

@@ -103,7 +103,7 @@ void cmCursesMainForm::InitializeUI()
// dummy entry widget (does not respond to input) // dummy entry widget (does not respond to input)
std::unique_ptr<cmCursesCacheEntryComposite> comp = std::unique_ptr<cmCursesCacheEntryComposite> comp =
cm::make_unique<cmCursesCacheEntryComposite>("EMPTY CACHE", 30, 30); cm::make_unique<cmCursesCacheEntryComposite>("EMPTY CACHE", 30, 30);
comp->Entry = new cmCursesDummyWidget(1, 1, 1, 1); comp->Entry = cm::make_unique<cmCursesDummyWidget>(1, 1, 1, 1);
newEntries.emplace_back(std::move(comp)); newEntries.emplace_back(std::move(comp));
} else { } else {
// Create the composites. // Create the composites.