numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
iteration_layer_handler.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <atomic>
23#include <memory>
24
26
33public:
38
40 auto operator=(const iteration_layer_handler&) = delete;
41
46 iteration_layer_handler&& /*obj*/) noexcept = default;
47
53 auto operator=(iteration_layer_handler&& /*obj*/) noexcept
54 -> iteration_layer_handler& = default;
55
59 ~iteration_layer_handler() noexcept = default;
60
64 void set_iterative() const noexcept { node_->set_iterative(); }
65
71 void initialize_lower_layer(iteration_layer_handler& lower_layer) noexcept {
72 lower_layer.node_->set_parent(node_);
73 }
74
81 [[nodiscard]] auto is_upper_layer_iterative() const noexcept -> bool {
82 return node_->is_ancestor_node_iterative();
83 }
84
85private:
87 class node {
88 public:
92 void set_iterative() noexcept { is_iterative_ = true; }
93
99 void set_parent(const std::shared_ptr<node>& parent) noexcept {
100 parent_ = parent;
101 }
102
109 [[nodiscard]] auto is_ancestor_node_iterative() const noexcept -> bool {
110 const auto locked = parent_.lock();
111 if (!locked) {
112 return false;
113 }
114 return locked->is_this_or_ancestor_node_iterative();
115 }
116
120 void reset() noexcept {
121 is_iterative_ = false;
122 parent_.reset();
123 }
124
125 private:
133 [[nodiscard]] auto is_this_or_ancestor_node_iterative() const noexcept
134 -> bool {
135 if (is_iterative_) {
136 return true;
137 }
139 }
140
142 std::atomic<bool> is_iterative_{false};
143
145 std::weak_ptr<node> parent_{};
146 };
147
149 std::shared_ptr<node> node_{std::make_shared<node>()};
150};
151
152} // namespace num_collect::logging::impl
void set_parent(const std::shared_ptr< node > &parent) noexcept
Set the parent node.
auto is_ancestor_node_iterative() const noexcept -> bool
Check whether one of ancestor nodes is iterative.
std::atomic< bool > is_iterative_
Whether this layer is iterative.
auto is_this_or_ancestor_node_iterative() const noexcept -> bool
Check whether this node or one of ancestor nodes is iterative.
void set_iterative() noexcept
Set this node to an iterative algorithm.
void set_iterative() const noexcept
Set this node to an iterative algorithm.
void initialize_lower_layer(iteration_layer_handler &lower_layer) noexcept
Initialize the lower layer.
iteration_layer_handler(iteration_layer_handler &&) noexcept=default
Move constructor.
auto is_upper_layer_iterative() const noexcept -> bool
Check whether one of upper layers is iterative.
Namespace of internal implementations.