1 | /*! |
---|
2 | \file declare_ref_func.hpp |
---|
3 | \author Ha NGUYEN |
---|
4 | \date 02 Dec 2014 |
---|
5 | \since 02 Dec 2014 |
---|
6 | |
---|
7 | \brief Macros to add functions used to solve references in class CDomain, CAxis and CField |
---|
8 | */ |
---|
9 | #ifndef __XIOS_DECLARE_REF_FUNC_HPP__ |
---|
10 | #define __XIOS_DECLARE_REF_FUNC_HPP__ |
---|
11 | |
---|
12 | // Declarations |
---|
13 | |
---|
14 | #define DECLARE_REF_FUNC(type, name) \ |
---|
15 | public: \ |
---|
16 | bool hasDirect##type##Reference(void) const; \ |
---|
17 | C##type* getDirect##type##Reference(void) const; \ |
---|
18 | C##type* getBase##type##Reference(void) const; \ |
---|
19 | const std::vector<C##type*>& getAllReference(void) const; \ |
---|
20 | void removeRefInheritance(); \ |
---|
21 | const StdString& getBase##type##Id(void) const; \ |
---|
22 | void solveRefInheritance(bool apply = true); \ |
---|
23 | void solveBaseReference(void); \ |
---|
24 | \ |
---|
25 | private: \ |
---|
26 | void addReference(C##type* _##name##_); \ |
---|
27 | \ |
---|
28 | std::vector<C##type*> refObject; \ |
---|
29 | C##type* baseRefObject; \ |
---|
30 | |
---|
31 | // Definitions |
---|
32 | |
---|
33 | #define DEFINE_REF_FUNC(type, name) \ |
---|
34 | void C##type::solveRefInheritance(bool apply) \ |
---|
35 | { \ |
---|
36 | std::set<C##type*> refObjects; \ |
---|
37 | C##type* refer_ptr = this; \ |
---|
38 | \ |
---|
39 | while (refer_ptr->hasDirect##type##Reference()) \ |
---|
40 | { \ |
---|
41 | refObjects.insert(refer_ptr); \ |
---|
42 | \ |
---|
43 | refer_ptr = refer_ptr->getDirect##type##Reference(); \ |
---|
44 | \ |
---|
45 | if (refObjects.end() != refObjects.find(refer_ptr)) \ |
---|
46 | { \ |
---|
47 | ERROR("void C" #type "::solveRefInheritance(bool apply)", \ |
---|
48 | << "Circular dependency stopped for " #name " object " \ |
---|
49 | << "with id = \"" << refer_ptr->getId() << "\"."); \ |
---|
50 | } \ |
---|
51 | \ |
---|
52 | SuperClassAttribute::setAttributes(refer_ptr, apply); \ |
---|
53 | } \ |
---|
54 | } \ |
---|
55 | \ |
---|
56 | void C##type::removeRefInheritance() \ |
---|
57 | { \ |
---|
58 | if (!this->name##_ref.isEmpty()) \ |
---|
59 | this->name##_ref.reset(); \ |
---|
60 | } \ |
---|
61 | \ |
---|
62 | void C##type::solveBaseReference(void) \ |
---|
63 | { \ |
---|
64 | std::set<C##type*> refObjects; \ |
---|
65 | baseRefObject = C##type::get(this); \ |
---|
66 | \ |
---|
67 | while (baseRefObject->hasDirect##type##Reference()) \ |
---|
68 | { \ |
---|
69 | refObjects.insert(baseRefObject); \ |
---|
70 | \ |
---|
71 | baseRefObject = baseRefObject->getDirect##type##Reference(); \ |
---|
72 | \ |
---|
73 | if (refObjects.end() != refObjects.find(baseRefObject)) \ |
---|
74 | { \ |
---|
75 | ERROR("void C" #type "::solveBaseReference(void)", \ |
---|
76 | << "Circular dependency stopped for " #name " object " \ |
---|
77 | << "with id = \"" << baseRefObject->getId() << "\"."); \ |
---|
78 | } \ |
---|
79 | } \ |
---|
80 | \ |
---|
81 | if (hasDirect##type##Reference()) baseRefObject->addReference(this); \ |
---|
82 | } \ |
---|
83 | \ |
---|
84 | C##type* C##type::getDirect##type##Reference(void) const \ |
---|
85 | { \ |
---|
86 | if (this->name##_ref.isEmpty()) \ |
---|
87 | return this->getBase##type##Reference(); \ |
---|
88 | \ |
---|
89 | if (!C##type::has(this->name##_ref)) \ |
---|
90 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
91 | << this->name##_ref \ |
---|
92 | << " refers to an unknown " #name " id."); \ |
---|
93 | \ |
---|
94 | return C##type::get(this->name##_ref); \ |
---|
95 | } \ |
---|
96 | \ |
---|
97 | C##type* C##type::getBase##type##Reference(void) const \ |
---|
98 | { \ |
---|
99 | return baseRefObject; \ |
---|
100 | } \ |
---|
101 | \ |
---|
102 | const std::vector<C##type*>& C##type::getAllReference(void) const \ |
---|
103 | { \ |
---|
104 | return refObject; \ |
---|
105 | } \ |
---|
106 | \ |
---|
107 | const StdString& C##type::getBase##type##Id(void) const \ |
---|
108 | { \ |
---|
109 | return this->getBase##type##Reference()->getId(); \ |
---|
110 | } \ |
---|
111 | \ |
---|
112 | void C##type::addReference(C##type* _##name##_) \ |
---|
113 | { \ |
---|
114 | refObject.push_back(_##name##_); \ |
---|
115 | } \ |
---|
116 | \ |
---|
117 | bool C##type::hasDirect##type##Reference(void) const \ |
---|
118 | { \ |
---|
119 | return !this->name##_ref.isEmpty(); \ |
---|
120 | } \ |
---|
121 | |
---|
122 | #endif // __XIOS_DECLARE_REF_FUNC_HPP__ |
---|