FRX SDK Documentation 2025 SP0
Loading...
Searching...
No Matches
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
22namespace ranges
23{
24 template <typename T>
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
39{
40public:
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
51private:
52
54 {
55 }
56
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};
std::function< void()> FuncType
static AcRxClass * Add(FuncType const &izer, FuncType const &unizer)
auto end(reversion_wrapper< T > w)
auto begin(reversion_wrapper< T > w)
reversion_wrapper< T > reverse(T &&iterable)