FEDEM Model Database  R8.0
Source code of the FEDEM model database
FFaTypeCheck.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_TYPE_CHECK_H
16 #define FFA_TYPE_CHECK_H
17 
18 
19 namespace FFaTypeCheck
20 {
22  int getNewTypeID(const char* typeName);
24  int getTypeIDFromName(const char* typeName);
26  const char* getTypeNameFromID(int typeID);
27 
28  constexpr int NO_TYPE_ID = -1;
29 }
30 
31 
39 #define Fmd_HEADER_INIT() \
40 public: \
41  virtual bool isOfType(int tp) const; \
42  virtual int getTypeID() const; \
43  virtual const char* getTypeIDName() const; \
44  \
45  static const char* getClassTypeIDName(); \
46  static int getClassTypeID(); \
47  static int getParentClassTypeID(); \
48  \
49 protected: \
50  static bool staticIsOfType(int tp); \
51  \
52  static int typeID; \
53  static const char* typeIDName
54 
62 #define Fmd_BASE_HEADER_INIT() \
63 protected: \
64  int itsTypeID; \
65  const char* itsTypeIDName; \
66 Fmd_HEADER_INIT()
67 
75 #define Fmd_CONSTRUCTOR_INIT(clType) \
76  itsTypeID = clType::getClassTypeID(); \
77  itsTypeIDName = clType::getClassTypeIDName()
78 
85 #define Fmd_SOURCE_INIT(clName, clType, prClType) \
86  \
87 int clType::typeID = FFaTypeCheck::getNewTypeID(#clName);\
88 const char* clType::typeIDName = #clName; \
89  \
90 int clType::getTypeID() const \
91 { \
92  return itsTypeID; \
93 } \
94  \
95 const char* clType::getTypeIDName() const \
96 { \
97  return itsTypeIDName; \
98 } \
99  \
100 int clType::getClassTypeID() \
101 { \
102  return typeID; \
103 } \
104  \
105 const char* clType::getClassTypeIDName() \
106 { \
107  return typeIDName; \
108 } \
109  \
110 int clType::getParentClassTypeID() \
111 { \
112  return prClType::getClassTypeID(); \
113 } \
114  \
115 bool clType::isOfType(int tp) const \
116 { \
117  if (itsTypeID == tp) \
118  return true; \
119  else \
120  return prClType::staticIsOfType(tp); \
121 } \
122  \
123 bool clType::staticIsOfType(int tp) \
124 { \
125  if (typeID == tp) \
126  return true; \
127  else if (typeID == prClType::getClassTypeID()) \
128  return false; \
129  else \
130  return prClType::staticIsOfType(tp); \
131 }
132 
133 #endif
Type checking control.
Definition: FFaTypeCheck.H:20
int getNewTypeID(const char *typeName)
Returns a unique type ID number for typeName.
Definition: FFaTypeCheck.C:35
constexpr int NO_TYPE_ID
Value for undefined type ID number.
Definition: FFaTypeCheck.H:28
const char * getTypeNameFromID(int typeID)
Returns the type name associated with the specified typeID.
Definition: FFaTypeCheck.C:65
int getTypeIDFromName(const char *typeName)
Returns the type ID number for typeName, if it exists.
Definition: FFaTypeCheck.C:50