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

Last change on this file since 776 was 775, checked in by mhnguyen, 9 years ago

Implementing the reading of attributes of an axis from a file

+) 3d grid can be read directly from a file
+) Clean some redundant codes
+) Add new attribute declaration that allows to output only desired attributes

Test
+) On Curie
+) test_remap passes and result is correct

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