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

Last change on this file since 768 was 768, checked in by rlacroix, 8 years ago

Remove now unused reference tracking.

File size: 6.5 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  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);                            \
23                                                            \
24private:                                                    \
25  C##type* baseRefObject;                                   \
26
27// Definitions
28
29#define DEFINE_REF_FUNC(type, name)                                    \
30void C##type::solveRefInheritance(bool apply)                          \
31{                                                                      \
32  std::set<C##type*> refObjects;                                       \
33  C##type* refer_ptr = this;                                           \
34                                                                       \
35  while (refer_ptr->hasDirect##type##Reference())                      \
36  {                                                                    \
37    refObjects.insert(refer_ptr);                                      \
38                                                                       \
39    refer_ptr = refer_ptr->getDirect##type##Reference();               \
40                                                                       \
41    if (refObjects.end() != refObjects.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    SuperClassAttribute::setAttributes(refer_ptr, apply);              \
49  }                                                                    \
50}                                                                      \
51                                                                       \
52void C##type::removeRefInheritance()                                   \
53{                                                                      \
54  if (!this->name##_ref.isEmpty())                                     \
55    this->name##_ref.reset();                                          \
56}                                                                      \
57                                                                       \
58void C##type::solveBaseReference(void)                                 \
59{                                                                      \
60  std::set<C##type*> refObjects;                                       \
61  baseRefObject = C##type::get(this);                                  \
62                                                                       \
63  while (baseRefObject->hasDirect##type##Reference())                  \
64  {                                                                    \
65    refObjects.insert(baseRefObject);                                  \
66                                                                       \
67    baseRefObject = baseRefObject->getDirect##type##Reference();       \
68                                                                       \
69    if (refObjects.end() != refObjects.find(baseRefObject))            \
70    {                                                                  \
71      ERROR("void C" #type "::solveBaseReference(void)",               \
72            << "Circular dependency stopped for " #name " object "     \
73            << "with id = \"" << baseRefObject->getId() << "\".");     \
74    }                                                                  \
75  }                                                                    \
76}                                                                      \
77                                                                       \
78C##type* C##type::getDirect##type##Reference(void) const               \
79{                                                                      \
80  if (this->name##_ref.isEmpty())                                      \
81    return this->getBase##type##Reference();                           \
82                                                                       \
83  if (!C##type::has(this->name##_ref))                                 \
84    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
85          << this->name##_ref                                          \
86          << " refers to an unknown " #name " id.");                   \
87                                                                       \
88  return C##type::get(this->name##_ref);                               \
89}                                                                      \
90                                                                       \
91C##type* C##type::getBase##type##Reference(void) const                 \
92{                                                                      \
93  return baseRefObject;                                                \
94}                                                                      \
95                                                                       \
96const StdString& C##type::getBase##type##Id(void) const                \
97{                                                                      \
98  return this->getBase##type##Reference()->getId();                    \
99}                                                                      \
100                                                                       \
101bool C##type::hasDirect##type##Reference(void) const                   \
102{                                                                      \
103  return !this->name##_ref.isEmpty();                                  \
104}                                                                      \
105
106#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.