presageCallback.h
Go to the documentation of this file.
/******************************************************
* Presage, an extensible predictive text entry system
* ---------------------------------------------------
*
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
**********(*)*/
#ifndef PRESAGE_CALLBACK
#define PRESAGE_CALLBACK
#ifdef __cplusplus
extern "C" {
#endif
typedef const char* (*_presage_callback_get_past_stream) (void*);
typedef const char* (*_presage_callback_get_future_stream) (void*);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#ifndef _MSC_VER
#include <string>
#include <sstream>
class PresageCallback {
public:
virtual ~PresageCallback() { };
virtual std::string get_past_stream() const = 0;
virtual std::string get_future_stream() const = 0;
protected:
PresageCallback() { };
};
class LegacyPresageCallback : public PresageCallback {
public:
LegacyPresageCallback() { }
~LegacyPresageCallback() { }
std::string get_past_stream() const { return m_stream; }
std::string get_future_stream() const { return m_empty; }
void update(std::string str) { for (size_t sz = 0; sz < str.size(); sz++) { update(str[sz]); } }
private:
void update(int character) {
if (character == '\b'
&& ! m_stream.empty()) {
m_stream.erase(m_stream.end() - 1);
} else {
m_stream.push_back(character);
}
}
std::string m_stream;
const std::string m_empty;
};
#endif /* _MSC_VER */
#endif /* _cplusplus */
#endif /* PRESAGE_CALLBACK */
LegacyPresageCallback::update
void update(std::string str)
Definition presageCallback.h:102
LegacyPresageCallback::get_future_stream
std::string get_future_stream() const
Definition presageCallback.h:100
LegacyPresageCallback::update
void update(int character)
Definition presageCallback.h:105
LegacyPresageCallback::~LegacyPresageCallback
~LegacyPresageCallback()
Definition presageCallback.h:97
LegacyPresageCallback::m_stream
std::string m_stream
Definition presageCallback.h:114
LegacyPresageCallback::LegacyPresageCallback
LegacyPresageCallback()
Definition presageCallback.h:96
LegacyPresageCallback::m_empty
const std::string m_empty
Definition presageCallback.h:115
LegacyPresageCallback::get_past_stream
std::string get_past_stream() const
Definition presageCallback.h:99
PresageCallback::PresageCallback
PresageCallback()
Definition presageCallback.h:74
PresageCallback::~PresageCallback
virtual ~PresageCallback()
Definition presageCallback.h:68
PresageCallback::get_future_stream
virtual std::string get_future_stream() const =0
PresageCallback::get_past_stream
virtual std::string get_past_stream() const =0