[540] | 1 | /*! |
---|
| 2 | \file declare_ref_func.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \date 02 Dec 2014 |
---|
| 5 | \since 02 Dec 2014 |
---|
| 6 | |
---|
[750] | 7 | \brief Macros to add functions used to solve references in class CDomain, CAxis and CField |
---|
[540] | 8 | */ |
---|
| 9 | #ifndef __XIOS_DECLARE_REF_FUNC_HPP__ |
---|
| 10 | #define __XIOS_DECLARE_REF_FUNC_HPP__ |
---|
| 11 | |
---|
[750] | 12 | // Declarations |
---|
[540] | 13 | |
---|
[750] | 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; \ |
---|
[540] | 30 | |
---|
[750] | 31 | // Definitions |
---|
| 32 | |
---|
| 33 | #define DEFINE_REF_FUNC(type, name) \ |
---|
[540] | 34 | void C##type::solveRefInheritance(bool apply) \ |
---|
[750] | 35 | { \ |
---|
[751] | 36 | std::set<C##type*> refObjects; \ |
---|
[750] | 37 | C##type* refer_ptr = this; \ |
---|
| 38 | \ |
---|
| 39 | while (refer_ptr->hasDirect##type##Reference()) \ |
---|
| 40 | { \ |
---|
[751] | 41 | refObjects.insert(refer_ptr); \ |
---|
| 42 | \ |
---|
[750] | 43 | refer_ptr = refer_ptr->getDirect##type##Reference(); \ |
---|
| 44 | \ |
---|
[751] | 45 | if (refObjects.end() != refObjects.find(refer_ptr)) \ |
---|
[750] | 46 | { \ |
---|
[751] | 47 | ERROR("void C" #type "::solveRefInheritance(bool apply)", \ |
---|
| 48 | << "Circular dependency stopped for " #name " object " \ |
---|
| 49 | << "with id = \"" << refer_ptr->getId() << "\"."); \ |
---|
[750] | 50 | } \ |
---|
| 51 | \ |
---|
| 52 | SuperClassAttribute::setAttributes(refer_ptr, apply); \ |
---|
| 53 | } \ |
---|
| 54 | } \ |
---|
| 55 | \ |
---|
[540] | 56 | void C##type::removeRefInheritance() \ |
---|
[750] | 57 | { \ |
---|
| 58 | if (!this->name##_ref.isEmpty()) \ |
---|
| 59 | this->name##_ref.reset(); \ |
---|
| 60 | } \ |
---|
| 61 | \ |
---|
[540] | 62 | void C##type::solveBaseReference(void) \ |
---|
[750] | 63 | { \ |
---|
[751] | 64 | std::set<C##type*> refObjects; \ |
---|
[750] | 65 | baseRefObject = C##type::get(this); \ |
---|
| 66 | \ |
---|
| 67 | while (baseRefObject->hasDirect##type##Reference()) \ |
---|
| 68 | { \ |
---|
[751] | 69 | refObjects.insert(baseRefObject); \ |
---|
| 70 | \ |
---|
[750] | 71 | baseRefObject = baseRefObject->getDirect##type##Reference(); \ |
---|
| 72 | \ |
---|
[751] | 73 | if (refObjects.end() != refObjects.find(baseRefObject)) \ |
---|
[750] | 74 | { \ |
---|
[751] | 75 | ERROR("void C" #type "::solveBaseReference(void)", \ |
---|
| 76 | << "Circular dependency stopped for " #name " object " \ |
---|
| 77 | << "with id = \"" << baseRefObject->getId() << "\"."); \ |
---|
[750] | 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)) \ |
---|
[752] | 90 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
| 91 | << this->name##_ref \ |
---|
| 92 | << " refers to an unknown " #name " id."); \ |
---|
[750] | 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 | } \ |
---|
[540] | 121 | |
---|
| 122 | #endif // __XIOS_DECLARE_REF_FUNC_HPP__ |
---|