From 45c26f76a3e4cca9fe8ce63a2671dd706e80d14e Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sun, 6 Feb 2022 23:09:20 +0100 Subject: [PATCH] Refactored config option to separate file --- src/config/config.h | 47 +----------------------- src/config/option.h | 69 ++++++++++++++++++++++++++++++++++++ uml/config_class_diagram.yml | 1 + 3 files changed, 71 insertions(+), 46 deletions(-) create mode 100644 src/config/option.h diff --git a/src/config/config.h b/src/config/config.h index b4358b3a..cb72d318 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -19,6 +19,7 @@ #include "class_diagram/model/diagram.h" #include "common/model/enums.h" +#include "option.h" #include "util/util.h" #include @@ -66,52 +67,6 @@ struct filter { std::string to_string(const diagram_type t); -template void append_value(T &l, const T &r) { l = r; } - -enum class option_inherit_mode { override, append }; - -template struct option { - option(const std::string &name_, - option_inherit_mode im = option_inherit_mode::override) - : name{name_} - , value{{}} - { - } - option(const std::string &name_, const T &initial_value, - option_inherit_mode im = option_inherit_mode::override) - : name{name_} - , value{initial_value} - { - } - - void set(const T &v) - { - value = v; - is_declared = true; - } - - void override(const option &o) - { - if (!is_declared && o.is_declared) { - if (inheritance_mode == option_inherit_mode::append) - append_value(value, o.value); - else - value = o.value; - - is_declared = true; - } - } - - T &operator()() { return value; } - - const T &operator()() const { return value; } - - std::string name; - T value; - bool is_declared{false}; - option_inherit_mode inheritance_mode; -}; - struct inheritable_diagram_options { option> glob{"glob"}; option> using_namespace{"using_namespace"}; diff --git a/src/config/option.h b/src/config/option.h new file mode 100644 index 00000000..3ba61f4c --- /dev/null +++ b/src/config/option.h @@ -0,0 +1,69 @@ +/** + * src/config/option.h + * + * Copyright (c) 2021-2022 Bartek Kryza + * + * 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 { +namespace config { + +template void append_value(T &l, const T &r) { l = r; } + +enum class option_inherit_mode { override, append }; + +template struct option { + option(const std::string &name_, + option_inherit_mode im = option_inherit_mode::override) + : name{name_} + , value{{}} + { + } + option(const std::string &name_, const T &initial_value, + option_inherit_mode im = option_inherit_mode::override) + : name{name_} + , value{initial_value} + { + } + + void set(const T &v) + { + value = v; + is_declared = true; + } + + void override(const option &o) + { + if (!is_declared && o.is_declared) { + if (inheritance_mode == option_inherit_mode::append) + append_value(value, o.value); + else + value = o.value; + + is_declared = true; + } + } + + T &operator()() { return value; } + + const T &operator()() const { return value; } + + std::string name; + T value; + bool is_declared{false}; + option_inherit_mode inheritance_mode; +}; +} +} diff --git a/uml/config_class_diagram.yml b/uml/config_class_diagram.yml index 69592b20..9d147d34 100644 --- a/uml/config_class_diagram.yml +++ b/uml/config_class_diagram.yml @@ -1,6 +1,7 @@ type: class include_relations_also_as_members: false glob: + - src/config/option.h - src/config/config.h - src/config/config.cc include: