You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, casting ModelNode (addresses) to derived ModelNode types is quite verbose, and requires a derived-type-specific MyModelPool::resolveMyModelNodeType function to be called. This should be improved, such that there is a generic function model_ptr<ModelNodeType> Model::resolve<ModelNodeType>(addressOrNodeObject). I would propose the following changes:
// Adjustments to the base model class:classModel
{
public:/** NEW METHOD: Resolve a ModelNodeAddress to a derived model_ptr. */template<classTarget = ModelNode>
model_ptr<Target> resolve(ModelNodeAddress const& a) const {
ifconstexpr (std::is_same_v<Target, ModelNode>) {
returnModelNode::Ptr::make(shared_from_this(), a);
} else {
return resolve<Target>(ModelNode::Ptr::make(shared_from_this(), a));
}
}
/** NEW METHOD: Resolve a ModelNode::Ptr to a derived model_ptr. */template<classTarget>
model_ptr<Target> resolve(model_ptr<Target> const& ptr) const {
return resolve<Target>(*ptr);
}
/** NEW METHOD: Resolve a ModelNode to a derived model_ptr. */template<classTarget>
model_ptr<Target> resolve(ModelNode const& n) const {
// Ensure that this Model can cast to the desired Node type.if (id_ != resolve::model_id<Target::ModelType>::id()) {
return {};
}
Target::ModelType const* model = static_cast<ModelType const*>(this);
::resolve::resolve<Target>(*model, n);
}
private:// The base Model has id which is unique for its final derived type,// and initialized based on resovle::model_id<DerivedModel>::id().size_t id_;
}
classDerivedModel : publicModel
{
public:// Is this the right syntax to friend all resolve impls?template<class> friend::resolve::resolve();
DerivedModel : Model(model_id<DerivedModel>::id()) {};
private:classImpl;
std::unique_ptr<Impl> impl_;
}
namespaceresolve
{
template <classTarget>
model_ptr<Target> resolve(Target::ModelType const& model, ModelNode const& n) {
static_assert(false&& )
}
// Example resolve function// Note: This would be MUCH better as a Model class method. But then, I get:// Error: explicit specialization in non-namespace scope ‘class DerivedModel’template<> model_ptr<SpecialModelNode> resolve(DerivedModel const& model, ModelNode const& n) {
// Somehow access members of DerivedModel::Impl by// implementing the template specialization inside of derived-model.cpp?return model.impl_->specialNodeStorage_[n.addr().index()];
}
template<typename T>
structmodel_id {
staticconstvoid* id() {
staticsize_t dummy;
return &dummy;
}
};
}
The text was updated successfully, but these errors were encountered:
Currently, casting ModelNode (addresses) to derived ModelNode types is quite verbose, and requires a derived-type-specific
MyModelPool::resolveMyModelNodeType
function to be called. This should be improved, such that there is a generic functionmodel_ptr<ModelNodeType> Model::resolve<ModelNodeType>(addressOrNodeObject)
. I would propose the following changes:The text was updated successfully, but these errors were encountered: