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

Last change on this file since 794 was 777, checked in by mhnguyen, 9 years ago

Fixing some minors bug during merge

Test
+) On Curie
+) test_remap passes

  • Property svn:executable set to *
File size: 5.7 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)                          \
56    refObjects[i]->setAttributes(refObjects[0], apply);                \
[775]57}                                                                      \
58                                                                       \
[540]59void C##type::removeRefInheritance()                                   \
[750]60{                                                                      \
[770]61  if (!this->name_##_ref.isEmpty())                                    \
62    this->name_##_ref.reset();                                         \
[750]63}                                                                      \
64                                                                       \
[771]65bool C##type::hasDirect##type##Reference(void) const                   \
[750]66{                                                                      \
[771]67  return !this->name_##_ref.isEmpty();                                 \
[750]68}                                                                      \
69                                                                       \
70C##type* C##type::getDirect##type##Reference(void) const               \
71{                                                                      \
[770]72  if (this->name_##_ref.isEmpty())                                     \
[771]73    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
74          << "The " #name_ " with id = '" << getId() << "'"            \
75          << " has no " #name_ "_ref.");                               \
[750]76                                                                       \
[770]77  if (!C##type::has(this->name_##_ref))                                \
[752]78    ERROR("C" #type "* C" #type "::getDirect" #type "Reference(void)", \
[770]79          << this->name_##_ref                                         \
80          << " refers to an unknown " #name_ " id.");                  \
[750]81                                                                       \
[770]82  return C##type::get(this->name_##_ref);                              \
[750]83}                                                                      \
84                                                                       \
[770]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}                                                                      \
[540]94
95#endif // __XIOS_DECLARE_REF_FUNC_HPP__
Note: See TracBrowser for help on using the repository browser.