Refactored filter diagrams to three value logic

This commit is contained in:
Bartek Kryza
2022-03-31 23:11:58 +02:00
parent a42598357b
commit 18b0624f7a
3 changed files with 116 additions and 90 deletions

74
src/common/model/tvl.h Normal file
View File

@@ -0,0 +1,74 @@
/**
* src/class_diagram/model/tvl.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 <optional>
#include <string>
namespace clanguml::common::model::tvl {
using value_t = std::optional<bool>;
inline bool is_true(const value_t &v) { return v.has_value() && v.value(); }
inline bool is_false(const value_t &v) { return v.has_value() && !v.value(); }
inline bool is_undefined(const value_t &v) { return !v.has_value(); }
template <typename InputIterator, typename Predicate>
inline value_t all_of(InputIterator first, InputIterator last, Predicate pred)
{
value_t res{};
for (InputIterator it = first; it != last; it++) {
value_t m = pred(*it);
if (m.has_value()) {
if (m.value() == true) {
res = true;
}
else {
res = false;
break;
}
}
}
return res;
}
template <typename InputIterator, typename Predicate>
inline value_t any_of(InputIterator first, InputIterator last, Predicate pred)
{
value_t res{};
for (InputIterator it = first; it != last; it++) {
value_t m = pred(*it);
if (m.has_value()) {
if (m.value() == true) {
res = true;
break;
}
else {
res = false;
}
}
}
return res;
}
};