Refactored nested diagrams with element_view template
This commit is contained in:
@@ -61,21 +61,21 @@ template <>
|
||||
const clanguml::common::optional_ref<class_diagram::model::class_> get(
|
||||
const class_diagram::model::diagram &d, const std::string &full_name)
|
||||
{
|
||||
return d.get_class(full_name);
|
||||
return d.find<class_diagram::model::class_>(full_name);
|
||||
}
|
||||
|
||||
template <>
|
||||
const clanguml::common::optional_ref<common::model::package> get(
|
||||
const package_diagram::model::diagram &d, const std::string &full_name)
|
||||
{
|
||||
return d.get_package(full_name);
|
||||
return d.find<package>(full_name);
|
||||
}
|
||||
|
||||
template <>
|
||||
const clanguml::common::optional_ref<common::model::source_file> get(
|
||||
const include_diagram::model::diagram &d, const std::string &full_name)
|
||||
{
|
||||
return d.get_file(full_name);
|
||||
return d.find<source_file>(full_name);
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -259,7 +259,7 @@ tvl::value_t subclass_filter::match(const diagram &d, const element &e) const
|
||||
clanguml::common::reference_set<class_diagram::model::class_> parents;
|
||||
|
||||
const auto &fn = e.full_name(false);
|
||||
auto class_ref = cd.get_class(fn);
|
||||
auto class_ref = cd.find<class_diagram::model::class_>(fn);
|
||||
|
||||
if (!class_ref.has_value())
|
||||
return false;
|
||||
@@ -308,7 +308,7 @@ tvl::value_t parents_filter::match(const diagram &d, const element &e) const
|
||||
clanguml::common::reference_set<class_diagram::model::class_> parents;
|
||||
|
||||
for (const auto &child : children_) {
|
||||
auto child_ref = cd.get_class(child);
|
||||
auto child_ref = cd.find<class_diagram::model::class_>(child);
|
||||
if (!child_ref.has_value())
|
||||
continue;
|
||||
parents.emplace(child_ref.value());
|
||||
@@ -370,8 +370,8 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
|
||||
return tvl::any_of(context_.begin(), context_.end(),
|
||||
[&e, &d](const auto &context_root_name) {
|
||||
const auto &context_root =
|
||||
static_cast<const class_diagram::model::diagram &>(d).get_class(
|
||||
context_root_name);
|
||||
static_cast<const class_diagram::model::diagram &>(d)
|
||||
.find<class_diagram::model::class_>(context_root_name);
|
||||
|
||||
if (context_root.has_value()) {
|
||||
// This is a direct match to the context root
|
||||
|
||||
70
src/common/model/element_view.h
Normal file
70
src/common/model/element_view.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* src/common/model/element_view.h
|
||||
*
|
||||
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
/**
|
||||
* Provides type based views over elements in a diagram.
|
||||
*
|
||||
* @tparam T Type of diagram element
|
||||
*/
|
||||
template <typename T> class element_view {
|
||||
public:
|
||||
/**
|
||||
* @brief Add reference to diagram element
|
||||
*
|
||||
* @param element Reference to diagram element of specific type
|
||||
*/
|
||||
void add(std::reference_wrapper<T> element)
|
||||
{
|
||||
elements_.emplace_back(std::move(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get collection of reference to diagram elements
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
const reference_vector<T> &view() const { return elements_; }
|
||||
|
||||
/**
|
||||
* @brief Get typed diagram element by id
|
||||
* @param id Global id of a diagram element
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
common::optional_ref<T> get(
|
||||
clanguml::common::model::diagram_element::id_t id) const
|
||||
{
|
||||
for (const auto &e : elements_) {
|
||||
if (e.get().id() == id) {
|
||||
return {e};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
reference_vector<T> elements_;
|
||||
};
|
||||
|
||||
} // namespace clanguml::common::model
|
||||
Reference in New Issue
Block a user