RayZaler
0.1
The free opto-mechanical simulation framework
ElementMacros.h
1
//
2
// Copyright (c) 2024 Gonzalo José Carracedo Carballal
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU Lesser General Public License as
6
// published by the Free Software Foundation, either version 3 of the
7
// License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this program. If not, see
16
// <http://www.gnu.org/licenses/>
17
//
18
19
20
#ifndef _ELEMENT_MACROS_H
21
#define _ELEMENT_MACROS_H
22
23
#include "Helpers.h"
24
25
// Recursive construction of elements should work like this. Assume two constructors,
26
// () and (name, desc)
27
//
28
// 1. Default constructor calls (name, desc) constructor. The latter is autogen
29
// 2. (name, desc) calls the parent through ()
30
// 3. (name, desc) sets the current metadata
31
// 4. () registers stuff
32
33
// In property definition, we determine whether the current metadata is up
34
// to date, and push it if necessary
35
36
#define RZ_ELEMENT_FACTORY(element) JOIN(element, Factory)
37
#define RZ_FACTORY_METHOD(element, method) RZ_ELEMENT_FACTORY(element)::method
38
#define RZ_FACTORY_CTOR(element) RZ_ELEMENT_FACTORY(element)::RZ_ELEMENT_FACTORY(element)
39
41
#define RZ_DECLARE_ABSTRACT_ELEMENT_FROM(elType, fromType) \
42
class RZ_ELEMENT_FACTORY(elType) : public RZ_ELEMENT_FACTORY(fromType) { \
43
public: \
44
RZ_ELEMENT_FACTORY(elType)(); \
45
RZ_ELEMENT_FACTORY(elType)(std::string const &, std::string const &); \
46
}
47
48
#define RZ_DESCRIBE_ABSTRACT_ELEMENT_FROM(elType, fromType, desc) \
49
RZ_FACTORY_CTOR(elType)(std::string const &name, std::string const &descStr) : \
50
RZ_ELEMENT_FACTORY(fromType)() \
51
{ \
52
enterDecls(name, descStr); \
53
} \
54
RZ_FACTORY_CTOR(elType)() : RZ_FACTORY_CTOR(elType)(STRINGFY(elType), desc) \
55
57
#define RZ_DECLARE_ELEMENT_FROM(elType, fromType) \
58
class RZ_ELEMENT_FACTORY(elType) : public RZ_ELEMENT_FACTORY(fromType) { \
59
public: \
60
RZ_ELEMENT_FACTORY(elType)(); \
61
RZ_ELEMENT_FACTORY(elType)(std::string const &, std::string const &); \
62
virtual Element *make( \
63
std::string const &name, \
64
ReferenceFrame *pFrame, \
65
Element *parent = nullptr) override; \
66
}
67
68
#define RZ_DESCRIBE_ELEMENT_FROM(elType, fromType, desc) \
69
Element * \
70
RZ_FACTORY_METHOD(elType, make)( \
71
std::string const &name, \
72
ReferenceFrame *pFrame, \
73
Element *parent) \
74
{ \
75
auto instance = new elType(this, name, pFrame, parent); \
76
instance->setDefaults(); \
77
return instance; \
78
} \
79
RZ_DESCRIBE_ABSTRACT_ELEMENT_FROM(elType, fromType, desc)
80
81
#define RZ_DECLARE_OPTICAL_ELEMENT(elType) \
82
RZ_DECLARE_ELEMENT_FROM(elType, OpticalElement)
83
#define RZ_DESCRIBE_OPTICAL_ELEMENT(elType, desc) \
84
RZ_DESCRIBE_ELEMENT_FROM(elType, OpticalElement, desc)
85
86
#define RZ_DECLARE_ELEMENT(elType) \
87
RZ_DECLARE_ELEMENT_FROM(elType, Element)
88
#define RZ_DESCRIBE_ELEMENT(elType, desc) \
89
RZ_DESCRIBE_ELEMENT_FROM(elType, Element, desc)
90
91
#define RZ_DECLARE_ABSTRACT_ELEMENT(elType) \
92
RZ_DECLARE_ABSTRACT_ELEMENT_FROM(elType, Element)
93
#define RZ_DESCRIBE_ABSTRACT_ELEMENT(elType, desc) \
94
RZ_DESCRIBE_ABSTRACT_ELEMENT_FROM(elType, Element, desc)
95
96
97
#endif
// _ELEMENT_MACROS_H
LibRZ
include
ElementMacros.h
Generated by
1.9.4