[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 | |
---|
[770] | 14 | #define DECLARE_REF_FUNC(type, name_) \ |
---|
[750] | 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 | void removeRefInheritance(); \ |
---|
| 20 | const StdString& getBase##type##Id(void) const; \ |
---|
| 21 | void solveRefInheritance(bool apply = true); \ |
---|
| 22 | void solveBaseReference(void); \ |
---|
[770] | 23 | const StdString& get##type##OutputName(void) const; \ |
---|
[750] | 24 | \ |
---|
| 25 | private: \ |
---|
| 26 | C##type* baseRefObject; \ |
---|
[540] | 27 | |
---|
[750] | 28 | // Definitions |
---|
| 29 | |
---|
[770] | 30 | #define DEFINE_REF_FUNC(type, name_) \ |
---|
[540] | 31 | void C##type::solveRefInheritance(bool apply) \ |
---|
[750] | 32 | { \ |
---|
[751] | 33 | std::set<C##type*> refObjects; \ |
---|
[750] | 34 | C##type* refer_ptr = this; \ |
---|
| 35 | \ |
---|
| 36 | while (refer_ptr->hasDirect##type##Reference()) \ |
---|
| 37 | { \ |
---|
[751] | 38 | refObjects.insert(refer_ptr); \ |
---|
| 39 | \ |
---|
[750] | 40 | refer_ptr = refer_ptr->getDirect##type##Reference(); \ |
---|
| 41 | \ |
---|
[751] | 42 | if (refObjects.end() != refObjects.find(refer_ptr)) \ |
---|
[750] | 43 | { \ |
---|
[751] | 44 | ERROR("void C" #type "::solveRefInheritance(bool apply)", \ |
---|
[770] | 45 | << "Circular dependency stopped for " #name_ " object " \ |
---|
[751] | 46 | << "with id = \"" << refer_ptr->getId() << "\"."); \ |
---|
[750] | 47 | } \ |
---|
| 48 | \ |
---|
| 49 | SuperClassAttribute::setAttributes(refer_ptr, apply); \ |
---|
| 50 | } \ |
---|
| 51 | } \ |
---|
| 52 | \ |
---|
[540] | 53 | void C##type::removeRefInheritance() \ |
---|
[750] | 54 | { \ |
---|
[770] | 55 | if (!this->name_##_ref.isEmpty()) \ |
---|
| 56 | this->name_##_ref.reset(); \ |
---|
[750] | 57 | } \ |
---|
| 58 | \ |
---|
[540] | 59 | void C##type::solveBaseReference(void) \ |
---|
[750] | 60 | { \ |
---|
[751] | 61 | std::set<C##type*> refObjects; \ |
---|
[750] | 62 | baseRefObject = C##type::get(this); \ |
---|
| 63 | \ |
---|
| 64 | while (baseRefObject->hasDirect##type##Reference()) \ |
---|
| 65 | { \ |
---|
[751] | 66 | refObjects.insert(baseRefObject); \ |
---|
| 67 | \ |
---|
[750] | 68 | baseRefObject = baseRefObject->getDirect##type##Reference(); \ |
---|
| 69 | \ |
---|
[751] | 70 | if (refObjects.end() != refObjects.find(baseRefObject)) \ |
---|
[750] | 71 | { \ |
---|
[751] | 72 | ERROR("void C" #type "::solveBaseReference(void)", \ |
---|
[770] | 73 | << "Circular dependency stopped for " #name_ " object " \ |
---|
[751] | 74 | << "with id = \"" << baseRefObject->getId() << "\"."); \ |
---|
[750] | 75 | } \ |
---|
| 76 | } \ |
---|
| 77 | } \ |
---|
| 78 | \ |
---|
| 79 | C##type* C##type::getDirect##type##Reference(void) const \ |
---|
| 80 | { \ |
---|
[770] | 81 | if (this->name_##_ref.isEmpty()) \ |
---|
[750] | 82 | return this->getBase##type##Reference(); \ |
---|
| 83 | \ |
---|
[770] | 84 | if (!C##type::has(this->name_##_ref)) \ |
---|
[752] | 85 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
[770] | 86 | << this->name_##_ref \ |
---|
| 87 | << " refers to an unknown " #name_ " id."); \ |
---|
[750] | 88 | \ |
---|
[770] | 89 | return C##type::get(this->name_##_ref); \ |
---|
[750] | 90 | } \ |
---|
| 91 | \ |
---|
| 92 | C##type* C##type::getBase##type##Reference(void) const \ |
---|
| 93 | { \ |
---|
| 94 | return baseRefObject; \ |
---|
| 95 | } \ |
---|
| 96 | \ |
---|
| 97 | const StdString& C##type::getBase##type##Id(void) const \ |
---|
| 98 | { \ |
---|
| 99 | return this->getBase##type##Reference()->getId(); \ |
---|
| 100 | } \ |
---|
| 101 | bool C##type::hasDirect##type##Reference(void) const \ |
---|
| 102 | { \ |
---|
[770] | 103 | return !this->name_##_ref.isEmpty(); \ |
---|
[750] | 104 | } \ |
---|
[770] | 105 | \ |
---|
| 106 | const StdString& C##type::get##type##OutputName(void) const \ |
---|
| 107 | { \ |
---|
| 108 | if (!this->name.isEmpty()) \ |
---|
| 109 | return this->name; \ |
---|
| 110 | else if (hasAutoGeneratedId() && hasDirect##type##Reference()) \ |
---|
| 111 | return this->name_##_ref; \ |
---|
| 112 | else \ |
---|
| 113 | return getId(); \ |
---|
| 114 | } \ |
---|
[540] | 115 | |
---|
| 116 | #endif // __XIOS_DECLARE_REF_FUNC_HPP__ |
---|