cmPropertyDefinition: Construct directly in defined state

Move `cmPropertyDefinitionMap::DefineProperty` functionality
directly into the constructor to avoid an intermediate state.
This commit is contained in:
Vitaly Stakhovsky
2020-03-12 08:36:43 -04:00
committed by Brad King
parent f86d8009c6
commit 73d52a862b
8 changed files with 35 additions and 39 deletions

View File

@@ -775,8 +775,9 @@ void CCONV DefineSourceFileProperty(void* arg, const char* name,
const char* longDocs, int chained)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
mf->GetState()->DefineProperty(name, cmProperty::SOURCE_FILE, briefDocs,
longDocs, chained != 0);
mf->GetState()->DefineProperty(name, cmProperty::SOURCE_FILE,
briefDocs ? briefDocs : "",
longDocs ? longDocs : "", chained != 0);
}
} // close the extern "C" scope

View File

@@ -95,7 +95,7 @@ bool cmDefinePropertyCommand(std::vector<std::string> const& args,
// Actually define the property.
status.GetMakefile().GetState()->DefineProperty(
PropertyName, scope, BriefDocs.c_str(), FullDocs.c_str(), inherited);
PropertyName, scope, BriefDocs, FullDocs, inherited);
return true;
}

View File

@@ -2,19 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmPropertyDefinition.h"
void cmPropertyDefinition::DefineProperty(const std::string& name,
cmProperty::ScopeType scope,
const char* shortDescription,
const char* fullDescription,
bool chain)
#include <utility>
cmPropertyDefinition::cmPropertyDefinition(std::string name,
cmProperty::ScopeType scope,
std::string shortDescription,
std::string fullDescription,
bool chain)
: Name(std::move(name))
, ShortDescription(std::move(shortDescription))
, FullDescription(std::move(fullDescription))
, Scope(scope)
, Chained(chain)
{
this->Name = name;
this->Scope = scope;
this->Chained = chain;
if (shortDescription) {
this->ShortDescription = shortDescription;
}
if (fullDescription) {
this->FullDescription = fullDescription;
}
}

View File

@@ -21,13 +21,10 @@
class cmPropertyDefinition
{
public:
/// Define this property
void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription, bool chained);
/// Default constructor
cmPropertyDefinition() { this->Chained = false; }
/// Constructor
cmPropertyDefinition(std::string name, cmProperty::ScopeType scope,
std::string ShortDescription,
std::string FullDescription, bool chained = false);
/// Is the property chained?
bool IsChained() const { return this->Chained; }

View File

@@ -2,20 +2,20 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmPropertyDefinitionMap.h"
#include <tuple>
#include <utility>
void cmPropertyDefinitionMap::DefineProperty(const std::string& name,
cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription,
bool chain)
void cmPropertyDefinitionMap::DefineProperty(
const std::string& name, cmProperty::ScopeType scope,
const std::string& ShortDescription, const std::string& FullDescription,
bool chain)
{
auto it = this->find(name);
cmPropertyDefinition* prop;
if (it == this->end()) {
prop = &(*this)[name];
prop->DefineProperty(name, scope, ShortDescription, FullDescription,
chain);
// try_emplace() since C++17
this->emplace(std::piecewise_construct, std::forward_as_tuple(name),
std::forward_as_tuple(name, scope, ShortDescription,
FullDescription, chain));
}
}

View File

@@ -17,8 +17,8 @@ class cmPropertyDefinitionMap
public:
// define the property
void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription, bool chain);
const std::string& ShortDescription,
const std::string& FullDescription, bool chain);
// has a named property been defined
bool IsPropertyDefined(const std::string& name) const;

View File

@@ -335,8 +335,8 @@ cmStateSnapshot cmState::Reset()
void cmState::DefineProperty(const std::string& name,
cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription, bool chained)
const std::string& ShortDescription,
const std::string& FullDescription, bool chained)
{
this->PropertyDefinitions[scope].DefineProperty(
name, scope, ShortDescription, FullDescription, chained);

View File

@@ -121,8 +121,8 @@ public:
cmStateSnapshot Reset();
// Define a property
void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription, bool chain = false);
const std::string& ShortDescription,
const std::string& FullDescription, bool chain = false);
// get property definition
cmPropertyDefinition const* GetPropertyDefinition(