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

Last change on this file since 930 was 922, checked in by mhnguyen, 8 years ago

Correcting compilation error with gcc 4.8

+) Remove some part which made gcc complain

Test
+) Compilation OK

  • Property svn:executable set to *
File size: 6.8 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  StdString outputName_;
26
27// Definitions
28
29#define DEFINE_REF_FUNC(type, name_)                                   \
30void C##type::solveRefInheritance(bool apply)                          \
31{                                                                      \
32  std::set<C##type*> tmpRefObjects;                                    \
33  C##type* refer_ptr = this;                                           \
34  refObjects.push_back(this);                                          \
35                                                                       \
36  while (refer_ptr->hasDirect##type##Reference())                      \
37  {                                                                    \
38    tmpRefObjects.insert(refer_ptr);                                   \
39                                                                       \
40    refer_ptr = refer_ptr->getDirect##type##Reference();               \
41                                                                       \
42    if (tmpRefObjects.end() != tmpRefObjects.find(refer_ptr))          \
43    {                                                                  \
44      ERROR("void C" #type "::solveRefInheritance(bool apply)",        \
45            << "Circular dependency stopped for " #name_ " object "    \
46            << "with id = \"" << refer_ptr->getId() << "\".");         \
47    }                                                                  \
48                                                                       \
49    refObjects.push_back(refer_ptr);                                   \
50    SuperClassAttribute::setAttributes(refer_ptr, apply);              \
51  }                                                                    \
52}                                                                      \
53                                                                       \
54void C##type::setAttributesReference(bool apply)                       \
55{                                                                      \
56  for (int i = 1; i < refObjects.size(); ++i)                          \
57    refObjects[i]->setAttributes(refObjects[i-1], apply);              \
58  if (refObjects.size() > 1)                                           \
59    refObjects[refObjects.size()-1]->removeRefInheritance();           \
60}                                                                      \
61                                                                       \
62void C##type::removeRefInheritance()                                   \
63{                                                                      \
64  if (!this->name_##_ref.isEmpty())                                    \
65    this->name_##_ref.reset();                                         \
66}                                                                      \
67                                                                       \
68bool C##type::hasDirect##type##Reference(void) const                   \
69{                                                                      \
70  return !this->name_##_ref.isEmpty();                                 \
71}                                                                      \
72                                                                       \
73C##type* C##type::getDirect##type##Reference(void) const               \
74{                                                                      \
75  if (this->name_##_ref.isEmpty())                                     \
76    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
77          << "The " #name_ " with id = '" << getId() << "'"            \
78          << " has no " #name_ "_ref.");                               \
79                                                                       \
80  if (!C##type::has(this->name_##_ref))                                \
81    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
82          << this->name_##_ref                                         \
83          << " refers to an unknown " #name_ " id.");                  \
84                                                                       \
85  return C##type::get(this->name_##_ref);                              \
86}                                                                      \
87                                                                       \
88const StdString& C##type::get##type##OutputName(void) const            \
89{                                                                      \
90  if (!this->name.isEmpty())                                           \
91    return this->name;                                                 \
92  else if (hasDirect##type##Reference())                               \
93  {                                                                    \
94    const C##type* refer_ptr = this, *tmp_ptr;                         \
95    StdString nameRef = this->name_##_ref;                             \
96    while (refer_ptr->hasAutoGeneratedId() &&                          \
97          (C##type::has(nameRef)))                                     \
98    {                                                                  \
99      tmp_ptr = refer_ptr;                                             \
100      refer_ptr = tmp_ptr->getDirect##type##Reference();               \
101      if (refer_ptr->hasDirect##type##Reference())                     \
102        nameRef = refer_ptr->name_##_ref;                              \
103    }                                                                  \
104    return refer_ptr->name_##_ref;                                     \
105  }                                                                    \
106  else                                                                 \
107    return getId();                                                    \
108}                                                                      \
109
110#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.