presage
0.8.8
Main Page
Classes
Files
File List
File Members
src
lib
presageCallback.h
Go to the documentation of this file.
1
2
/******************************************************
3
* Presage, an extensible predictive text entry system
4
* ---------------------------------------------------
5
*
6
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License along
19
with this program; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
*
22
**********(*)*/
23
24
25
#ifndef PRESAGE_CALLBACK
26
#define PRESAGE_CALLBACK
27
28
#ifdef __cplusplus
29
extern
"C"
{
30
#endif
31
32
typedef
const
char
* (*_presage_callback_get_past_stream) (
void
*);
33
typedef
const
char
* (*_presage_callback_get_future_stream) (
void
*);
34
35
#ifdef __cplusplus
36
}
37
#endif
38
39
40
#ifdef __cplusplus
41
#ifndef _MSC_VER
42
43
#include <string>
44
#include <sstream>
45
66
class
PresageCallback
{
67
public
:
68
virtual
~PresageCallback
() { };
69
70
virtual
std::string
get_past_stream
()
const
= 0;
71
virtual
std::string
get_future_stream
()
const
= 0;
72
73
protected
:
74
PresageCallback
() { };
75
76
};
77
78
94
class
LegacyPresageCallback
:
public
PresageCallback
{
95
public
:
96
LegacyPresageCallback
() { }
97
~LegacyPresageCallback
() { }
98
99
std::string
get_past_stream
()
const
{
return
m_stream
; }
100
std::string
get_future_stream
()
const
{
return
m_empty
; }
101
102
void
update
(std::string str) {
for
(
size_t
sz = 0; sz < str.size(); sz++) {
update
(str[sz]); } }
103
104
private
:
105
void
update
(
int
character) {
106
if
(character ==
'\b'
107
&& !
m_stream
.empty()) {
108
m_stream
.erase(
m_stream
.end() - 1);
109
}
else
{
110
m_stream
.push_back(character);
111
}
112
}
113
114
std::string
m_stream
;
115
const
std::string
m_empty
;
116
};
117
118
#endif
/* _MSC_VER */
119
#endif
/* _cplusplus */
120
121
#endif
/* PRESAGE_CALLBACK */
Generated on Wed Jun 13 2012 10:34:24 for presage by
1.8.1