source: XIOS/trunk/src/declare_ref_func.hpp @ 890

Last change on this file since 890 was 820, checked in by mhnguyen, 8 years ago

Fixing duplicate *_ref on reading attributes from file

+) Remove *_ref from *_ref root of the reference tree

Test
+) On Curie
+) Test passes

  • Property svn:executable set to *
File size: 5.9 KB
RevLine 
[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]15public:                                                     \
[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;       \
[777]21  void setAttributesReference(bool apply = true);       \
22                                                                       \
23private:                                                               \
24  std::vector<C##type*> refObjects;                                    \
[540]25
[750]26// Definitions
27
[770]28#define DEFINE_REF_FUNC(type, name_)                                   \
[540]29void C##type::solveRefInheritance(bool apply)                          \
[750]30{                                                                      \
[777]31  std::set<C##type*> tmpRefObjects;                                    \
[750]32  C##type* refer_ptr = this;                                           \
[777]33  refObjects.push_back(this);                                          \
[750]34                                                                       \
35  while (refer_ptr->hasDirect##type##Reference())                      \
36  {                                                                    \
[777]37    tmpRefObjects.insert(refer_ptr);                                   \
[751]38                                                                       \
[750]39    refer_ptr = refer_ptr->getDirect##type##Reference();               \
40                                                                       \
[777]41    if (tmpRefObjects.end() != tmpRefObjects.find(refer_ptr))          \
[750]42    {                                                                  \
[751]43      ERROR("void C" #type "::solveRefInheritance(bool apply)",        \
[770]44            << "Circular dependency stopped for " #name_ " object "    \
[751]45            << "with id = \"" << refer_ptr->getId() << "\".");         \
[750]46    }                                                                  \
47                                                                       \
[777]48    refObjects.push_back(refer_ptr);                                   \
[750]49    SuperClassAttribute::setAttributes(refer_ptr, apply);              \
50  }                                                                    \
51}                                                                      \
52                                                                       \
[777]53void C##type::setAttributesReference(bool apply)                       \
[775]54{                                                                      \
[777]55  for (int i = 1; i < refObjects.size(); ++i)                          \
[820]56    refObjects[i]->setAttributes(refObjects[i-1], apply);              \
57  if (refObjects.size() > 1)                                           \
58    refObjects[refObjects.size()-1]->removeRefInheritance();           \
[775]59}                                                                      \
60                                                                       \
[540]61void C##type::removeRefInheritance()                                   \
[750]62{                                                                      \
[770]63  if (!this->name_##_ref.isEmpty())                                    \
64    this->name_##_ref.reset();                                         \
[750]65}                                                                      \
66                                                                       \
[771]67bool C##type::hasDirect##type##Reference(void) const                   \
[750]68{                                                                      \
[771]69  return !this->name_##_ref.isEmpty();                                 \
[750]70}                                                                      \
71                                                                       \
72C##type* C##type::getDirect##type##Reference(void) const               \
73{                                                                      \
[770]74  if (this->name_##_ref.isEmpty())                                     \
[771]75    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
76          << "The " #name_ " with id = '" << getId() << "'"            \
77          << " has no " #name_ "_ref.");                               \
[750]78                                                                       \
[770]79  if (!C##type::has(this->name_##_ref))                                \
[752]80    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
[770]81          << this->name_##_ref                                         \
82          << " refers to an unknown " #name_ " id.");                  \
[750]83                                                                       \
[770]84  return C##type::get(this->name_##_ref);                              \
[750]85}                                                                      \
86                                                                       \
[770]87const 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}                                                                      \
[540]96
97#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.