ReactOS 0.4.15-dev-5672-gf73ac17
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{
42}
43
44BOOL CTextHistory::Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
45{
46 if (!dwMaxHistoryLines)
47 {
49 return FALSE;
50 }
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
63{
64 if (!m_pHistoryBuffer) return;
65 if (_tcslen(pchLine) == 0) return;
66 if (_tcslen(pchLine) >= m_dwMaxHistoryLineSize)
67 {
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}
DWORD m_dwMaxHistoryLines
Definition: TextHistory.h:19
DWORD m_dwHisoryFull
Definition: TextHistory.h:23
virtual ~CTextHistory()
Definition: TextHistory.cpp:39
void AddHistoryLine(const TCHAR *pchLine)
Definition: TextHistory.cpp:62
TCHAR * m_pHistoryBuffer
Definition: TextHistory.h:18
BOOL Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
Definition: TextHistory.cpp:44
const TCHAR * GetHistoryLine(DWORD dwIndex)
Definition: TextHistory.cpp:83
DWORD m_dwMaxHistoryLineSize
Definition: TextHistory.h:20
DWORD m_dwLastHistoryIndex
Definition: TextHistory.h:22
DWORD m_dwFirstHistoryIndex
Definition: TextHistory.h:21
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _tcscpy
Definition: tchar.h:623
#define ASSERT(a)
Definition: mode.c:44
char TCHAR
Definition: xmlstorage.h:189
#define _tcslen
Definition: xmlstorage.h:198