[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: \ |
---|
[771] | 16 | void solveRefInheritance(bool apply = true); \ |
---|
| 17 | void removeRefInheritance(); \ |
---|
[750] | 18 | bool hasDirect##type##Reference(void) const; \ |
---|
| 19 | C##type* getDirect##type##Reference(void) const; \ |
---|
[770] | 20 | const StdString& get##type##OutputName(void) const; \ |
---|
[775] | 21 | void setAttributesBaseReference(bool apply = true); \ |
---|
[540] | 22 | |
---|
[750] | 23 | // Definitions |
---|
| 24 | |
---|
[770] | 25 | #define DEFINE_REF_FUNC(type, name_) \ |
---|
[540] | 26 | void C##type::solveRefInheritance(bool apply) \ |
---|
[750] | 27 | { \ |
---|
[751] | 28 | std::set<C##type*> refObjects; \ |
---|
[750] | 29 | C##type* refer_ptr = this; \ |
---|
| 30 | \ |
---|
| 31 | while (refer_ptr->hasDirect##type##Reference()) \ |
---|
| 32 | { \ |
---|
[751] | 33 | refObjects.insert(refer_ptr); \ |
---|
| 34 | \ |
---|
[750] | 35 | refer_ptr = refer_ptr->getDirect##type##Reference(); \ |
---|
| 36 | \ |
---|
[751] | 37 | if (refObjects.end() != refObjects.find(refer_ptr)) \ |
---|
[750] | 38 | { \ |
---|
[751] | 39 | ERROR("void C" #type "::solveRefInheritance(bool apply)", \ |
---|
[770] | 40 | << "Circular dependency stopped for " #name_ " object " \ |
---|
[751] | 41 | << "with id = \"" << refer_ptr->getId() << "\"."); \ |
---|
[750] | 42 | } \ |
---|
| 43 | \ |
---|
| 44 | SuperClassAttribute::setAttributes(refer_ptr, apply); \ |
---|
| 45 | } \ |
---|
| 46 | } \ |
---|
| 47 | \ |
---|
[775] | 48 | void C##type::setAttributesBaseReference(bool apply) \ |
---|
| 49 | { \ |
---|
| 50 | baseRefObject->setAttributes(this, apply); \ |
---|
| 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 | \ |
---|
[771] | 59 | bool C##type::hasDirect##type##Reference(void) const \ |
---|
[750] | 60 | { \ |
---|
[771] | 61 | return !this->name_##_ref.isEmpty(); \ |
---|
[750] | 62 | } \ |
---|
| 63 | \ |
---|
| 64 | C##type* C##type::getDirect##type##Reference(void) const \ |
---|
| 65 | { \ |
---|
[770] | 66 | if (this->name_##_ref.isEmpty()) \ |
---|
[771] | 67 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
| 68 | << "The " #name_ " with id = '" << getId() << "'" \ |
---|
| 69 | << " has no " #name_ "_ref."); \ |
---|
[750] | 70 | \ |
---|
[770] | 71 | if (!C##type::has(this->name_##_ref)) \ |
---|
[752] | 72 | ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \ |
---|
[770] | 73 | << this->name_##_ref \ |
---|
| 74 | << " refers to an unknown " #name_ " id."); \ |
---|
[750] | 75 | \ |
---|
[770] | 76 | return C##type::get(this->name_##_ref); \ |
---|
[750] | 77 | } \ |
---|
| 78 | \ |
---|
[770] | 79 | const StdString& C##type::get##type##OutputName(void) const \ |
---|
| 80 | { \ |
---|
| 81 | if (!this->name.isEmpty()) \ |
---|
| 82 | return this->name; \ |
---|
| 83 | else if (hasAutoGeneratedId() && hasDirect##type##Reference()) \ |
---|
| 84 | return this->name_##_ref; \ |
---|
| 85 | else \ |
---|
| 86 | return getId(); \ |
---|
| 87 | } \ |
---|
[540] | 88 | |
---|
| 89 | #endif // __XIOS_DECLARE_REF_FUNC_HPP__ |
---|