|
|
1.1 ! root 1: // database.h : Declares the interfaces for the CDataBase class. ! 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 __DATABASE_H__ ! 14: #define __DATABASE_H__ ! 15: ! 16: #include "person.h" ! 17: ! 18: ///////////////////////////////////////////////////////////////////////////// ! 19: ! 20: // string const for untitiled database ! 21: extern const char szUntitled[]; ! 22: ////////////////////////////////////////////////// ! 23: // CDataBase ! 24: // The database object is intended to encapsulate everything ! 25: // needed to work the the CPersonList into one interface. ! 26: // Exception handling, data manipulations, and searching ! 27: // are handled on this level freeing the view program, whether it ! 28: // is character or windows, to deal with displaying the data. ! 29: // ! 30: class CDataBase: public CObject ! 31: { ! 32: public: ! 33: // constructor ! 34: CDataBase() ! 35: { ! 36: m_pDataList = NULL; ! 37: m_pFindList = NULL; ! 38: m_szFileName = ""; ! 39: m_szFileTitle = ""; ! 40: } ! 41: ! 42: // Create/Destory CPersonLists ! 43: BOOL New(); ! 44: void Terminate(); ! 45: ! 46: // File handling ! 47: BOOL DoOpen( const char* pszFileName ); ! 48: BOOL DoSave( const char* pszFileName = NULL ); ! 49: BOOL DoFind( const char* pszLastName = NULL ); ! 50: ! 51: // Person Handling ! 52: void AddPerson( CPerson* pNewPerson ); ! 53: void ReplacePerson( CPerson* pOldPerson, const CPerson& rNewPerson ); ! 54: void DeletePerson( int nIndex ); ! 55: CPerson* GetPerson( int nIndex ); ! 56: ! 57: // Database Attributes ! 58: int GetCount() ! 59: { ! 60: ASSERT_VALID( this ); ! 61: if ( m_pFindList != NULL ) ! 62: return m_pFindList->GetCount(); ! 63: if ( m_pDataList != NULL ) ! 64: return m_pDataList->GetCount(); ! 65: return 0; ! 66: } ! 67: ! 68: BOOL IsDirty() ! 69: { ASSERT_VALID( this ); ! 70: return ( m_pDataList != NULL ) ? m_pDataList->GetDirty() : FALSE; } ! 71: ! 72: BOOL IsNamed() ! 73: { ASSERT_VALID( this ); ! 74: return m_szFileName != szUntitled; } ! 75: ! 76: const char* GetName() ! 77: { ASSERT_VALID( this ); ! 78: return m_szFileName; } ! 79: ! 80: CString GetTitle() ! 81: { ASSERT_VALID( this ); ! 82: return "Phone Book - " + m_szFileTitle; } ! 83: void SetTitle( const char* pszTitle ) ! 84: { ASSERT_VALID( this ); ! 85: m_szFileTitle = pszTitle; } ! 86: ! 87: BOOL IsPresent() ! 88: { ASSERT_VALID( this ); ! 89: return m_pDataList != NULL; } ! 90: ! 91: protected: ! 92: CPersonList* m_pDataList; ! 93: CPersonList* m_pFindList; ! 94: CString m_szFileName; ! 95: CString m_szFileTitle; ! 96: ! 97: private: ! 98: CPersonList* ReadDataBase( CFile* pFile ); ! 99: BOOL WriteDataBase( CFile* pFile ); ! 100: ! 101: #ifdef _DEBUG ! 102: public: ! 103: void AssertValid() const; ! 104: #endif ! 105: }; ! 106: ! 107: ///////////////////////////////////////////////////////////////////////////// ! 108: ! 109: #endif // __DATABASE_H__
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.