home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK11 / MFC / SAMPLES / TUTORIAL / PERSON.H$ / person
Encoding:
Text File  |  1992-01-10  |  3.8 KB  |  144 lines

  1. // person.h : Defines the class interfaces for CPerson, CPersonList.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // QuickHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #ifndef __PERSON_H__
  14. #define __PERSON_H__
  15. #ifdef _DOS
  16.     #include <afx.h>
  17. #else
  18.     #include <afxwin.h>
  19. #endif
  20. #include <afxcoll.h>
  21.  
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // class CPerson:
  25. // Represents one person in the phone database.  This class is derived from
  26. // CObject (mostly to get access to the serialization protocol).
  27.  
  28. class CPerson : public CObject
  29. {
  30.     DECLARE_SERIAL( CPerson );
  31.  
  32. public:
  33. //Construction
  34.     // For serializable classes, declare a constructor with no arguments.
  35.     CPerson()
  36.         { m_modTime = CTime::GetCurrentTime(); }
  37.         
  38.     CPerson( const CPerson& a );
  39.  
  40.     // For our convenience, also declare a constructor with arguments.
  41.     CPerson( const char* pszLastName,
  42.         const char* pszFirstName,
  43.         const char* pszPhoneNum );
  44.  
  45. //Attributes
  46.     // Member functions to modify the protected member variables.
  47.     void SetLastName( const char* pszName )
  48.         {   ASSERT_VALID( this );
  49.             ASSERT( pszName != NULL);
  50.             m_LastName = pszName;
  51.             m_modTime = CTime::GetCurrentTime(); }
  52.             
  53.     const CString& GetLastName() const
  54.         {   ASSERT_VALID( this );
  55.             return m_LastName; }
  56.  
  57.     void SetFirstName( const char* pszName )
  58.         {   ASSERT_VALID( this );
  59.             ASSERT( pszName != NULL );
  60.             m_FirstName = pszName;
  61.             m_modTime = CTime::GetCurrentTime(); }
  62.             
  63.     const CString& GetFirstName() const
  64.         {   ASSERT_VALID( this );
  65.             return m_FirstName; }
  66.  
  67.     void SetPhoneNumber( const char* pszNumber )
  68.         {   ASSERT_VALID( this );
  69.             ASSERT( pszNumber != NULL );
  70.             m_PhoneNumber = pszNumber;
  71.             m_modTime = CTime::GetCurrentTime(); }
  72.             
  73.     const CString& GetPhoneNumber() const
  74.         {   ASSERT_VALID( this );
  75.             return m_PhoneNumber; }
  76.  
  77.     const CTime GetModTime() const
  78.         {   ASSERT_VALID( this );
  79.             return m_modTime; }
  80.  
  81. //Operations
  82.     CPerson& operator=( const CPerson& b );
  83.  
  84. //Implementation
  85. protected:
  86.     // Member variables that hold data for person
  87.     CString        m_LastName;
  88.     CString        m_FirstName;
  89.     CString        m_PhoneNumber;
  90.     CTime          m_modTime;
  91.  
  92. public:
  93.     // Override the Serialize function
  94.     virtual void Serialize( CArchive& archive );
  95.  
  96. #ifdef _DEBUG
  97.     // Override Dump for debugging support
  98.     virtual void Dump( CDumpContext& dc ) const;
  99.     virtual void AssertValid() const;
  100. #endif
  101. };
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // class CPersonList:
  105. // This represents a list of all persons in a phone database.  This class is
  106. // derived from CObList, a list of pointers to CObject-type objects.
  107.  
  108. class CPersonList : public CObList
  109. {
  110.     DECLARE_SERIAL( CPersonList )
  111.     
  112. public:
  113. //Construction
  114.  
  115.     CPersonList()
  116.         { m_bIsDirty = FALSE; }
  117.  
  118.     // Add new functions
  119.     CPersonList* FindPerson( const char * szTarget );
  120.     
  121.     // SetDirty/GetDirty
  122.     // Mark the person list as "dirty" (meaning "modified").  This flag can be
  123.     // checked later to see if the database needs to be saved.
  124.     //
  125.     void SetDirty( BOOL bDirty )
  126.         {   ASSERT_VALID( this );
  127.             m_bIsDirty = bDirty; }
  128.     
  129.     BOOL GetDirty()
  130.         {   ASSERT_VALID( this );
  131.             return m_bIsDirty; }
  132.  
  133.     // Delete All will delete the Person objects as well as the pointers.
  134.     void DeleteAll();
  135.     
  136. protected:
  137.     BOOL  m_bIsDirty;
  138. };
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141.  
  142. #endif // __PERSON_H__
  143.  
  144.