ReactOS  0.4.14-dev-1007-g90d795b
TextHistory.cpp
Go to the documentation of this file.
1 /*
2  * regexpl - Console Registry Explorer
3  *
4  * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 // TextHistory.cpp: implementation of the CTextHistory class.
23 //
25 
26 #include "ph.h"
27 #include "TextHistory.h"
28 
30 // Construction/Destruction
32 
34 {
37 }
38 
40 {
41  if (m_pHistoryBuffer) delete[] m_pHistoryBuffer;
42 }
43 
44 BOOL CTextHistory::Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
45 {
46  if (!dwMaxHistoryLines)
47  {
48  ASSERT(FALSE);
49  return FALSE;
50  }
51  if (m_pHistoryBuffer) delete[] m_pHistoryBuffer;
54  m_dwHisoryFull = 0;
55  m_dwMaxHistoryLines = dwMaxHistoryLines;
56  m_dwMaxHistoryLineSize = dwMaxHistoryLineSize;
57  m_pHistoryBuffer = new (std::nothrow) TCHAR [m_dwMaxHistoryLines*dwMaxHistoryLineSize];
58  if (!m_pHistoryBuffer) return FALSE;
59  return TRUE;
60 }
61 
62 void CTextHistory::AddHistoryLine(const TCHAR *pchLine)
63 {
64  if (!m_pHistoryBuffer) return;
65  if (_tcslen(pchLine) == 0) return;
66  if (_tcslen(pchLine) >= m_dwMaxHistoryLineSize)
67  {
68  ASSERT(FALSE);
69  return;
70  }
71  if (m_dwHisoryFull == m_dwMaxHistoryLines) // if buffer is full, replace last
72  {
75  }
81 }
82 
84 {
85  if (!m_pHistoryBuffer) return NULL;
87  if (dwIndex >= m_dwHisoryFull) return NULL;
88  dwIndex = m_dwHisoryFull - dwIndex - 1;
89  dwIndex = (dwIndex+m_dwLastHistoryIndex) % m_dwMaxHistoryLines;
90  ASSERT(dwIndex < m_dwMaxHistoryLines);
92 }
#define TRUE
Definition: types.h:120
virtual ~CTextHistory()
Definition: TextHistory.cpp:39
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
unsigned int BOOL
Definition: ntddk_ex.h:94
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
const TCHAR * GetHistoryLine(DWORD dwIndex)
Definition: TextHistory.cpp:83
char TCHAR
Definition: xmlstorage.h:189
TCHAR * m_pHistoryBuffer
Definition: TextHistory.h:18
void AddHistoryLine(const TCHAR *pchLine)
Definition: TextHistory.cpp:62
DWORD m_dwMaxHistoryLines
Definition: TextHistory.h:19
DWORD m_dwLastHistoryIndex
Definition: TextHistory.h:22
BOOL Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
Definition: TextHistory.cpp:44
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
DWORD m_dwHisoryFull
Definition: TextHistory.h:23
DWORD m_dwMaxHistoryLineSize
Definition: TextHistory.h:20
DWORD m_dwFirstHistoryIndex
Definition: TextHistory.h:21