FRX SDK Documentation
2025 SP0
Loading...
Searching...
No Matches
SDK
FxARX
_impl_include
AutoInitializer.h
Go to the documentation of this file.
1
#pragma once
2
3
//
4
// (C) Copyright 2005-2024 by Graebert GmbH.
5
//
6
// Permission to use, copy, modify, and distribute this software in
7
// object code form for any purpose and without fee is hereby granted,
8
// provided that the above copyright notice appears in all copies and
9
// that both that copyright notice and the limited warranty and
10
// restricted rights notice below appear in all supporting
11
// documentation.
12
//
13
// GRAEBERT PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
14
// GRAEBERT SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
15
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. GRAEBERT GMBH
16
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
17
// UNINTERRUPTED OR ERROR FREE.
18
19
#include <functional>
20
21
// This is a workaround for reversing a range-based for loop before c++ 20
22
namespace
ranges
23
{
24
template
<
typename
T>
25
struct
reversion_wrapper
{
T
&
iterable
; };
26
27
template
<
typename
T>
28
auto
begin
(
reversion_wrapper<T>
w
) {
return
std::rbegin(
w
.iterable ); }
29
30
template
<
typename
T>
31
auto
end
(
reversion_wrapper<T>
w
) {
return
std::rend(
w
.iterable ); }
32
33
template
<
typename
T>
34
reversion_wrapper<T>
reverse
(
T
&& iterable ) {
return
{ iterable }; }
35
};
36
37
// A static class for automatic initializing/deinitializing custom AcRx classes
38
class
AutoInitializer
39
{
40
public
:
41
42
using
FuncType
= std::function<
void
()>;
43
44
// This method is used for adding initializers to the list
45
static
AcRxClass
*
Add
(
FuncType
const
&
izer
,
FuncType
const
&
unizer
)
46
{
47
AutoInitializer::instance()._initializers.push_back( {
izer
,
unizer
} );
48
return
nullptr
;
49
}
50
51
private
:
52
53
AutoInitializer
()
54
{
55
}
56
57
~AutoInitializer
()
58
{
59
}
60
61
// Meyers' singleton - ensures that this class will be created before it's use
62
static
AutoInitializer
&instance()
63
{
64
static
AutoInitializer
izer
;
65
return
izer
;
66
}
67
68
void
_DoInitialize()
69
{
70
for
(
auto
&
izer
: _initializers )
71
{
72
izer
.first();
73
}
74
}
75
76
void
_DoUninitialize()
77
{
78
for
(
auto
&
izer
:
ranges
::
reverse
( _initializers ) )
79
{
80
izer
.second();
81
}
82
}
83
84
friend
class
AcRxDbxApp
;
85
86
// List of initializer and deinitializer functions
87
std::vector<std::pair<FuncType, FuncType>> _initializers;
88
};
AcArrayObjectCopyReallocator
Definition
_AcArray.h:21
AcRxClass
Definition
AcRxClass.h:22
AcRxDbxApp
Definition
addclass.h:837
AutoInitializer
Definition
AutoInitializer.h:39
AutoInitializer::FuncType
std::function< void()> FuncType
Definition
AutoInitializer.h:42
AutoInitializer::Add
static AcRxClass * Add(FuncType const &izer, FuncType const &unizer)
Definition
AutoInitializer.h:45
ranges
Definition
AutoInitializer.h:23
ranges::end
auto end(reversion_wrapper< T > w)
Definition
AutoInitializer.h:31
ranges::begin
auto begin(reversion_wrapper< T > w)
Definition
AutoInitializer.h:28
ranges::reverse
reversion_wrapper< T > reverse(T &&iterable)
Definition
AutoInitializer.h:34
ranges::reversion_wrapper
Definition
AutoInitializer.h:25
ranges::reversion_wrapper::iterable
T & iterable
Definition
AutoInitializer.h:25
Generated on Mon Mar 4 2024 12:50:08