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

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

Remove the now unused base reference framework.

File size: 4.9 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
22// Definitions
23
24#define DEFINE_REF_FUNC(type, name_)                                   \
25void C##type::solveRefInheritance(bool apply)                          \
26{                                                                      \
27  std::set<C##type*> refObjects;                                       \
28  C##type* refer_ptr = this;                                           \
29                                                                       \
30  while (refer_ptr->hasDirect##type##Reference())                      \
31  {                                                                    \
32    refObjects.insert(refer_ptr);                                      \
33                                                                       \
34    refer_ptr = refer_ptr->getDirect##type##Reference();               \
35                                                                       \
36    if (refObjects.end() != refObjects.find(refer_ptr))                \
37    {                                                                  \
38      ERROR("void C" #type "::solveRefInheritance(bool apply)",        \
39            << "Circular dependency stopped for " #name_ " object "    \
40            << "with id = \"" << refer_ptr->getId() << "\".");         \
41    }                                                                  \
42                                                                       \
43    SuperClassAttribute::setAttributes(refer_ptr, apply);              \
44  }                                                                    \
45}                                                                      \
46                                                                       \
47void C##type::removeRefInheritance()                                   \
48{                                                                      \
49  if (!this->name_##_ref.isEmpty())                                    \
50    this->name_##_ref.reset();                                         \
51}                                                                      \
52                                                                       \
53bool C##type::hasDirect##type##Reference(void) const                   \
54{                                                                      \
55  return !this->name_##_ref.isEmpty();                                 \
56}                                                                      \
57                                                                       \
58C##type* C##type::getDirect##type##Reference(void) const               \
59{                                                                      \
60  if (this->name_##_ref.isEmpty())                                     \
61    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
62          << "The " #name_ " with id = '" << getId() << "'"            \
63          << " has no " #name_ "_ref.");                               \
64                                                                       \
65  if (!C##type::has(this->name_##_ref))                                \
66    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
67          << this->name_##_ref                                         \
68          << " refers to an unknown " #name_ " id.");                  \
69                                                                       \
70  return C##type::get(this->name_##_ref);                              \
71}                                                                      \
72                                                                       \
73const StdString& C##type::get##type##OutputName(void) const            \
74{                                                                      \
75  if (!this->name.isEmpty())                                           \
76    return this->name;                                                 \
77  else if (hasAutoGeneratedId() && hasDirect##type##Reference())       \
78    return this->name_##_ref;                                          \
79  else                                                                 \
80    return getId();                                                    \
81}                                                                      \
82
83#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.