Changeset 1105 for XIOS/trunk/src


Ignore:
Timestamp:
04/25/17 10:57:48 (7 years ago)
Author:
mhnguyen
Message:

Adding comparison operator between objects of XIOS.
Two objects of a same type are considered equal if they have same non-empty
attributes which have same values

+) Add operator== to class CArray
+) Add comparison operator to some basic attribute classes
+) Add operator== to date and duration (It seems that they don't serve much)

Test
+) On Curie
+) No Unit tests but test with transformation work (the next commit)

Location:
XIOS/trunk/src
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/array_new.hpp

    r1050 r1105  
    300300        Array<T_numtype,N_rank>::reference(array); 
    301301        initialized = true; 
     302      } 
     303 
     304      bool operator== (const CArray<T_numtype,N_rank>& array) 
     305      { 
     306        size_t nbThis = this->numElements(); 
     307        size_t nbArr  = array.numElements(); 
     308        if (nbThis != nbArr) return false; 
     309        for (size_t idx = 0; idx < nbThis; ++idx) 
     310          if ((*this)(idx) != array(idx)) return false; 
     311 
     312        return true; 
     313      } 
     314 
     315      bool operator== (const Array<T_numtype,N_rank>& array) 
     316      { 
     317        return ((*this) == (dynamic_cast<const CArray<T_numtype,N_rank>& >(array))); 
    302318      } 
    303319 
  • XIOS/trunk/src/attribute.hpp

    r778 r1105  
    1616{ 
    1717      /// ////////////////////// Déclarations ////////////////////// /// 
     18   /*! 
     19   \class CAttribute 
     20      The fundamental class which describes the attributes of other different class in XIOS. 
     21      This class only plays a role of interface, its class child will have specific implelemtation corresponding to type of attribute 
     22   */ 
    1823      class CAttribute : public CObject, public virtual CBaseType 
    1924      { 
     
    2429            /// Constructeurs /// 
    2530            explicit CAttribute(const StdString & id); 
    26 //            CAttribute(const CAttribute & attribut); 
    27 //            CAttribute(const CAttribute * const attribut); // Not implemented. 
    2831 
    2932            /// Accesseurs /// 
    3033            const StdString & getName(void) const; 
    31 //            const boost::any & getAnyValue(void) const; 
    32 //            template <typename T> inline T getValue(void) const; 
    33 //            template <typename T> inline T* getRef(void); 
    3434 
    35 //            /// Mutateurs /// 
    36 //            template <typename T> inline void setValue(const T & value); 
    37 //            void setAnyValue(const boost::any & value); 
    38 //            void clear(void); 
    39  
    40             /// Test /// 
    41 //            bool isEmpty(void) const; 
    42 //            template <typename T> inline bool isType(void) const; 
    4335            virtual void set(const CAttribute& ) =0 ; 
    4436            virtual void reset(void ) =0 ; 
     
    4941            virtual StdString toString(void) const = 0; 
    5042            virtual void fromString(const StdString & str) = 0; 
    51  
    52 //            virtual void toBinary  (StdOStream & os) const = 0; 
    53 //            virtual void fromBinary(StdIStream & is) = 0; 
     43            virtual bool isEqual(const CAttribute& ) = 0; 
    5444 
    5545            //! Returns true if and only if the attribute should be publicly exposed in the API 
    5646            virtual bool isPublic() const { return true; } 
    5747 
     48            /* 
     49              Groupd of functions to generate C and Fortran interface  
     50            */ 
    5851            virtual void generateCInterface(ostream& oss, const string& className) = 0 ; 
    5952            virtual void generateCInterfaceIsDefined(ostream& oss, const string& className) ; 
     
    7366            virtual bool hasInheritedValue(void) const = 0; 
    7467             
    75          protected : 
    76  
    77             /// Constructeurs /// 
    78 //            CAttribute(void);  // Not implemented. 
    79  
    80             /// Propriété /// 
    81 //            boost::any value; 
     68         protected :  
    8269 
    8370      }; // class CAttribute 
    8471 
    85       /// ////////////////////// Définitions ////////////////////// /// 
    86 /* 
    87       template <typename T> 
    88          T CAttribute::getValue(void) const 
    89       {  
    90          return (boost::any_cast<T>(this->value));  
    91       } 
    92  
    93       template <typename T> 
    94          T* CAttribute::getRef(void) 
    95       {  
    96          return (boost::any_cast<T>(&value));  
    97       } 
    98  
    99       template <typename T> 
    100          void CAttribute::setValue(const T & value) 
    101       {  
    102          this->value = value;  
    103       } 
    104  
    105       template<typename T> 
    106          bool CAttribute::isType(void) const 
    107       {  
    108          return (this->value.type() == typeid(T));  
    109       } 
    110 */ 
    111   
    11272   CMessage& operator<<(CMessage& msg,CAttribute& type) ; 
    11373   CMessage& operator<<(CMessage& msg, const CAttribute&  type) ; 
  • XIOS/trunk/src/attribute_array.hpp

    r780 r1105  
    4040            CArray<T_numtype, N_rank> getInheritedValue(void) const ; 
    4141            bool hasInheritedValue(void) const; 
     42             
     43            bool isEqual(const CAttributeArray& attr); 
     44            bool isEqual(const CAttribute& attr); 
    4245 
    4346            /// Destructeur /// 
  • XIOS/trunk/src/attribute_array_impl.hpp

    r778 r1105  
    103103    } 
    104104 
     105    template <typename T_numtype, int N_rank> 
     106    bool CAttributeArray<T_numtype,N_rank>::isEqual(const CAttributeArray& attr) 
     107    { 
     108      return ((dynamic_cast<CArray<T_numtype,N_rank>& >(*this)) == (dynamic_cast<const CArray<T_numtype,N_rank>& >(attr)));       
     109    } 
     110 
     111    template <typename T_numtype, int N_rank> 
     112    bool CAttributeArray<T_numtype,N_rank>::isEqual(const CAttribute& attr) 
     113    { 
     114      return ((*this) == (dynamic_cast<const CAttributeArray<T_numtype,N_rank>& >(attr)));       
     115    } 
    105116 
    106117    template <typename T_numtype, int N_rank> 
  • XIOS/trunk/src/attribute_enum.hpp

    r591 r1105  
    4747            bool hasInheritedValue(void) const;           
    4848           
     49            bool isEqual(const CAttributeEnum& attr ); 
     50            bool isEqual(const CAttribute& attr ); 
     51 
    4952            /// Destructeur /// 
    5053            virtual ~CAttributeEnum(void) { } 
  • XIOS/trunk/src/attribute_enum_impl.hpp

    r580 r1105  
    111111  } 
    112112 
     113  template <class T> 
     114  bool CAttributeEnum<T>::isEqual(const CAttribute& attr) 
     115  { 
     116    return (this->isEqual(dynamic_cast<const CAttributeEnum<T>& >(attr))); 
     117  } 
     118 
     119  template <class T> 
     120  bool CAttributeEnum<T>::isEqual(const CAttributeEnum& attr) 
     121  { 
     122    return ((dynamic_cast<const CEnum<T>& >(*this)) == (dynamic_cast<const CEnum<T>& >(attr))); 
     123  } 
     124 
    113125  //--------------------------------------------------------------- 
    114126 
  • XIOS/trunk/src/attribute_map.cpp

    r996 r1105  
    1616      ///-------------------------------------------------------------- 
    1717 
     18      /*! 
     19         Clear all attributes of an object and reset them to empty state 
     20      */ 
    1821      void CAttributeMap::clearAllAttributes(void) 
    1922      { 
     
    2932      //--------------------------------------------------------------- 
    3033 
     34      /* 
     35        Clear an attribute and reset its value 
     36        \param[in] key id of attribute 
     37      */ 
    3138      void CAttributeMap::clearAttribute(const StdString& key) 
    3239      { 
     
    3643      //--------------------------------------------------------------- 
    3744 
     45      /*! 
     46        Set an attribute of certain id with a value 
     47        \param[in] key id of the attribute 
     48        \param[in] attr value of attribute 
     49      */ 
    3850      void CAttributeMap::setAttribute(const StdString& key, CAttribute* const attr) 
    3951      { 
     
    5062      //--------------------------------------------------------------- 
    5163 
     64      /*! 
     65        Subscript operator. Return attribute with a specific id 
     66      */ 
    5267      CAttribute* CAttributeMap::operator[](const StdString& key) 
    5368      { 
     
    103118         } 
    104119      } 
     120 
     121      /*! 
     122         Compare two attribute maps 
     123         \param [in] another attribute map to compare 
     124         \return true if these two maps have same attributes whose value are identical 
     125      */ 
     126      bool CAttributeMap::isEqual(const CAttributeMap& another) 
     127      { 
     128         SuperClassMap::const_iterator itb = another.begin(), ite = another.end(), it; 
     129         for (it = itb; it !=ite; ++it) 
     130         { 
     131            if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0) 
     132            { 
     133              if (this->hasAttribute(it->first)) 
     134              {  
     135                if (!((*it).second->isEqual(*(*this)[it->first]))) 
     136                return false; 
     137              } 
     138              else 
     139                return false; 
     140            } 
     141         } 
     142 
     143         return true; 
     144      } 
     145 
    105146 
    106147      //--------------------------------------------------------------- 
     
    139180      } 
    140181 
     182      /*! 
     183        Duplicate attribute map with a specific attribute map. 
     184        Copy all non-empty attribute of the current attribute map 
     185        \param [in] srcAttr attribute map which is copied from. 
     186      */ 
    141187      void CAttributeMap::duplicateAttributes(const CAttributeMap* const srcAttr) 
    142188      { 
     
    216262      } 
    217263 */ 
     264 
     265       
    218266      void CAttributeMap::generateCInterface(ostream& oss, const string& className) 
    219267      { 
  • XIOS/trunk/src/attribute_map.hpp

    r996 r1105  
    1212{ 
    1313      /// ////////////////////// Déclarations ////////////////////// /// 
     14      /*! 
     15        \class CAttributeMap 
     16        This class represents the set of attributes which an object can have. 
     17      */ 
     18 
    1419      class CAttributeMap 
    1520         : public xios_map<StdString, CAttribute*> 
     
    3439 
    3540            void clearAttribute(const StdString& key); 
     41            bool isEqual(const CAttributeMap& another); 
    3642 
    3743            /// Destructeur /// 
  • XIOS/trunk/src/attribute_template.hpp

    r780 r1105  
    5454            bool hasInheritedValue(void) const; 
    5555 
     56            bool isEqual(const CAttributeTemplate& attr ); 
     57            bool isEqual(const CAttribute& attr ); 
     58             
    5659            /// Destructeur /// 
    5760            virtual ~CAttributeTemplate(void) { } 
  • XIOS/trunk/src/attribute_template_impl.hpp

    r1028 r1105  
    139139    { 
    140140      return !this->isEmpty() || !inheritedValue.isEmpty() ; 
     141    } 
     142 
     143    template <class T> 
     144    bool CAttributeTemplate<T>::isEqual(const CAttribute& attr) 
     145    { 
     146      const CAttributeTemplate<T>& tmp = dynamic_cast<const CAttributeTemplate<T>& >(attr); 
     147      this->isEqual(tmp); 
     148 
     149    } 
     150 
     151    template <class T> 
     152    bool CAttributeTemplate<T>::isEqual(const CAttributeTemplate& attr) 
     153    { 
     154      if ((!this->hasInheritedValue() && !attr.hasInheritedValue())) 
     155          return true; 
     156      if (this->hasInheritedValue() && attr.hasInheritedValue()) 
     157          return (this->getInheritedValue() == attr.getInheritedValue()); 
     158      else  
     159        return false; 
    141160    } 
    142161 
  • XIOS/trunk/src/date.cpp

    r647 r1105  
    6262         hour = date.hour; minute = date.minute; second = date.second; 
    6363         return (*this); 
     64      } 
     65 
     66      bool CDate::operator==(const CDate& date) 
     67      {          
     68         return (&(*relCalendar) == &(*date.relCalendar) && 
     69                 year == date.year && month  == date.month  && day == date.day && 
     70                 hour == date.hour && minute == date.minute && second == date.second); 
     71          
    6472      } 
    6573 
  • XIOS/trunk/src/date.hpp

    r591 r1105  
    3232            /// Opérateurs /// 
    3333            CDate& operator=(const CDate& date); 
     34            bool operator==(const CDate& date); 
    3435            friend StdOStream& operator<<(StdOStream& out, const CDate& date); 
    3536            friend StdIStream& operator>>(StdIStream& in, CDate& date); 
  • XIOS/trunk/src/duration.cpp

    r1049 r1105  
    2424        hour = duration.hour; minute = duration.minute; second = duration.second; timestep = duration.timestep; 
    2525        return *this; 
     26      } 
     27 
     28      /*! 
     29        This operation may not serve much, it's here because of the need of operator== from generic class CType<T> 
     30      */ 
     31      bool CDuration::operator==(const CDuration& duration) 
     32      { 
     33        return (year == duration.year && month  == duration.month  && day == duration.day && 
     34                hour == duration.hour && minute == duration.minute && second == duration.second && timestep == duration.timestep);         
    2635      } 
    2736 
  • XIOS/trunk/src/duration.hpp

    r1028 r1105  
    2222            /// Opérateurs /// 
    2323            CDuration& operator=(const CDuration& duration); 
     24            bool operator==(const CDuration& duration); 
    2425 
    2526            friend StdOStream& operator<<(StdOStream& out, const CDuration& duration); 
  • XIOS/trunk/src/object_template.hpp

    r731 r1105  
    6161         static bool dispatchEvent(CEventServer& event) ; 
    6262 
     63         bool isEqual(const string& id); 
     64         bool isEqual(T* obj); 
     65 
    6366         /// Accesseur statique /// 
    6467         static std::vector<boost::shared_ptr<DerivedType> > & 
  • XIOS/trunk/src/object_template_impl.hpp

    r769 r1105  
    136136   } 
    137137 
     138   /*! 
     139     Compare two object of same type 
     140   */ 
     141   template <class T> 
     142   bool CObjectTemplate<T>::isEqual(const string& id) 
     143   { 
     144      T* obj = CObjectTemplate<T>::get(id); 
     145      return this->isEqual(obj); 
     146   } 
     147 
     148   template <class T> 
     149   bool CObjectTemplate<T>::isEqual(T* obj) 
     150   { 
     151 
     152      CAttributeMap& attrMapThis = *this; 
     153      CAttributeMap& attrMapObj  = *obj; 
     154      return (attrMapThis.isEqual(attrMapObj)); 
     155   } 
     156 
    138157   //--------------------------------------------------------------- 
    139158 
  • XIOS/trunk/src/type/enum.hpp

    r591 r1105  
    100100    __INLINE__ const CEnum_ref& operator = (const CEnum_ref& val) const; 
    101101    __INLINE__ operator T_enum&() const; 
    102     bool operator == (const CEnum_ref &other) {return this->get()==other.get() ;} 
     102     
    103103 
    104104    inline virtual CBaseType* clone(void) const   { return _clone(); } 
     
    134134  } ; 
    135135   
     136  template <typename T> __INLINE__ bool operator== (const CEnum<T>& lhs, const typename T::t_enum& rhs); 
     137  template <typename T> __INLINE__ bool operator== (const typename T::t_enum& lhs, const CEnum<T>& rhs); 
     138  template <typename T> __INLINE__ bool operator== (const CEnum<T>& lhs, const CEnum<T>& rhs);   
     139  template <typename T> __INLINE__ bool operator== (const CEnum_ref<T>& lhs, const CEnum_ref<T>& rhs); 
     140  template <typename T> __INLINE__ bool operator== (const CEnum_ref<T>& lhs, const typename T::t_enum& rhs); 
     141  template <typename T> __INLINE__ bool operator== (const typename T::t_enum& lhs, const CEnum_ref<T>& rhs); 
     142  template <typename T> __INLINE__ bool operator== (const CEnum<T>& lhs, const CEnum_ref<T>& rhs) {return (lhs.get() == rhs.get());} 
     143  template <typename T> __INLINE__ bool operator== (const CEnum_ref<T>& lhs, const CEnum<T>& rhs) {return (rhs == lhs); } 
     144 
    136145  template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const CEnum<T>& type) ; 
    137146  template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const typename T::t_enum & type) ;   
  • XIOS/trunk/src/type/enum_impl.hpp

    r680 r1105  
    249249                     << "Enum is not initialized."); 
    250250  }   
    251  
    252    
     251   
     252  template <typename T>  
     253  bool operator== (const CEnum<T>& lhs, const typename T::t_enum& rhs) 
     254  { 
     255     if (lhs.isEmpty()) return false; 
     256     return (lhs.get() == rhs); 
     257  } 
     258 
     259  template <typename T>  
     260  bool operator== (const typename T::t_enum& lhs, const CEnum<T>& rhs) 
     261  { 
     262    return rhs == lhs; 
     263  } 
     264 
     265  template <typename T>  
     266  bool operator== (const CEnum<T>& lhs, const CEnum<T>& rhs) 
     267  { 
     268    if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; 
     269    if (lhs.isEmpty() && rhs.isEmpty()) return true; 
     270    return (lhs.get() == rhs.get()); 
     271  } 
     272 
     273 
    253274  template <typename T> 
    254275  CBufferOut& operator<<(CBufferOut& buffer, const CEnum<T>& type) 
  • XIOS/trunk/src/type/enum_ref_impl.hpp

    r680 r1105  
    263263  } 
    264264                      
    265  
     265  template <typename T>  
     266  bool operator== (const CEnum_ref<T>& lhs, const typename T::t_enum& rhs) 
     267  { 
     268     if (lhs.isEmpty()) return false; 
     269     return (lhs.get() == rhs); 
     270  } 
     271 
     272  template <typename T>  
     273  bool operator== (const typename T::t_enum& lhs, const CEnum_ref<T>& rhs) 
     274  { 
     275    return rhs == lhs; 
     276  } 
     277 
     278  template <typename T>  
     279  bool operator== (const CEnum_ref<T>& lhs, const CEnum_ref<T>& rhs) 
     280  { 
     281    if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; 
     282    if (lhs.isEmpty() && rhs.isEmpty()) return true; 
     283    return (lhs.get() == rhs.get()); 
     284  } 
    266285   
    267286  template <typename T> 
  • XIOS/trunk/src/type/type.hpp

    r748 r1105  
    9494    const CType_ref& operator = (CType<T>& val) const ; 
    9595    const CType_ref& operator = (const CType_ref& val) const; 
    96     operator T&() const; 
     96    operator T&() const;     
    9797 
    9898    inline virtual CBaseType* clone(void) const   { return _clone(); } 
     
    127127    size_t _size(void) const ; 
    128128  } ; 
     129 
     130  template <typename T> inline bool operator==(const CType<T>& lhs, const T& rhs);    
     131  template <typename T> inline bool operator==(const T& lhs, const CType<T>& rhs);    
     132  template <typename T> inline bool operator==(const CType_ref<T>& lhs, const T& rhs);    
     133  template <typename T> inline bool operator==(const T& lhs, const CType_ref<T>& rhs);  
     134  template <typename T> inline bool operator==(const CType_ref<T>& lhs, const CType_ref<T>& rhs);  
     135 
     136  template <typename T> 
     137  inline bool operator==(const CType_ref<T>& lhs, const CType<T>& rhs) 
     138  { 
     139    if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; 
     140    if (lhs.isEmpty() && rhs.isEmpty()) return true; 
     141    return (*lhs.ptrValue == *rhs.ptrValue); 
     142  }  
     143 
     144  template <typename T> 
     145  inline bool operator==(const CType<T>& lhs, const CType_ref<T>& rhs) 
     146  { 
     147    return (rhs == lhs); 
     148  } 
    129149 
    130150 
  • XIOS/trunk/src/type/type_decl.cpp

    r591 r1105  
    2222/*  template CMessage& operator<< <decl_type> (CMessage& msg, const CType_ref<decl_type>& type) ;*/ \ 
    2323  template CMessage& operator<< <decl_type> (CMessage& msg, const decl_type& type) ; \ 
    24   template CMessage& operator<< <decl_type> (CMessage& msg, decl_type& type) ; 
     24  template CMessage& operator<< <decl_type> (CMessage& msg, decl_type& type) ;       \     
     25  template bool operator==(const CType<decl_type>& lhs, const decl_type& rhs);                 \           
     26  template bool operator==(const decl_type& lhs, const CType<decl_type>& rhs);                \ 
     27  template bool operator==(const CType_ref<decl_type>& lhs, const decl_type& rhs);             \ 
     28  template bool operator==(const decl_type& lhs, const CType_ref<decl_type>& rhs);             \ 
     29  template bool operator==(const CType_ref<decl_type>& lhs, const CType<decl_type>& rhs);      \ 
     30  template bool operator==(const CType<decl_type>& lhs, const CType_ref<decl_type>& rhs);     \ 
     31  template bool operator==(const CType_ref<decl_type>& lhs, const CType_ref<decl_type>& rhs);     
    2532   
    2633  macro(string) 
  • XIOS/trunk/src/type/type_impl.hpp

    r748 r1105  
    211211  } 
    212212 
     213  template <typename T> 
     214  bool operator==(const CType<T>& lhs, const T& rhs) 
     215  { 
     216    if (lhs.isEmpty()) return false; 
     217    return (*lhs.ptrValue == rhs);     
     218  } 
     219 
     220  template <typename T> 
     221  bool operator==(const T& lhs, const CType<T>& rhs) 
     222  { 
     223    return (rhs == lhs); 
     224  } 
     225 
     226  template <typename T> 
     227  bool operator==(const CType<T>& lhs, const CType<T>& rhs) 
     228  { 
     229    if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; 
     230    if (lhs.isEmpty() && rhs.isEmpty()) return true; 
     231     
     232    return (*lhs.ptrValue == *rhs.ptrValue); 
     233  } 
    213234 
    214235  template <typename T> 
  • XIOS/trunk/src/type/type_ref_impl.hpp

    r680 r1105  
    201201  } 
    202202                      
    203  
     203  template <typename T> 
     204  bool operator==(const CType_ref<T>& lhs, const T& rhs) 
     205  { 
     206    if (lhs.isEmpty()) return false; 
     207    return (*lhs.ptrValue == rhs);     
     208  } 
     209 
     210  template <typename T> 
     211  bool operator==(const T& lhs, const CType_ref<T>& rhs) 
     212  { 
     213    return (rhs == lhs); 
     214  } 
     215 
     216  template <typename T> 
     217  bool operator==(const CType_ref<T>& lhs, const CType_ref<T>& rhs) 
     218  { 
     219    if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; 
     220    if (lhs.isEmpty() && rhs.isEmpty()) return true; 
     221     
     222    return (*lhs.ptrValue == *rhs.ptrValue); 
     223  } 
    204224   
    205225  template <typename T> 
Note: See TracChangeset for help on using the changeset viewer.