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

Last change on this file since 784 was 777, checked in by mhnguyen, 8 years ago

Fixing some minors bug during merge

Test
+) On Curie
+) test_remap passes

  • Property svn:executable set to *
File size: 5.7 KB
Line 
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_)                       \
15public:                                                     \
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                                                                       \
23private:                                                               \
24  std::vector<C##type*> refObjects;                                    \
25
26// Definitions
27
28#define DEFINE_REF_FUNC(type, name_)                                   \
29void 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                                                                       \
53void C##type::setAttributesReference(bool apply)                       \
54{                                                                      \
55  for (int i = 1; i < refObjects.size(); ++i)                          \
56    refObjects[i]->setAttributes(refObjects[0], apply);                \
57}                                                                      \
58                                                                       \
59void C##type::removeRefInheritance()                                   \
60{                                                                      \
61  if (!this->name_##_ref.isEmpty())                                    \
62    this->name_##_ref.reset();                                         \
63}                                                                      \
64                                                                       \
65bool C##type::hasDirect##type##Reference(void) const                   \
66{                                                                      \
67  return !this->name_##_ref.isEmpty();                                 \
68}                                                                      \
69                                                                       \
70C##type* C##type::getDirect##type##Reference(void) const               \
71{                                                                      \
72  if (this->name_##_ref.isEmpty())                                     \
73    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
74          << "The " #name_ " with id = '" << getId() << "'"            \
75          << " has no " #name_ "_ref.");                               \
76                                                                       \
77  if (!C##type::has(this->name_##_ref))                                \
78    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
79          << this->name_##_ref                                         \
80          << " refers to an unknown " #name_ " id.");                  \
81                                                                       \
82  return C##type::get(this->name_##_ref);                              \
83}                                                                      \
84                                                                       \
85const StdString& C##type::get##type##OutputName(void) const            \
86{                                                                      \
87  if (!this->name.isEmpty())                                           \
88    return this->name;                                                 \
89  else if (hasAutoGeneratedId() && hasDirect##type##Reference())       \
90    return this->name_##_ref;                                          \
91  else                                                                 \
92    return getId();                                                    \
93}                                                                      \
94
95#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.