presage 0.9.2~beta
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
29extern "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
67public:
68 virtual ~PresageCallback() { };
69
70 virtual std::string get_past_stream() const = 0;
71 virtual std::string get_future_stream() const = 0;
72
73protected:
75
76};
77
78
95public:
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
104private:
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 */
void update(std::string str)
std::string get_future_stream() const
void update(int character)
const std::string m_empty
std::string get_past_stream() const
virtual ~PresageCallback()
virtual std::string get_future_stream() const =0
virtual std::string get_past_stream() const =0