FEDEM Solver  R8.0
Source code of the dynamics solver
FFaDynCB.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
15 #ifndef FFA_DYNCB_H
16 #define FFA_DYNCB_H
17 
19 //
20 // User interface:
21 // Use these classes only through the following macros and methods:
22 //
23 // To create a DynCB:
24 //
25 
26 #define FFaDynCB0M(ownerType, ownerPt, methodName) \
27  FFaDynCB0(new FFaMethodCB0< ownerType > (ownerPt, &ownerType::methodName))
28 #define FFaDynCB1M(ownerType, ownerPt, methodName, P1Type) \
29  FFaDynCB1 < P1Type > (new FFaMethodCB1< ownerType , P1Type > (ownerPt, &ownerType::methodName))
30 #define FFaDynCB2M(ownerType, ownerPt, methodName, P1Type, P2Type) \
31  FFaDynCB2 < P1Type, P2Type > (new FFaMethodCB2< ownerType , P1Type , P2Type > (ownerPt, &ownerType::methodName))
32 #define FFaDynCB3M(ownerType, ownerPt, methodName, P1Type, P2Type, P3Type) \
33  FFaDynCB3 < P1Type, P2Type, P3Type > (new FFaMethodCB3< ownerType , P1Type , P2Type , P3Type > (ownerPt, &ownerType::methodName))
34 #define FFaDynCB4M(ownerType, ownerPt, methodName, P1Type, P2Type, P3Type, P4Type) \
35  FFaDynCB4 < P1Type, P2Type, P3Type, P4Type > (new FFaMethodCB4< ownerType , P1Type , P2Type , P3Type, P4Type > (ownerPt, &ownerType::methodName))
36 
37 #define FFaDynCB0S(function) \
38  FFaDynCB0(new FFaStaticCB0 (function))
39 #define FFaDynCB1S(function, P1Type) \
40  FFaDynCB1 < P1Type > (new FFaStaticCB1 < P1Type > (function))
41 #define FFaDynCB2S(function, P1Type, P2Type) \
42  FFaDynCB2 < P1Type, P2Type > (new FFaStaticCB2 < P1Type , P2Type > (function))
43 #define FFaDynCB3S(function, P1Type, P2Type, P3Type) \
44  FFaDynCB3 < P1Type, P2Type, P3Type > (new FFaStaticCB3 < P1Type , P2Type , P3Type > (function))
45 #define FFaDynCB4S(function, P1Type, P2Type, P3Type, P4Type) \
46  FFaDynCB4 < P1Type, P2Type, P3Type, P4Type > (new FFaStaticCB4 < P1Type , P2Type , P3Type, P4Type > (function))
47 
48 // To invoke the callback:
49 // aDynCB->invoke(arg1,arg2);
50 //
51 // To copy a call back:
52 // FFaDynCB<N>* aCopyDynCB = aDynCB->copy();
53 //
54 //
55 // End user interface
57 
58 
59 // one type :
60 
61 #define FFADYNCB_H_TEMPLATE1 template< class P1Type >
62 #define FFADYNCB_H_ADDED_TEMPLATE_ARGS1 , class P1Type
63 #define FFADYNCB_H_TYPE_LIST1 < P1Type >
64 #define FFADYNCB_H_ADDED_TYPE_LIST1 , P1Type
65 #define FFADYNCB_H_ARGUMENT_LIST1 P1Type p1
66 #define FFADYNCB_H_PARAM_LIST1 p1
67 
68 
69 // Two types :
70 
71 #define FFADYNCB_H_TEMPLATE2 template< class P1Type, class P2Type >
72 #define FFADYNCB_H_ADDED_TEMPLATE_ARGS2 , class P1Type, class P2Type
73 #define FFADYNCB_H_TYPE_LIST2 < P1Type, P2Type >
74 #define FFADYNCB_H_ADDED_TYPE_LIST2 , P1Type, P2Type
75 #define FFADYNCB_H_ARGUMENT_LIST2 P1Type p1, P2Type p2
76 #define FFADYNCB_H_PARAM_LIST2 p1, p2
77 
78 // Three types :
79 
80 #define FFADYNCB_H_TEMPLATE3 template< class P1Type, class P2Type , class P3Type >
81 #define FFADYNCB_H_ADDED_TEMPLATE_ARGS3 , class P1Type, class P2Type, class P3Type
82 #define FFADYNCB_H_TYPE_LIST3 < P1Type, P2Type , P3Type >
83 #define FFADYNCB_H_ADDED_TYPE_LIST3 , P1Type, P2Type, P3Type
84 #define FFADYNCB_H_ARGUMENT_LIST3 P1Type p1, P2Type p2, P3Type p3
85 #define FFADYNCB_H_PARAM_LIST3 p1, p2, p3
86 
87 // Four types :
88 
89 #define FFADYNCB_H_TEMPLATE4 template< class P1Type, class P2Type , class P3Type, class P4Type >
90 #define FFADYNCB_H_ADDED_TEMPLATE_ARGS4 , class P1Type, class P2Type, class P3Type, class P4Type
91 #define FFADYNCB_H_TYPE_LIST4 < P1Type, P2Type , P3Type, P4Type >
92 #define FFADYNCB_H_ADDED_TYPE_LIST4 , P1Type, P2Type, P3Type, P4Type
93 #define FFADYNCB_H_ARGUMENT_LIST4 P1Type p1, P2Type p2, P3Type p3, P4Type p4
94 #define FFADYNCB_H_PARAM_LIST4 p1, p2, p3, p4
95 
96 
97 
98 //
99 // Macro that defines the different dynCBN templates
100 // One macro call for each number of arguments we want to support :
101 //
102 
103 #define MAKE_BASE_DYNCB(nr, templateDef, argumentList) \
104  \
105 templateDef class FFaBaseDynCB##nr \
106 { \
107 public: \
108  FFaBaseDynCB##nr () {} \
109  virtual ~FFaBaseDynCB##nr () {} \
110  \
111  virtual void invoke (argumentList) = 0; \
112  virtual FFaBaseDynCB##nr * copy () const = 0; \
113 };
114 
115 
116 MAKE_BASE_DYNCB(0, ,)
121 
122 
123 #define MAKE_METHODCB(nr, addedTemplateArgs, argumentList, parameterList, typeList, addedTypeList) \
124  \
125 template<class T addedTemplateArgs> class FFaMethodCB##nr : public FFaBaseDynCB##nr typeList \
126 { \
127  typedef void (T::*methodType) (argumentList); \
128  \
129 public: \
130  FFaMethodCB##nr (T* anObj, methodType aMethod) : myObject(anObj), myMethodPt(aMethod) {} \
131  virtual ~FFaMethodCB##nr () {} \
132  \
133  virtual void invoke (argumentList) { if (myObject) (myObject->*this->myMethodPt) (parameterList); } \
134  \
135  virtual FFaBaseDynCB##nr typeList * copy () const \
136  { \
137  return new FFaMethodCB##nr <T addedTypeList> (myObject, myMethodPt); \
138  } \
139  \
140 private: \
141  T* myObject; \
142  methodType myMethodPt; \
143 };
144 
145 MAKE_METHODCB(0, ,,,,)
150 
151 
152 #define MAKE_STATICCB(nr, templateDef, argumentList, parameterList, typeList) \
153  \
154 templateDef class FFaStaticCB##nr : public FFaBaseDynCB##nr typeList \
155 { \
156  typedef void (*functionType)(argumentList); \
157  \
158 public: \
159  FFaStaticCB##nr (functionType aFunction) : myFunctionPt(aFunction) {} \
160  virtual ~FFaStaticCB##nr () {} \
161  \
162  virtual void invoke (argumentList) { myFunctionPt(parameterList); } \
163  \
164  virtual FFaBaseDynCB##nr typeList * copy () const \
165  { \
166  return new FFaStaticCB##nr typeList (myFunctionPt); \
167  } \
168  \
169 private: \
170  functionType myFunctionPt; \
171 };
172 
173 MAKE_STATICCB(0, ,,,)
178 
179 
180 #define MAKE_DYNCB(nr, templateDef, argumentList, parameterList, typeList) \
181  \
182 templateDef class FFaDynCB##nr \
183 { \
184 public: \
185  FFaDynCB##nr (FFaBaseDynCB##nr typeList *aBaseDynCB = 0) : myBaseDynCBPtr(aBaseDynCB) {} \
186  FFaDynCB##nr (const FFaDynCB##nr typeList &rhs) \
187  { \
188  myBaseDynCBPtr = rhs.myBaseDynCBPtr ? rhs.myBaseDynCBPtr->copy() : 0; \
189  } \
190  ~FFaDynCB##nr () { if (myBaseDynCBPtr) delete myBaseDynCBPtr; } \
191  \
192  void invoke(argumentList) { if (myBaseDynCBPtr) myBaseDynCBPtr->invoke(parameterList); } \
193  \
194  FFaDynCB##nr &operator= (const FFaDynCB##nr typeList &rhs) \
195  { \
196  if (this != &rhs) \
197  { \
198  if (myBaseDynCBPtr) delete myBaseDynCBPtr; \
199  myBaseDynCBPtr = rhs.myBaseDynCBPtr ? rhs.myBaseDynCBPtr->copy() : 0; \
200  } \
201  return *this; \
202  } \
203  \
204  bool empty() const { return myBaseDynCBPtr == 0; } \
205  void erase() { if (myBaseDynCBPtr) delete myBaseDynCBPtr; myBaseDynCBPtr = 0; } \
206  FFaDynCB##nr* copy() const { return new FFaDynCB##nr (*this); } \
207  \
208 private: \
209  FFaBaseDynCB##nr typeList *myBaseDynCBPtr; \
210 };
211 
212 MAKE_DYNCB(0, ,,,)
217 
218 #endif
#define FFADYNCB_H_PARAM_LIST1
Definition: FFaDynCB.H:66
#define FFADYNCB_H_ADDED_TEMPLATE_ARGS4
Definition: FFaDynCB.H:90
#define FFADYNCB_H_TYPE_LIST3
Definition: FFaDynCB.H:82
#define FFADYNCB_H_PARAM_LIST4
Definition: FFaDynCB.H:94
#define FFADYNCB_H_TYPE_LIST4
Definition: FFaDynCB.H:91
#define FFADYNCB_H_ARGUMENT_LIST4
Definition: FFaDynCB.H:93
#define MAKE_DYNCB(nr, templateDef, argumentList, parameterList, typeList)
Definition: FFaDynCB.H:180
#define FFADYNCB_H_TEMPLATE2
Definition: FFaDynCB.H:71
#define FFADYNCB_H_TEMPLATE3
Definition: FFaDynCB.H:80
#define FFADYNCB_H_TEMPLATE4
Definition: FFaDynCB.H:89
#define FFADYNCB_H_PARAM_LIST3
Definition: FFaDynCB.H:85
#define MAKE_BASE_DYNCB(nr, templateDef, argumentList)
Definition: FFaDynCB.H:103
#define FFADYNCB_H_ADDED_TYPE_LIST4
Definition: FFaDynCB.H:92
#define FFADYNCB_H_ADDED_TYPE_LIST2
Definition: FFaDynCB.H:74
#define FFADYNCB_H_ARGUMENT_LIST1
Definition: FFaDynCB.H:65
#define FFADYNCB_H_PARAM_LIST2
Definition: FFaDynCB.H:76
#define FFADYNCB_H_ADDED_TEMPLATE_ARGS1
Definition: FFaDynCB.H:62
#define FFADYNCB_H_ARGUMENT_LIST2
Definition: FFaDynCB.H:75
#define MAKE_METHODCB(nr, addedTemplateArgs, argumentList, parameterList, typeList, addedTypeList)
Definition: FFaDynCB.H:123
#define FFADYNCB_H_ADDED_TYPE_LIST1
Definition: FFaDynCB.H:64
#define FFADYNCB_H_ADDED_TEMPLATE_ARGS2
Definition: FFaDynCB.H:72
#define FFADYNCB_H_TYPE_LIST1
Definition: FFaDynCB.H:63
#define FFADYNCB_H_ADDED_TYPE_LIST3
Definition: FFaDynCB.H:83
#define FFADYNCB_H_TYPE_LIST2
Definition: FFaDynCB.H:73
#define MAKE_STATICCB(nr, templateDef, argumentList, parameterList, typeList)
Definition: FFaDynCB.H:152
#define FFADYNCB_H_ARGUMENT_LIST3
Definition: FFaDynCB.H:84
#define FFADYNCB_H_ADDED_TEMPLATE_ARGS3
Definition: FFaDynCB.H:81
#define FFADYNCB_H_TEMPLATE1
Definition: FFaDynCB.H:61