Refactored class_diagram generator to common base class template

This commit is contained in:
Bartek Kryza
2022-02-15 23:37:47 +01:00
parent 5fba937927
commit 2678a4040e
9 changed files with 316 additions and 205 deletions

81
src/common/model/enums.cc Normal file
View File

@@ -0,0 +1,81 @@
/**
* src/class_diagram/model/enums.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 "enums.h"
#include <cassert>
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 "friendship";
case relationship_t::kDependency:
return "dependency";
default:
assert(false);
}
}
std::string to_string(scope_t s)
{
switch (s) {
case scope_t::kPublic:
return "public";
case scope_t::kProtected:
return "protected";
case scope_t::kPrivate:
return "private";
case scope_t::kNone:
return "none";
default:
assert(false);
}
}
std::string to_string(access_t a)
{
switch (a) {
case access_t::kPublic:
return "public";
case access_t::kProtected:
return "protected";
case access_t::kPrivate:
return "private";
default:
assert(false);
}
}
}

View File

@@ -17,6 +17,8 @@
*/
#pragma once
#include <string>
namespace clanguml::common::model {
enum class access_t { kPublic, kProtected, kPrivate };
@@ -36,4 +38,9 @@ enum class relationship_t {
kDependency
};
std::string to_string(relationship_t r);
std::string to_string(scope_t r);
std::string to_string(access_t r);
}

View File

@@ -20,34 +20,6 @@
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,

View File

@@ -24,8 +24,6 @@
namespace clanguml::common::model {
std::string to_string(relationship_t r);
class relationship : public common::model::decorated_element,
public common::model::stylable_element {
public: