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 | void solveRefInheritance(bool apply = true); \ |
---|
17 | void removeRefInheritance(); \ |
---|
18 | bool hasDirect##type##Reference(void) const; \ |
---|
19 | C##type* getDirect##type##Reference(void) const; \ |
---|
20 | const StdString& get##type##OutputName(void) const; \ |
---|
21 | void setAttributesReference(bool apply = true); \ |
---|
22 | \ |
---|
23 | private: \ |
---|
24 | std::vector<C##type*> refObjects; \ |
---|
25 | |
---|
26 | // Definitions |
---|
27 | |
---|
28 | #define DEFINE_REF_FUNC(type, name_) \ |
---|
29 | void C##type::solveRefInheritance(bool apply) \ |
---|
30 | { \ |
---|
31 | std::set<C##type*> tmpRefObjects; \ |
---|
32 | C##type* refer_ptr = this; \ |
---|
33 | refObjects.push_back(this); \ |
---|
34 | \ |
---|
35 | while (refer_ptr->hasDirect##type##Reference()) \ |
---|
36 | { \ |
---|
37 | tmpRefObjects.insert(refer_ptr); \ |
---|
38 | \ |
---|
39 | refer_ptr = refer_ptr->getDirect##type##Reference(); \ |
---|
40 | \ |
---|
41 | if (tmpRefObjects.end() != tmpRefObjects.find(refer_ptr)) \ |
---|
42 | { \ |
---|
43 | ERROR("void C" #type "::solveRefInheritance(bool apply)", \ |
---|
44 | << "Circular dependency stopped for " #name_ " object " \ |
---|
45 | << "with id = \"" << refer_ptr->getId() << "\"."); \ |
---|
46 | } \ |
---|
47 | \ |
---|
48 | refObjects.push_back(refer_ptr); \ |
---|
49 | SuperClassAttribute::setAttributes(refer_ptr, apply); \ |
---|
50 | } \ |
---|
51 | } \ |
---|
52 | \ |
---|
53 | void C##type::setAttributesReference(bool apply) \ |
---|
54 | { \ |
---|
55 | for (int i = 1; i < refObjects.size(); ++i) \ |
---|
56 | refObjects[i]->setAttributes(refObjects[i-1], apply); \ |
---|
57 | if (refObjects.size() > 1) \ |
---|
58 | refObjects[refObjects.size()-1]->removeRefInheritance(); \ |
---|
59 | } \ |
---|
60 | \ |
---|
61 | void C##type::removeRefInheritance() \ |
---|
62 | { \ |
---|
63 | if (!this->name_##_ref.isEmpty()) \ |
---|
64 | this->name_##_ref.reset(); \ |
---|
65 | } \ |
---|
66 | \ |
---|
67 | bool C##type::hasDirect##type##Reference(void) const \ |
---|
68 | { \ |
---|
69 | return !this->name_##_ref.isEmpty(); \ |
---|
70 | } \ |
---|
71 | \ |
---|
72 | C##type* C##type::getDirect##type##Reference(void) const \ |
---|
73 | { \ |
---|
74 | if (this->name_##_ref.isEmpty()) \ |
---|
75 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
76 | << "The " #name_ " with id = '" << getId() << "'" \ |
---|
77 | << " has no " #name_ "_ref."); \ |
---|
78 | \ |
---|
79 | if (!C##type::has(this->name_##_ref)) \ |
---|
80 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
81 | << this->name_##_ref \ |
---|
82 | << " refers to an unknown " #name_ " id."); \ |
---|
83 | \ |
---|
84 | return C##type::get(this->name_##_ref); \ |
---|
85 | } \ |
---|
86 | \ |
---|
87 | const StdString& C##type::get##type##OutputName(void) const \ |
---|
88 | { \ |
---|
89 | if (!this->name.isEmpty()) \ |
---|
90 | return this->name; \ |
---|
91 | else if (hasAutoGeneratedId() && hasDirect##type##Reference()) \ |
---|
92 | return this->name_##_ref; \ |
---|
93 | else \ |
---|
94 | return getId(); \ |
---|
95 | } \ |
---|
96 | |
---|
97 | #endif // __XIOS_DECLARE_REF_FUNC_HPP__ |
---|