home *** CD-ROM | disk | FTP | other *** search
- // FileVDoc.cpp : implementation of the CFileViewDoc class
- //
-
- #include "stdafx.h"
- #include "FileView.h"
-
- #include "FileVDoc.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CFileViewDoc
-
- IMPLEMENT_DYNCREATE(CFileViewDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CFileViewDoc, CDocument)
- //{{AFX_MSG_MAP(CFileViewDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CFileViewDoc construction/destruction
-
- CFileViewDoc::CFileViewDoc()
- {
- lines = NULL;
- maxLineLength = 0;
-
- try {
- lines = new CPtrArray();
- }
- catch (CMemoryException *e)
- {
- AfxMessageBox("Can't allocate memory for reading file contents");
- TRACE0("Unable to allocate memory for file contents\n");
- e->Delete();
- }
- TRACE0("Allocated lines array\n");
- }
-
- CFileViewDoc::~CFileViewDoc()
- {
- int i = 0;
-
- if (lines != NULL)
- {
- while (i < lines->GetSize())
- delete (CString *) lines->GetAt(i++);
- lines->RemoveAll();
- delete lines;
- lines = NULL;
- }
- TRACE0("Deleted lines array\n");
- }
-
- BOOL CFileViewDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CFileViewDoc serialization
-
- void CFileViewDoc::Serialize(CArchive& ar)
- {
- BYTE buf;
- CString s;
-
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- while (1)
- {
- try {
- ar >> buf;
- }
- catch (CArchiveException *e)
- {
- if (e->m_cause != CArchiveException::endOfFile)
- {
- TRACE0("Unknown exception loading file!\n");
- throw;
- } else
- {
- TRACE0("End of file reached...\n");
- e->Delete();
- }
- break;
- }
- s += buf;
- if (buf == '\n')
- {
- try {
- lines->Add(new CString(s));
- }
- catch (CMemoryException *e)
- {
- AfxMessageBox("Not enough memory to load entire file");
- TRACE1("Not enough memory to load entire file; only %d lines loaded\n", lines->GetSize());
- e->Delete();
- break;
- }
- if (maxLineLength < s.GetLength())
- maxLineLength = s.GetLength();
- s.Empty();
- }
- }
- #ifdef _DEBUG
- afxDump.SetDepth(1);
- afxDump << lines;
- #endif
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CFileViewDoc diagnostics
-
- #ifdef _DEBUG
- void CFileViewDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CFileViewDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CFileViewDoc commands
-