Refactored common diagram elements to clanguml::common:model namespace
This commit is contained in:
82
src/common/model/decorated_element.cc
Normal file
82
src/common/model/decorated_element.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* src/class_diagram/model/decorated_element.cc
|
||||
*
|
||||
* Copyright (c) 2021-2022 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.
|
||||
*/
|
||||
|
||||
#include "decorated_element.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
bool decorated_element::skip() const
|
||||
{
|
||||
for (auto d : decorators_)
|
||||
if (std::dynamic_pointer_cast<decorators::skip>(d))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool decorated_element::skip_relationship() const
|
||||
{
|
||||
for (auto d : decorators_)
|
||||
if (std::dynamic_pointer_cast<decorators::skip_relationship>(d))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::pair<relationship_t, std::string> decorated_element::get_relationship() const
|
||||
{
|
||||
for (auto &d : decorators_)
|
||||
if (std::dynamic_pointer_cast<decorators::association>(d))
|
||||
return {relationship_t::kAssociation,
|
||||
std::dynamic_pointer_cast<decorators::relationship>(d)
|
||||
->multiplicity};
|
||||
else if (std::dynamic_pointer_cast<decorators::aggregation>(d))
|
||||
return {relationship_t::kAggregation,
|
||||
std::dynamic_pointer_cast<decorators::relationship>(d)
|
||||
->multiplicity};
|
||||
else if (std::dynamic_pointer_cast<decorators::composition>(d))
|
||||
return {relationship_t::kComposition,
|
||||
std::dynamic_pointer_cast<decorators::relationship>(d)
|
||||
->multiplicity};
|
||||
|
||||
return {relationship_t::kNone, ""};
|
||||
}
|
||||
|
||||
std::string decorated_element::style_spec()
|
||||
{
|
||||
for (auto d : decorators_)
|
||||
if (std::dynamic_pointer_cast<decorators::style>(d))
|
||||
return std::dynamic_pointer_cast<decorators::style>(d)->spec;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<decorators::decorator>> &
|
||||
decorated_element::decorators() const
|
||||
{
|
||||
return decorators_;
|
||||
}
|
||||
|
||||
void decorated_element::add_decorators(
|
||||
const std::vector<std::shared_ptr<decorators::decorator>> &decorators)
|
||||
{
|
||||
for (auto d : decorators) {
|
||||
decorators_.push_back(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
src/common/model/decorated_element.h
Normal file
50
src/common/model/decorated_element.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* src/class_diagram/model/decorated_element.h
|
||||
*
|
||||
* Copyright (c) 2021-2022 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 "enums.h"
|
||||
|
||||
#include "decorators/decorators.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
class decorated_element {
|
||||
public:
|
||||
bool skip() const;
|
||||
|
||||
bool skip_relationship() const;
|
||||
|
||||
std::pair<relationship_t, std::string> get_relationship() const;
|
||||
|
||||
std::string style_spec();
|
||||
|
||||
const std::vector<std::shared_ptr<decorators::decorator>> &
|
||||
decorators() const;
|
||||
|
||||
void add_decorators(
|
||||
const std::vector<std::shared_ptr<decorators::decorator>> &decorators);
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<decorators::decorator>> decorators_;
|
||||
};
|
||||
|
||||
}
|
||||
68
src/common/model/element.cc
Normal file
68
src/common/model/element.cc
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* src/class_diagram/model/element.cc
|
||||
*
|
||||
* Copyright (c) 2021-2022 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.
|
||||
*/
|
||||
|
||||
#include "element.h"
|
||||
|
||||
#include "util/util.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
std::atomic_uint64_t element::m_nextId = 1;
|
||||
|
||||
element::element(const std::vector<std::string> &using_namespaces)
|
||||
: using_namespaces_{using_namespaces}
|
||||
, m_id{m_nextId++}
|
||||
{
|
||||
}
|
||||
|
||||
std::string element::alias() const { return fmt::format("C_{:010}", m_id); }
|
||||
|
||||
void element::add_relationship(relationship &&cr)
|
||||
{
|
||||
if (cr.destination().empty()) {
|
||||
LOG_WARN("Skipping relationship '{}' - {} - '{}' due empty "
|
||||
"destination",
|
||||
cr.destination(), to_string(cr.type()), full_name(true));
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = std::find(relationships_.begin(), relationships_.end(), cr);
|
||||
if (it == relationships_.end())
|
||||
relationships_.emplace_back(std::move(cr));
|
||||
}
|
||||
|
||||
void element::set_using_namespaces(const std::vector<std::string> &un)
|
||||
{
|
||||
using_namespaces_ = un;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &element::using_namespaces() const
|
||||
{
|
||||
return using_namespaces_;
|
||||
}
|
||||
|
||||
std::vector<relationship> &element::relationships()
|
||||
{
|
||||
return relationships_;
|
||||
}
|
||||
|
||||
const std::vector<relationship> &element::relationships() const
|
||||
{
|
||||
return relationships_;
|
||||
}
|
||||
}
|
||||
67
src/common/model/element.h
Normal file
67
src/common/model/element.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* src/class_diagram/model/element.h
|
||||
*
|
||||
* Copyright (c) 2021-2022 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 "relationship.h"
|
||||
#include "decorated_element.h"
|
||||
#include "relationship.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
class element : public decorated_element {
|
||||
public:
|
||||
element(const std::vector<std::string> &using_namespaces);
|
||||
|
||||
std::string alias() const;
|
||||
|
||||
void set_name(const std::string &name) { name_ = name; }
|
||||
|
||||
std::string name() const { return name_; }
|
||||
|
||||
void set_namespace(const std::vector<std::string> &ns) { namespace_ = ns; }
|
||||
|
||||
std::vector<std::string> get_namespace() const { return namespace_; }
|
||||
|
||||
virtual std::string full_name(bool relative) const { return name(); }
|
||||
|
||||
void set_using_namespaces(const std::vector<std::string> &un);
|
||||
|
||||
const std::vector<std::string> &using_namespaces() const;
|
||||
|
||||
std::vector<relationship> &relationships();
|
||||
|
||||
const std::vector<relationship> &relationships() const;
|
||||
|
||||
void add_relationship(relationship &&cr);
|
||||
|
||||
protected:
|
||||
const uint64_t m_id{0};
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::vector<std::string> namespace_;
|
||||
std::vector<std::string> using_namespaces_;
|
||||
std::vector<relationship> relationships_;
|
||||
|
||||
static std::atomic_uint64_t m_nextId;
|
||||
};
|
||||
}
|
||||
39
src/common/model/enums.h
Normal file
39
src/common/model/enums.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* src/class_diagram/model/enums.h
|
||||
*
|
||||
* Copyright (c) 2021-2022 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
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
enum class access_t { kPublic, kProtected, kPrivate };
|
||||
|
||||
enum class scope_t { kPublic, kProtected, kPrivate, kNone };
|
||||
|
||||
enum class relationship_t {
|
||||
kNone,
|
||||
kExtension,
|
||||
kComposition,
|
||||
kAggregation,
|
||||
kContainment,
|
||||
kOwnership,
|
||||
kAssociation,
|
||||
kInstantiation,
|
||||
kFriendship,
|
||||
kDependency
|
||||
};
|
||||
|
||||
}
|
||||
113
src/common/model/relationship.cc
Normal file
113
src/common/model/relationship.cc
Normal file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* src/common/model/class_relationship.cc
|
||||
*
|
||||
* Copyright (c) 2021-2022 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.
|
||||
*/
|
||||
|
||||
#include "relationship.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
std::string to_string(relationship_t r)
|
||||
{
|
||||
switch (r) {
|
||||
case relationship_t::kNone:
|
||||
return "none";
|
||||
case relationship_t::kExtension:
|
||||
return "extension";
|
||||
case relationship_t::kComposition:
|
||||
return "composition";
|
||||
case relationship_t::kAggregation:
|
||||
return "aggregation";
|
||||
case relationship_t::kContainment:
|
||||
return "containment";
|
||||
case relationship_t::kOwnership:
|
||||
return "ownership";
|
||||
case relationship_t::kAssociation:
|
||||
return "association";
|
||||
case relationship_t::kInstantiation:
|
||||
return "instantiation";
|
||||
case relationship_t::kFriendship:
|
||||
return "frendship";
|
||||
case relationship_t::kDependency:
|
||||
return "dependency";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
relationship::relationship(relationship_t type,
|
||||
const std::string &destination, scope_t scope, const std::string &label,
|
||||
const std::string &multiplicity_source,
|
||||
const std::string &multiplicity_destination)
|
||||
: type_{type}
|
||||
, destination_{destination}
|
||||
, scope_{scope}
|
||||
, label_{label}
|
||||
, multiplicity_source_{multiplicity_source}
|
||||
, multiplicity_destination_{multiplicity_destination}
|
||||
{
|
||||
}
|
||||
|
||||
void relationship::set_type(relationship_t type) noexcept
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
relationship_t relationship::type() const noexcept { return type_; }
|
||||
|
||||
void relationship::set_destination(const std::string &destination)
|
||||
{
|
||||
destination_ = destination;
|
||||
}
|
||||
|
||||
std::string relationship::destination() const { return destination_; }
|
||||
|
||||
void relationship::set_multiplicity_source(
|
||||
const std::string &multiplicity_source)
|
||||
{
|
||||
multiplicity_source_ = multiplicity_source;
|
||||
}
|
||||
|
||||
std::string relationship::multiplicity_source() const
|
||||
{
|
||||
return multiplicity_source_;
|
||||
}
|
||||
|
||||
void relationship::set_multiplicity_destination(
|
||||
const std::string &multiplicity_destination)
|
||||
{
|
||||
multiplicity_destination_ = multiplicity_destination;
|
||||
}
|
||||
|
||||
std::string relationship::multiplicity_destination() const
|
||||
{
|
||||
return multiplicity_destination_;
|
||||
}
|
||||
|
||||
void relationship::set_label(const std::string &label) { label_ = label; }
|
||||
|
||||
std::string relationship::label() const { return label_; }
|
||||
|
||||
void relationship::set_scope(scope_t scope) noexcept { scope_ = scope; }
|
||||
|
||||
scope_t relationship::scope() const noexcept { return scope_; }
|
||||
|
||||
bool operator==(const relationship &l, const relationship &r)
|
||||
{
|
||||
return l.type() == r.type() && l.destination() == r.destination() &&
|
||||
l.label() == r.label();
|
||||
}
|
||||
}
|
||||
69
src/common/model/relationship.h
Normal file
69
src/common/model/relationship.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* src/common/model/relationship.h
|
||||
*
|
||||
* Copyright (c) 2021-2022 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/model/decorated_element.h"
|
||||
#include "common/model/stylable_element.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
std::string to_string(relationship_t r);
|
||||
|
||||
class relationship : public common::model::decorated_element,
|
||||
public common::model::stylable_element {
|
||||
public:
|
||||
relationship(relationship_t type, const std::string &destination,
|
||||
scope_t scope = scope_t::kNone, const std::string &label = "",
|
||||
const std::string &multiplicity_source = "",
|
||||
const std::string &multiplicity_destination = "");
|
||||
|
||||
virtual ~relationship() = default;
|
||||
|
||||
void set_type(relationship_t type) noexcept;
|
||||
relationship_t type() const noexcept;
|
||||
|
||||
void set_destination(const std::string &destination);
|
||||
std::string destination() const;
|
||||
|
||||
void set_multiplicity_source(const std::string &multiplicity_source);
|
||||
std::string multiplicity_source() const;
|
||||
|
||||
void set_multiplicity_destination(
|
||||
const std::string &multiplicity_destination);
|
||||
std::string multiplicity_destination() const;
|
||||
|
||||
void set_label(const std::string &label);
|
||||
std::string label() const;
|
||||
|
||||
void set_scope(scope_t scope) noexcept;
|
||||
scope_t scope() const noexcept;
|
||||
|
||||
friend bool operator==(
|
||||
const relationship &l, const relationship &r);
|
||||
|
||||
private:
|
||||
relationship_t type_{relationship_t::kAssociation};
|
||||
std::string destination_;
|
||||
std::string multiplicity_source_;
|
||||
std::string multiplicity_destination_;
|
||||
std::string label_;
|
||||
scope_t scope_{scope_t::kNone};
|
||||
};
|
||||
}
|
||||
27
src/common/model/stylable_element.cc
Normal file
27
src/common/model/stylable_element.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* src/class_diagram/model/stylable_element.cc
|
||||
*
|
||||
* Copyright (c) 2021-2022 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.
|
||||
*/
|
||||
|
||||
#include "stylable_element.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
void stylable_element::set_style(const std::string &style) { style_ = style; }
|
||||
|
||||
std::string stylable_element::style() const { return style_; }
|
||||
|
||||
}
|
||||
33
src/common/model/stylable_element.h
Normal file
33
src/common/model/stylable_element.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* src/class_diagram/model/stylable_element.h
|
||||
*
|
||||
* Copyright (c) 2021-2022 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 <string>
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
class stylable_element {
|
||||
public:
|
||||
void set_style(const std::string &style);
|
||||
std::string style() const;
|
||||
|
||||
private:
|
||||
std::string style_;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user