mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 20:00:38 -06:00
cmPropertyDefinition: Construct directly in defined state
Move `cmPropertyDefinitionMap::DefineProperty` functionality directly into the constructor to avoid an intermediate state.
This commit is contained in:
committed by
Brad King
parent
f86d8009c6
commit
73d52a862b
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user