Darwin Neuroevolution Framework
core
global_initializer.h
1
// Copyright 2019 The Darwin Neuroevolution Framework Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#pragma once
16
17
namespace
core
{
18
19
struct
DynamicInitializer {
20
explicit
DynamicInitializer(
void
(*pfn)()) { (*pfn)(); }
21
};
22
23
#define _GLOBAL_INITIALIZER_HELPER(id) \
24
void dynamicInitialierBody_##id(); \
25
core::DynamicInitializer g_dynamic_initializer_##id(&dynamicInitialierBody_##id); \
26
void dynamicInitialierBody_##id()
27
28
#define _GLOBAL_INITIALIZER_DEF(id) _GLOBAL_INITIALIZER_HELPER(id)
29
30
// A helper for defining global (dynamic) initializers. For example:
31
//
32
// GLOBAL_INITIALIZER {
33
// printf("Initializing...\n");
34
// registerType("Foo");
35
// }
36
//
37
// This macro is intended to be used at namespace scope and it's subject to the same
38
// initialization gotchas as the initialization of global objects (initialization order
39
// across translation units is not specified)
40
//
41
// NOTE: GLOBAL_INITIALIZER should NOT be used in headers
42
//
43
#define GLOBAL_INITIALIZER _GLOBAL_INITIALIZER_DEF(__COUNTER__)
44
45
}
// namespace core
core
Generic utilities.
Definition:
exception.h:24
Generated by
1.8.14