mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 12:16:40 +08:00
cmCursesMainForm: change Entries to object vector
- Add move constructor and move assignment operator for `cmCursesCacheEntryComposite`. - Transfer ownership of Entries objects to std::vector.
This commit is contained in:
@@ -25,6 +25,10 @@ public:
|
|||||||
cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite const&) =
|
cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite const&) =
|
||||||
delete;
|
delete;
|
||||||
|
|
||||||
|
cmCursesCacheEntryComposite(cmCursesCacheEntryComposite&&) = default;
|
||||||
|
cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite&&) =
|
||||||
|
default;
|
||||||
|
|
||||||
const char* GetValue();
|
const char* GetValue();
|
||||||
|
|
||||||
friend class cmCursesMainForm;
|
friend class cmCursesMainForm;
|
||||||
|
@@ -67,10 +67,9 @@ cmCursesMainForm::~cmCursesMainForm()
|
|||||||
// See if a cache entry is in the list of entries in the ui.
|
// See if a cache entry is in the list of entries in the ui.
|
||||||
bool cmCursesMainForm::LookForCacheEntry(const std::string& key)
|
bool cmCursesMainForm::LookForCacheEntry(const std::string& key)
|
||||||
{
|
{
|
||||||
return std::any_of(
|
return std::any_of(this->Entries.begin(), this->Entries.end(),
|
||||||
this->Entries.begin(), this->Entries.end(),
|
[&key](cmCursesCacheEntryComposite const& entry) {
|
||||||
[&key](std::unique_ptr<cmCursesCacheEntryComposite> const& entry) {
|
return key == entry.Key;
|
||||||
return key == entry->Key;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ void cmCursesMainForm::InitializeUI()
|
|||||||
{
|
{
|
||||||
// Create a vector of cmCursesCacheEntryComposite's
|
// Create a vector of cmCursesCacheEntryComposite's
|
||||||
// which contain labels, entries and new entry markers
|
// which contain labels, entries and new entry markers
|
||||||
std::vector<std::unique_ptr<cmCursesCacheEntryComposite>> newEntries;
|
std::vector<cmCursesCacheEntryComposite> newEntries;
|
||||||
std::vector<std::string> cacheKeys =
|
std::vector<std::string> cacheKeys =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryKeys();
|
this->CMakeInstance->GetState()->GetCacheEntryKeys();
|
||||||
newEntries.reserve(cacheKeys.size());
|
newEntries.reserve(cacheKeys.size());
|
||||||
@@ -101,9 +100,8 @@ void cmCursesMainForm::InitializeUI()
|
|||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
// If cache is empty, display a label saying so and a
|
// If cache is empty, display a label saying so and a
|
||||||
// dummy entry widget (does not respond to input)
|
// dummy entry widget (does not respond to input)
|
||||||
std::unique_ptr<cmCursesCacheEntryComposite> comp =
|
cmCursesCacheEntryComposite comp("EMPTY CACHE", 30, 30);
|
||||||
cm::make_unique<cmCursesCacheEntryComposite>("EMPTY CACHE", 30, 30);
|
comp.Entry = cm::make_unique<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.
|
||||||
@@ -118,8 +116,8 @@ void cmCursesMainForm::InitializeUI()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this->LookForCacheEntry(key)) {
|
if (!this->LookForCacheEntry(key)) {
|
||||||
newEntries.emplace_back(cm::make_unique<cmCursesCacheEntryComposite>(
|
newEntries.emplace_back(key, this->CMakeInstance->GetState(), true, 30,
|
||||||
key, this->CMakeInstance->GetState(), true, 30, entrywidth));
|
entrywidth);
|
||||||
this->OkToGenerate = false;
|
this->OkToGenerate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,8 +132,8 @@ void cmCursesMainForm::InitializeUI()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->LookForCacheEntry(key)) {
|
if (this->LookForCacheEntry(key)) {
|
||||||
newEntries.emplace_back(cm::make_unique<cmCursesCacheEntryComposite>(
|
newEntries.emplace_back(key, this->CMakeInstance->GetState(), false,
|
||||||
key, this->CMakeInstance->GetState(), false, 30, entrywidth));
|
30, entrywidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,12 +159,12 @@ void cmCursesMainForm::RePost()
|
|||||||
} else {
|
} else {
|
||||||
// If normal mode, count only non-advanced entries
|
// If normal mode, count only non-advanced entries
|
||||||
this->NumberOfVisibleEntries = 0;
|
this->NumberOfVisibleEntries = 0;
|
||||||
for (std::unique_ptr<cmCursesCacheEntryComposite>& entry : this->Entries) {
|
for (cmCursesCacheEntryComposite& entry : this->Entries) {
|
||||||
const char* existingValue =
|
const char* existingValue =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
|
this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
|
||||||
bool advanced =
|
bool advanced =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
||||||
entry->GetValue(), "ADVANCED");
|
entry.GetValue(), "ADVANCED");
|
||||||
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -182,22 +180,22 @@ void cmCursesMainForm::RePost()
|
|||||||
this->Fields.reserve(3 * this->NumberOfVisibleEntries + 1);
|
this->Fields.reserve(3 * this->NumberOfVisibleEntries + 1);
|
||||||
|
|
||||||
// Assign fields
|
// Assign fields
|
||||||
for (std::unique_ptr<cmCursesCacheEntryComposite>& entry : this->Entries) {
|
for (cmCursesCacheEntryComposite& entry : this->Entries) {
|
||||||
const char* existingValue =
|
const char* existingValue =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
|
this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
|
||||||
bool advanced =
|
bool advanced =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
||||||
entry->GetValue(), "ADVANCED");
|
entry.GetValue(), "ADVANCED");
|
||||||
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this->Fields.push_back(entry->Label->Field);
|
this->Fields.push_back(entry.Label->Field);
|
||||||
this->Fields.push_back(entry->IsNewLabel->Field);
|
this->Fields.push_back(entry.IsNewLabel->Field);
|
||||||
this->Fields.push_back(entry->Entry->Field);
|
this->Fields.push_back(entry.Entry->Field);
|
||||||
}
|
}
|
||||||
// if no cache entries there should still be one dummy field
|
// if no cache entries there should still be one dummy field
|
||||||
if (this->Fields.empty()) {
|
if (this->Fields.empty()) {
|
||||||
const auto& front = *this->Entries.front();
|
const auto& front = this->Entries.front();
|
||||||
this->Fields.push_back(front.Label->Field);
|
this->Fields.push_back(front.Label->Field);
|
||||||
this->Fields.push_back(front.IsNewLabel->Field);
|
this->Fields.push_back(front.IsNewLabel->Field);
|
||||||
this->Fields.push_back(front.Entry->Field);
|
this->Fields.push_back(front.Entry->Field);
|
||||||
@@ -241,12 +239,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
|
|||||||
} else {
|
} else {
|
||||||
// If normal, display only non-advanced entries
|
// If normal, display only non-advanced entries
|
||||||
this->NumberOfVisibleEntries = 0;
|
this->NumberOfVisibleEntries = 0;
|
||||||
for (std::unique_ptr<cmCursesCacheEntryComposite>& entry : this->Entries) {
|
for (cmCursesCacheEntryComposite& entry : this->Entries) {
|
||||||
const char* existingValue =
|
const char* existingValue =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
|
this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
|
||||||
bool advanced =
|
bool advanced =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
||||||
entry->GetValue(), "ADVANCED");
|
entry.GetValue(), "ADVANCED");
|
||||||
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -259,12 +257,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
|
|||||||
if (height > 0) {
|
if (height > 0) {
|
||||||
bool isNewPage;
|
bool isNewPage;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (std::unique_ptr<cmCursesCacheEntryComposite>& entry : this->Entries) {
|
for (cmCursesCacheEntryComposite& entry : this->Entries) {
|
||||||
const char* existingValue =
|
const char* existingValue =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
|
this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue());
|
||||||
bool advanced =
|
bool advanced =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
|
||||||
entry->GetValue(), "ADVANCED");
|
entry.GetValue(), "ADVANCED");
|
||||||
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
if (!existingValue || (!this->AdvancedMode && advanced)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -275,10 +273,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
|
|||||||
if (isNewPage) {
|
if (isNewPage) {
|
||||||
this->NumberOfPages++;
|
this->NumberOfPages++;
|
||||||
}
|
}
|
||||||
entry->Label->Move(left, top + row - 1, isNewPage);
|
entry.Label->Move(left, top + row - 1, isNewPage);
|
||||||
entry->IsNewLabel->Move(left + 32, top + row - 1, false);
|
entry.IsNewLabel->Move(left + 32, top + row - 1, false);
|
||||||
entry->Entry->Move(left + 33, top + row - 1, false);
|
entry.Entry->Move(left + 33, top + row - 1, false);
|
||||||
entry->Entry->SetPage(this->NumberOfPages);
|
entry.Entry->SetPage(this->NumberOfPages);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,10 +628,10 @@ void cmCursesMainForm::RemoveEntry(const char* value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto removeIt = std::find_if(
|
auto removeIt =
|
||||||
this->Entries.begin(), this->Entries.end(),
|
std::find_if(this->Entries.begin(), this->Entries.end(),
|
||||||
[value](std::unique_ptr<cmCursesCacheEntryComposite>& entry) -> bool {
|
[value](cmCursesCacheEntryComposite& entry) -> bool {
|
||||||
const char* val = entry->GetValue();
|
const char* val = entry.GetValue();
|
||||||
return val != nullptr && !strcmp(value, val);
|
return val != nullptr && !strcmp(value, val);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -646,13 +644,13 @@ void cmCursesMainForm::RemoveEntry(const char* value)
|
|||||||
// copy from the list box to the cache manager
|
// copy from the list box to the cache manager
|
||||||
void cmCursesMainForm::FillCacheManagerFromUI()
|
void cmCursesMainForm::FillCacheManagerFromUI()
|
||||||
{
|
{
|
||||||
for (std::unique_ptr<cmCursesCacheEntryComposite>& entry : this->Entries) {
|
for (cmCursesCacheEntryComposite& entry : this->Entries) {
|
||||||
const std::string& cacheKey = entry->Key;
|
const std::string& cacheKey = entry.Key;
|
||||||
const char* existingValue =
|
const char* existingValue =
|
||||||
this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey);
|
this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey);
|
||||||
if (existingValue) {
|
if (existingValue) {
|
||||||
std::string oldValue = existingValue;
|
std::string oldValue = existingValue;
|
||||||
std::string newValue = entry->Entry->GetValue();
|
std::string newValue = entry.Entry->GetValue();
|
||||||
std::string fixedOldValue;
|
std::string fixedOldValue;
|
||||||
std::string fixedNewValue;
|
std::string fixedNewValue;
|
||||||
cmStateEnums::CacheEntryType t =
|
cmStateEnums::CacheEntryType t =
|
||||||
@@ -943,12 +941,12 @@ void cmCursesMainForm::HandleInput()
|
|||||||
// make the next or prev. current field after deletion
|
// make the next or prev. current field after deletion
|
||||||
auto nextEntryIt = std::find_if(
|
auto nextEntryIt = std::find_if(
|
||||||
this->Entries.begin(), this->Entries.end(),
|
this->Entries.begin(), this->Entries.end(),
|
||||||
[&nextVal](std::unique_ptr<cmCursesCacheEntryComposite>& entry) {
|
[&nextVal](cmCursesCacheEntryComposite const& entry) {
|
||||||
return nextVal == entry->Key;
|
return nextVal == entry.Key;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nextEntryIt != this->Entries.end()) {
|
if (nextEntryIt != this->Entries.end()) {
|
||||||
set_current_field(this->Form, (*nextEntryIt)->Entry->Field);
|
set_current_field(this->Form, nextEntryIt->Entry->Field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include "cmCursesCacheEntryComposite.h"
|
||||||
#include "cmCursesForm.h"
|
#include "cmCursesForm.h"
|
||||||
#include "cmCursesStandardIncludes.h"
|
#include "cmCursesStandardIncludes.h"
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class cmCursesCacheEntryComposite;
|
|
||||||
class cmake;
|
class cmake;
|
||||||
|
|
||||||
/** \class cmCursesMainForm
|
/** \class cmCursesMainForm
|
||||||
@@ -123,7 +123,7 @@ protected:
|
|||||||
void JumpToCacheEntry(const char* str);
|
void JumpToCacheEntry(const char* str);
|
||||||
|
|
||||||
// Copies of cache entries stored in the user interface
|
// Copies of cache entries stored in the user interface
|
||||||
std::vector<std::unique_ptr<cmCursesCacheEntryComposite>> Entries;
|
std::vector<cmCursesCacheEntryComposite> Entries;
|
||||||
// Errors produced during last run of cmake
|
// Errors produced during last run of cmake
|
||||||
std::vector<std::string> Errors;
|
std::vector<std::string> Errors;
|
||||||
// Command line arguments to be passed to cmake each time
|
// Command line arguments to be passed to cmake each time
|
||||||
|
Reference in New Issue
Block a user