Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
registration.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <functional>
27
28namespace ext {
29
30template < class T >
31class Register {
32 T m_data;
33
34 std::function < void ( const T & ) > m_finish;
35public:
36 template < class InitCallback, class FinalizeCallback >
37 explicit Register ( InitCallback init, FinalizeCallback finish ) : m_data ( init ( ) ), m_finish ( std::move ( finish ) ) {
38 }
39
40 template < class InitCallback >
41 explicit Register ( InitCallback init ) : Register ( init, [] ( const T & ) { } ) {
42 }
43
44 Register ( const Register & ) = delete;
45
46 Register ( Register && other ) noexcept : m_data ( std::move ( other.m_data ) ), m_finish ( std::move ( other.m_finish ) ) {
47 other.m_finish = [] ( const T & ) { };
48 }
49
50 Register & operator = ( const Register & ) = delete;
51
52 Register & operator = ( Register && other ) = delete;
53
55 m_finish ( m_data );
56 }
57};
58
59template < >
60class Register < void > {
61 std::function < void ( ) > m_finish;
62public:
63 template < class InitCallback, class FinalizeCallback >
64 explicit Register ( InitCallback init, FinalizeCallback finish ) : m_finish ( std::move ( finish ) ) {
65 init ( );
66 }
67
68 template < class InitCallback >
69 explicit Register ( InitCallback init ) : Register ( init, [] ( ) { } ) {
70 }
71
72 Register ( const Register & ) = delete;
73
74 Register ( Register && other ) noexcept : m_finish ( std::move ( other.m_finish ) ) {
75 other.m_finish = [] ( ) { };
76 }
77
78 Register & operator = ( const Register & ) = delete;
79
80 Register & operator = ( Register && other ) = delete;
81
83 m_finish ( );
84 }
85};
86
87} /* namespace ext */
88
~Register()
Definition: registration.hpp:82
Register(Register &&other) noexcept
Definition: registration.hpp:74
Register(const Register &)=delete
Register(InitCallback init, FinalizeCallback finish)
Definition: registration.hpp:64
Register(InitCallback init)
Definition: registration.hpp:69
Definition: registration.hpp:31
Register(Register &&other) noexcept
Definition: registration.hpp:46
Register(InitCallback init, FinalizeCallback finish)
Definition: registration.hpp:37
Register(const Register &)=delete
Register & operator=(const Register &)=delete
Register(InitCallback init)
Definition: registration.hpp:41
~Register()
Definition: registration.hpp:54
Definition: sigHandler.cpp:20
Definition: FordFulkerson.hpp:16