home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c07 / treelist / anmldata.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  1.9 KB  |  83 lines

  1. // AnmlData.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tree.h"
  6. #include "AnmlData.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAnimalInfo
  16.  
  17. IMPLEMENT_SERIAL (CAnimalInfo, CObject, 1)
  18.  
  19. // A default ctor is necessary for a serializable class.
  20. CAnimalInfo::CAnimalInfo()
  21. {
  22. }
  23.  
  24. // A 4 argument ctor is useful in this class.
  25. CAnimalInfo::CAnimalInfo(CString arg_class, CString arg_type,
  26.                         CString arg_animal, int arg_weight)
  27.     : m_class(arg_class), m_type(arg_type),    m_animal(arg_animal),
  28.         m_weight(arg_weight)
  29. {
  30. }
  31.  
  32. // No dynamic allocation means the dtor has nothing to do.
  33. CAnimalInfo::~CAnimalInfo()
  34. {
  35. }
  36.  
  37. void CAnimalInfo::Serialize(CArchive & ar)
  38. {
  39.     if ( ar.IsLoading() )
  40.         ar >> m_class >> m_type >> m_animal >> m_weight;
  41.     else
  42.         ar << m_class << m_type << m_animal << m_weight;
  43. }
  44.  
  45. // Since this class will be used in a CList, an overloaded assignment
  46. // operator and a copy constructor are also necessary to make this
  47. // class serializable. The comparison in = demands an overloaded ==.
  48.  
  49. CAnimalInfo & CAnimalInfo::operator = (const CAnimalInfo &cmd)
  50. {
  51.     // An overloaded = operator should always check
  52.     // for the object being assigned to itself.
  53.     if (cmd == *this)
  54.         return *this;
  55.  
  56.     m_class = cmd.m_class;
  57.     m_type = cmd.m_type;
  58.     m_animal = cmd.m_animal;
  59.     m_weight = cmd.m_weight;
  60.  
  61.     return * this;
  62. }
  63.  
  64. CAnimalInfo::CAnimalInfo(const CAnimalInfo & cmd)
  65. {
  66.     m_class = cmd.m_class;
  67.     m_type = cmd.m_type;
  68.     m_animal = cmd.m_animal;
  69.     m_weight = cmd.m_weight;
  70. }
  71.  
  72. int CAnimalInfo::operator == (const CAnimalInfo &cmd) const
  73. {
  74.     if ( (m_class == cmd.m_class) &&
  75.          (m_type == cmd.m_type) &&
  76.          (m_animal == cmd.m_animal) &&
  77.          (m_weight == cmd.m_weight) )
  78.          return TRUE;
  79.     else
  80.         return FALSE;
  81. }
  82.  
  83.